Determines whether to move back or forward in time and returns the
 distance in days, weeks, months or years
 Example: move(10, 'd') adds 10 days to :now
971440
def add(direction, count, distance)
      count = direction.downcase == 'b' ? -count.to_i : count.to_i

      case distance
      when 'd'
        @now + count
      when 'w'
        @now + count * 7
      when 'm'
        @now >> count
      when 'y'
        @now >> count * 12
      end

    end
818614
def rollforward(self, dt):
        
        dt = as_timestamp(dt)
        if not self.onOffset(dt):
            dt = dt + self.__class__(1, normalize=self.normalize, **self.kwds)
        return dt
660126
function(d) {
		"use strict";

		if (this.options.weekStartOnMonday === false) {
			return d.getDay();
		}
		return d.getDay() === 0 ? 6 : (d.getDay()-1);
	}
1353166
def average(self, dt=None):
        
        if dt is None:
            dt = Date.today()

        return self.add(days=int(self.diff(dt, False).in_days() / 2))
843790
def shift(self, direction):
        
        try:
            if direction == Direction.UP:
                return self.shift_up()
            elif direction == Direction.DOWN:
                return self.shift_down()
            elif direction == Direction.RIGHT:
                return self.shift_right()
            elif direction == Direction.LEFT:
                return self.shift_left()
            else:
                raise IndexError("Invalid direction {}".format(direction))
        except IndexError as e:
            raise IndexError(e)
1226768
def _move_datetime(dt, direction, delta):
    
    if direction == 'next':
        dt = dt + delta
    elif direction == 'last':
        dt = dt - delta
    else:
        pass
        # raise some delorean error here
    return dt
1097444
def _days_to_seconds(cls, val, **kwargs):
        '''
        
        '''
        zero_value = kwargs.get('zero_value', 0)
        if val is not None:
            if val == 0:
                return zero_value
            return val * 86400
        else:
            return 'Not Defined'
1074295
def next(time, base)
      current = time
      until match?(current, base) && current > time
        pot_next = align(potential_next(current, base), base)
        pot_next += min_step if pot_next == current

        current = pot_next
      end

      current
    end
788508
def minutes_back(self, date):
        ''' 
        '''
        elapsed = (datetime.utcnow() - datetime.strptime(date,'%Y-%m-%dT%H:%M:%S'))
        if elapsed.days > 0:
            secondsback = (elapsed.days * 24 * 60 * 60) + elapsed.seconds
        else:
            secondsback = elapsed.seconds
        minutesback = secondsback / 60
        return int(minutesback)
1025860
def rollforward(self, date):
        """"""
        if self.onOffset(date):
            return date
        else:
            return date + QuarterBegin(month=self.month)
579390
def calculate_delta_date(literal):
    
    mapping = {
        "today": 0,
        "yesterday": 1,
        "this-week": 7,
        "this-month": 30,
        "this-year": 365,
    }
    today = DateTime(DateTime().Date())  # current date without the time
    return today - mapping.get(literal, 0)
972767
def get_seconds_until_next_day(now=None):
    
    if now is None:
        now = arrow.utcnow()
    return (now.ceil('day') - now).seconds
985522
function SeconsToNow(){ // as datetime object returns difference in seconds
		if(empty(self::$dtnow)){
			self::$dtnow=new \DateTime();
			}
		//Get difference
		$diff = $this->diff(self::$dtnow);
		$diff_sec =$diff->format('%r').( // prepend the sign - if negative, change it to R if you want the +, too
                	($diff->s)+ // seconds (no errors)
                	(60*($diff->i))+ // minutes (no errors)
	                (60*60*($diff->h))+ // hours (no errors)
        	        (24*60*60*($diff->d))+ // days (no errors)
                	(30*24*60*60*($diff->m))+ // months (???)
	                (365*24*60*60*($diff->y)) // years (???)
                	);
		return $diff_sec;
		}
1358064
def roll_forward(self, dt):
        
        dt = pd.Timestamp(dt, tz='UTC')

        trading_days = self.all_sessions()
        try:
            return trading_days[trading_days.searchsorted(dt)]
        except IndexError:
            raise ValueError(
                "Date {} was past the last session for domain {}. "
                "The last session for this domain is {}.".format(
                    dt.date(),
                    self,
                    trading_days[-1].date()
                )
            )
1154390
function diff (from, to, term) {
  term = (term || 'day').toLowerCase();
  var t, f;
  switch(TERM[term]) {
  case 'y':
    return this.getAge(from, to);
  case 'm':
    f = this.toDate(from);
    t = this.toDate(to);
    if (!(f && t)) {
      return null;
    }
    return (t.getFullYear() - f.getFullYear()) * 12 + t.getMonth() - f.getMonth() -
      (t.getDate() < f.getDate() ? 0 : 1);
  case 'w':
    f = this.toDate(from);
    t = this.toDate(to);
    return f && t ? parseInt((t - f) / A_WEEK, 10) : null;
  case 'd':
    f = this.toDate(from);
    t = this.toDate(to);
    return f && t ? (t - f) / A_DAY : null;
  case 'h':
    f = this.toDatetime(from);
    t = this.toDatetime(to);
    return f && t ? parseInt((t - f) / A_HOUR, 10) : null;
  case 'i':
    f = this.toDatetime(from);
    t = this.toDatetime(to);
    return f && t ? parseInt((t - f) / A_MINUTE, 10) : null;
  case 's':
    f = this.toDatetime(from);
    t = this.toDatetime(to);
    return f && t ? parseInt((t - f) / A_SECOND, 10) : null;
  case 'ms':
    f = this.toDatetime(from);
    t = this.toDatetime(to);
    return f && t ? t - f : null;
  default:
    return null;
  }
}
1141207
def this_month():
        
        since = TODAY + delta(day=1)
        until = since + delta(months=1)
        return Date(since), Date(until)
960530
function(d) {
    if (d.wyExtent) return d.wyExtent;

    // go to start of ISO week to get to the right year
    var year = later.dw.next(later.wy.start(d), 5),
        dwFirst = later.dw.val(later.Y.start(year)),
        dwLast = later.dw.val(later.Y.end(year));

    return (d.wyExtent = [1, dwFirst === 5 || dwLast === 5 ? 53 : 52]);
  }