Calculate start/end date for event list
TODO this should go in a helper class
1791
public static function offset_date($type, $timestamp, $offset = 30)
    {
        if (!$timestamp) {
            $timestamp = time();
        }

        // check whether the timestamp was
        // given as a date string (2016-09-05)
        if(strpos($timestamp, "-") > 0) {
            $timestamp = strtotime($timestamp);
        }

        $offsetCalc = $offset * 24 * 60 * 60; //days in secs

        $offsetTime = null;
        if ($type == 'start') {
            $offsetTime = $timestamp - $offsetCalc;
        } elseif ($type == 'end') {
            $offsetTime = $timestamp + $offsetCalc;
        }

        $str = date('Y-m-d', $offsetTime);
        return $str;
    }
1001588
function end () {
  var diff = new Date() - startTime

  log('\n\n')
  log('  ' + SYMBOLS.success + ' ' + (stats.success + ' passing ').green)
  log(('(' + diff + 'ms)').grey)

  if (stats.skipped) {
    log('\n  ' + SYMBOLS.skipped + ' ' + (stats.skipped + ' pending').cyan)
  }

  if (stats.failure) {
    log('\n  ' + SYMBOLS.failure + ' ' + (stats.failure + ' failing').red)

    // Log all accumulated errors
    log('\n\n')
    failures.forEach(logError)
  }

  log('\n\n')
}
1275316
function(start, end) {
    var date;
    var res = [];
    for (var key in holidays) {
      date = beginningOfDay(new Date(key));
      // given `start` and `end` Date object are both normalized to beginning of the day
      if (beginningOfDay(start) <= date && date <= beginningOfDay(end)) {
        res.push(holiday(date, holidays[key]));
      }
    }
    return res;
  }
1353453
private List<O> findByDate(String dateField, Date start, Date end, int numObjects, boolean asc) {
        if (start == null)
            start = new Date(0);
        if (end == null)
            end = new Date();
        return getDatastore().find(clazz).filter(dateField + " >", start).filter(dateField + " <", end).order(asc ? dateField : '-' + dateField).limit(numObjects).asList();
    }
606405
function() {
		var dates = [];
		for (var i = 0; i < this.events.length; i++) {
			if (this.events[i].end_date) {
				dates.push({ date: this.events[i].end_date });
			} else {
				dates.push({ date: this.events[i].start_date });
			}
		}
		for (var i = 0; i < this.eras.length; i++) {
			if (this.eras[i].end_date) {
				dates.push({ date: this.eras[i].end_date });
			} else {
				dates.push({ date: this.eras[i].start_date });
			}
		}
		TL.DateUtil.sortByDate(dates, 'date');
		return dates.slice(-1)[0].date;
	}
943880
def get_allEvents(self):
        '''
        
        '''

        if not hasattr(self,'allEvents'):
            timeFilters = {'endTime__gte': timezone.now()}
            if getConstant('registration__displayLimitDays') or 0 > 0:
                timeFilters['startTime__lte'] = timezone.now() + timedelta(days=getConstant('registration__displayLimitDays'))

            # Get the Event listing here to avoid duplicate queries
            self.allEvents = Event.objects.filter(
                **timeFilters
            ).filter(
                Q(instance_of=PublicEvent) |
                Q(instance_of=Series)
            ).annotate(
                **self.get_annotations()
            ).exclude(
                Q(status=Event.RegStatus.hidden) |
                Q(status=Event.RegStatus.regHidden) |
                Q(status=Event.RegStatus.linkOnly)
            ).order_by(*self.get_ordering())

        return self.allEvents
1132785
function countdown () {
            var target_date = new Date(settings.date), // set target date
                current_date = currentDate(); // get fixed current date

            // difference of dates
            var difference = target_date - current_date;

            // if difference is negative than it's pass the target date
            if (difference < 0) {
                // stop timer
                clearInterval(interval);

                if (callback && typeof callback === 'function') callback();

                return;
            }

            // basic math variables
            var _second = 1000,
                _minute = _second * 60,
                _hour = _minute * 60,
                _day = _hour * 24;

            // calculate dates
            var days = Math.floor(difference / _day),
                hours = Math.floor((difference % _day) / _hour),
                minutes = Math.floor((difference % _hour) / _minute),
                seconds = Math.floor((difference % _minute) / _second);

                // fix dates so that it will show two digets
                days = (String(days).length >= 2) ? days : '0' + days;
                hours = (String(hours).length >= 2) ? hours : '0' + hours;
                minutes = (String(minutes).length >= 2) ? minutes : '0' + minutes;
                seconds = (String(seconds).length >= 2) ? seconds : '0' + seconds;

            // based on the date change the refrence wording
            var ref_days = (days === 1) ? 'day' : 'days',
                ref_hours = (hours === 1) ? 'hour' : 'hours',
                ref_minutes = (minutes === 1) ? 'minute' : 'minutes',
                ref_seconds = (seconds === 1) ? 'second' : 'seconds';

            // set to DOM
            container.find('.days').text(days);
            container.find('.hours').text(hours);
            container.find('.minutes').text(minutes);
            container.find('.seconds').text(seconds);

            container.find('.days_ref').text(ref_days);
            container.find('.hours_ref').text(ref_hours);
            container.find('.minutes_ref').text(ref_minutes);
            container.find('.seconds_ref').text(ref_seconds);
        }
