Returns the difference in milliseconds between the moment this
calendar is set to and the moment the given calendar or Date object
is set to.
337316
private long compare(Object that) {
        long thatMs;
        if (that instanceof Calendar) {
            thatMs = ((Calendar)that).getTimeInMillis();
        } else if (that instanceof Date) {
            thatMs = ((Date)that).getTime();
        } else {
            throw new IllegalArgumentException(that + "is not a Calendar or Date");
        }
        return getTimeInMillis() - thatMs;
    }
559909
public static GregorianCalendar millisToCalendar(long millis) {

        GregorianCalendar result = new GregorianCalendar();
        result.setTimeZone(TimeZone.getTimeZone("GMT"));
        result.setTimeInMillis((long)(Math.ceil(millis / 1000) * 1000));
        return result;
    }
931802
def datetime_to_millis(x):
    """"""
    if x is None:
        return None
    if hasattr(x, 'timestamp'):
        # Python >= 3.3
        secs = x.timestamp()
    elif x.tzinfo is None:
        # Timezone naive
        secs = (time.mktime((x.year, x.month, x.day,
                             x.hour, x.minute, x.second,
                             -1, -1, -1)) + x.microsecond / 1e6)
    else:
        # Timezone aware
        secs = (x - _EPOCH).total_seconds()
    return int(secs * 1000)
38039
static double fromDate(Date dt) {

        // the number of milliseconds since January 1, 1970, 00:00:00 GMT
        long t = dt.getTime();

        // the number of milliseconds since January 1, 1970, 00:00:00 Local Time
        Calendar c = new GregorianCalendar();
        c.setTime(dt);
        t += (c.get(Calendar.ZONE_OFFSET) + c.get(Calendar.DST_OFFSET)) ;

        // the number of milliseconds since December 30, 1899, 00:00:00 Local Time
        t += 2209161600000L;

        // DATE is an offset from "30 December 1899"
        if (t < 0) {
            // -0.3 -> -0.7
            long offset = -(t % MSPD);    // TODO: check
            t = t - MSPD + offset;
        }
        double d = ((double) t) / MSPD;
        return d;
    }
1291867
private static Moment moveEventuallyToLS(Moment adjusted) {

        PlainDate date = adjusted.getDateUTC();
        PlainTime time = adjusted.getTimeUTC();

        if (
            (LeapSeconds.getInstance().getShift(date) == 1)
            && (time.getHour() == 23)
            && (time.getMinute() == 59)
            && (time.getSecond() == 59)
        ) {
            return adjusted.plus(1, SI.SECONDS);
        } else {
            return adjusted;
        }

    }
876335
def _millis_to_datetime(millis, opts):
    """"""
    diff = ((millis % 1000) + 1000) % 1000
    seconds = (millis - diff) / 1000
    micros = diff * 1000
    if opts.tz_aware:
        dt = EPOCH_AWARE + datetime.timedelta(seconds=seconds,
                                              microseconds=micros)
        if opts.tzinfo:
            dt = dt.astimezone(opts.tzinfo)
        return dt
    else:
        return EPOCH_NAIVE + datetime.timedelta(seconds=seconds,
                                                microseconds=micros)
163540
public static long todayEndSeconds(){
		Date curTime = new Date();
		return DateUtils.getDiffSeconds(DateUtils.getDayEnd(curTime), curTime);
	}
649074
public static String getDuration(long diff) {
        GregorianCalendar calendar = new GregorianCalendar();
        calendar.setTime(new Date(diff));
        StringBuffer s = new StringBuffer();
        if (calendar.get(Calendar.HOUR) > 1) {
            s.append("hours: " + (calendar.get(Calendar.HOUR) - 1) + ", ");
        }
        if (calendar.get(Calendar.MINUTE) > 0) {
            s.append("minutes: " + (calendar.get(Calendar.MINUTE)) + ", ");
        }
        if (calendar.get(Calendar.SECOND) > 0) {
            s.append("seconds: " + (calendar.get(Calendar.SECOND)) + ", ");
        }
        if (calendar.get(Calendar.MILLISECOND) > 1) {
            s.append("milliseconds: " + (calendar.get(Calendar.MILLISECOND)) + ", ");
        }
        s.append("total milliseconds: " + diff);
        return s.toString();
    }
1178156
def timediff(time):
    """"""
    now = datetime.datetime.utcnow()
    diff = now - time
    diff_sec = diff.total_seconds()
    return diff_sec
300255
function timeSince(date) {
		const seconds = Math.floor((new Date().getTime() / 1000) - (date / 1000));
		let interval = Math.floor(seconds / 31536000);

		if (interval > 1) {
			return interval + ' year';
		}

		interval = Math.floor(seconds / 2592000);
		if (interval > 1) {
			return interval + ' month';
		}

		interval = Math.floor(seconds / 86400);
		if (interval >= 1) {
			return interval + ' day';
		}

		interval = Math.floor(seconds / 3600);
		if (interval >= 1) {
			return interval + ' hour';
		}

		interval = Math.floor(seconds / 60);
		if (interval > 1) {
			return interval + ' min';
		}

		return Math.floor(seconds) + ' sec';
	}
873053
def _getFromTime(self, atDate=None):
        
        return getLocalTime(self.date_from, self.time_from, self.tz)
1166792
public static Date getLastDayFromCurrentMonth(Date d) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(d);                
        cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DATE));
        cal.set(Calendar.HOUR_OF_DAY, 23);
        cal.set(Calendar.MINUTE, 59);
        cal.set(Calendar.SECOND, 59);
        cal.set(Calendar.MILLISECOND, 999);
        return cal.getTime();
    }
844134
def milliseconds_offset(cls, timestamp, now=None):
        
        if isinstance(timestamp, (int, float)):
            base = timestamp
        else:
            base = cls.to_unix(timestamp)
            base += (timestamp.microsecond / 1000000)
        if now is None:
            now = time.time()
        return (now - base) * 1000
699260
public static Duration diff(Date start, Date end) {
		return fromMillis(end.getTime() - start.getTime());
	}
659779
function icaltime_compare(other) {
      var a = this.toSeconds();
      var b = other.toSeconds();
      return (a > b) - (b > a);
    }
84291
private static long getTime(int year, int month, int day, int hour,
			int minute, int second, int millisecond) {
		Calendar cal = Calendar.getInstance(Util.TIME_ZONE_UTC);
		cal.set(year, month - 1, day, hour, minute, second);
		cal.set(Calendar.MILLISECOND, millisecond);
		return cal.getTimeInMillis();
	}
14599
def _DateToEpoch(date):
  """"""
  tz_zero = datetime.datetime.utcfromtimestamp(0)
  diff_sec = int((date - tz_zero).total_seconds())
  return diff_sec * 1000000