979573
function getDateDiff (startDate, endDate, rules) {
  var startTime, endTime, item, diffTime, rule, len, index
  var result = { done: false, time: 0 }
  startDate = toStringDate(startDate)
  endDate = endDate ? toStringDate(endDate) : new Date()
  if (baseExports.isDate(startDate) && baseExports.isDate(endDate)) {
    startTime = getDateTime(startDate)
    endTime = getDateTime(endDate)
    if (startTime < endTime) {
      diffTime = result.time = endTime - startTime
      rule = rules && rules.length > 0 ? rules : setupDefaults.dateDiffRules
      result.done = true
      for (index = 0, len = rule.length; index < len; index++) {
        item = rule[index]
        if (diffTime >= item[1]) {
          if (index === len - 1) {
            result[item[0]] = diffTime || 0
          } else {
            result[item[0]] = Math.floor(diffTime / item[1])
            diffTime -= result[item[0]] * item[1]
          }
        } else {
          result[item[0]] = 0
        }
      }
    }
  }
  return result
}
371123
function(eventData) {

    var firstEventStart = moment(eventData[0].start)
    var firstEventEnd = moment(eventData[0].end)
    var firstEventDuration = firstEventEnd.diff(firstEventStart, 'minutes')

    if (firstEventDuration <= 90) {
      calendarTarget.fullCalendar('option', 'slotDuration', '00:15:00')
    }

    calendarTarget.fullCalendar('addEventSource', {
      events: eventData
    });

    calendarTarget.removeClass('empty-calendar');

    // Go to first event if enabled
    goToFirstEvent(eventData[0].start);

  }
1197343
function () {
    
                var start = new Date(),
                    retval = method.apply(this, arguments),
                    stop = new Date();
                
                saveDataPoint(name, stop-start);
                
                return retval;                
            
            }
1227963
private long getTime(Date start, Date end)
   {
      long total = 0;
      if (start != null && end != null)
      {
         Date startTime = DateHelper.getCanonicalTime(start);
         Date endTime = DateHelper.getCanonicalTime(end);

         Date startDay = DateHelper.getDayStartDate(start);
         Date finishDay = DateHelper.getDayStartDate(end);

         //
         // Handle the case where the end of the range is at midnight -
         // this will show up as the start and end days not matching
         //
         if (startDay.getTime() != finishDay.getTime())
         {            
            endTime = DateHelper.addDays(endTime, 1);
         }

         total = (endTime.getTime() - startTime.getTime());
      }
      return (total);
   }
725516
def getEvent(self, dev_id, starttime, endtime):
        """"""
        path = 'device/%s/event?startTime=%s&endTime=%s' % \
            (dev_id, starttime, endtime)
        return self.rachio.get(path)
792841
def event_strips_for_month(shown_date, first_day_of_week=0, find_options = {})
      if first_day_of_week.is_a?(Hash)
        find_options.merge!(first_day_of_week)
        first_day_of_week =  0
      end
      strip_start, strip_end = get_start_and_end_dates(shown_date, first_day_of_week)
      events = events_for_date_range(strip_start, strip_end, find_options)
      event_strips = create_event_strips(strip_start, strip_end, events)
      event_strips
    end
212197
function(date) {
        var start = this.findMonthStart(date);
        var nextMonth = this.add(start, this.MONTH, 1);
        var end = this.subtract(nextMonth, this.DAY, 1);
        return end;
    }
1273875
def date_range_for_webtrends(cls, start_at=None, end_at=None):
        
        if start_at and end_at:
            start_date = cls.parse_standard_date_string_to_date(
                start_at)
            end_date = cls.parse_standard_date_string_to_date(
                end_at)
            numdays = (end_date - start_date).days + 1
            start_dates = [end_date - timedelta(days=x)
                           for x in reversed(range(0, numdays))]
            date_range = []
            for i, date in enumerate(start_dates):
                query_date = cls.parse_date_for_query(date)
                date_range.append((query_date, query_date))
            return date_range
        else:
            return [("current_day-1", "current_day-1")]
1218051
def GetCalendarFieldValuesTuple(self):
    """"""
    if self.start_date and self.end_date:
      return [getattr(self, fn) for fn in self._FIELD_NAMES]
265518
private void initDatesPanel() {

        m_startLabel.setText(Messages.get().key(Messages.GUI_SERIALDATE_TIME_STARTTIME_0));
        m_startTime.setAllowInvalidValue(true);
        m_startTime.setValue(m_model.getStart());
        m_endLabel.setText(Messages.get().key(Messages.GUI_SERIALDATE_TIME_ENDTIME_0));
        m_endTime.setAllowInvalidValue(true);
        m_endTime.setValue(m_model.getEnd());
        m_seriesCheckBox.setText(Messages.get().key(Messages.GUI_SERIALDATE_SERIES_CHECKBOX_0));
        m_wholeDayCheckBox.setText(Messages.get().key(Messages.GUI_SERIALDATE_WHOLE_DAY_CHECKBOX_0));
        m_currentTillEndCheckBox.setText(Messages.get().key(Messages.GUI_SERIALDATE_CURRENT_TILL_END_CHECKBOX_0));
        m_currentTillEndCheckBox.getButton().setTitle(
            Messages.get().key(Messages.GUI_SERIALDATE_CURRENT_TILL_END_CHECKBOX_HELP_0));
    }