Unrelated but handy function to calculate Unix timestamp from GMT.

@param {Array} tuple
@throws {IllegalMonthError} If the provided month element is invalid.
@throws {IllegalDayError} If the provided day element is invalid.
@api public
545556
function timegm(timegmt) {
      var year   = timegmt[0];
      var month  = timegmt[1];
      var day    = timegmt[2];
      var hour   = timegmt[3];
      var minute = timegmt[4];
      var second = timegmt[5];

      if(month < 1 || month > 12) {
        throw new IllegalMonthError();
      }

      if(day < 1 || day > (_DAYS_IN_MONTH[month] + (month === 2 && isleap(year)))) {
        throw new IllegalDayError();
      }

      if(hour < 0 || hour > 23 || minute < 0 || minute > 59 || second < 0 || second > 59) {
        throw new IllegalTimeError();
      }

      var days = _toordinal(year, month, 1) - 719163 + day - 1;
      var hours = (days * 24) + hour;
      var minutes = (hours * 60) + minute;
      var seconds = (minutes * 60) + second;

      return seconds;
    }
95420
function $$core$$ToLocalTime(date, calendar, timeZone) {
        // 1. Apply calendrical calculations on date for the given calendar and time zone to
        //    produce weekday, era, year, month, day, hour, minute, second, and inDST values.
        //    The calculations should use best available information about the specified
        //    calendar and time zone. If the calendar is "gregory", then the calculations must
        //    match the algorithms specified in ES5, 15.9.1, except that calculations are not
        //    bound by the restrictions on the use of best available information on time zones
        //    for local time zone adjustment and daylight saving time adjustment imposed by
        //    ES5, 15.9.1.7 and 15.9.1.8.
        // ###TODO###
        var d = new Date(date),
            m = 'get' + (timeZone || '');

        // 2. Return a Record with fields [[weekday]], [[era]], [[year]], [[month]], [[day]],
        //    [[hour]], [[minute]], [[second]], and [[inDST]], each with the corresponding
        //    calculated value.
        return new $$core$$Record({
            '[[weekday]]': d[m + 'Day'](),
            '[[era]]'    : +(d[m + 'FullYear']() >= 0),
            '[[year]]'   : d[m + 'FullYear'](),
            '[[month]]'  : d[m + 'Month'](),
            '[[day]]'    : d[m + 'Date'](),
            '[[hour]]'   : d[m + 'Hours'](),
            '[[minute]]' : d[m + 'Minutes'](),
            '[[second]]' : d[m + 'Seconds'](),
            '[[inDST]]'  : false // ###TODO###
        });
    }
1024837
function decodePeriodTime(map, timeStr, type){
  let times = timeStr.split('/');
  let min = Limit[type][0];
  let max = Limit[type][1];

  let remind = Number(times[0]);
  let period = Number(times[1]);

  if(period==0)
    return;

  for(let i = min; i <= max; i++){
    if(i%period == remind)
      map[i] = i;
  }
}
1366731
function _GpfDate() {
        var firstArgument = arguments[_GPF_START], values = _gpfIsISO8601String(firstArgument);
        if (values) {
            return new _GpfGenuineDate(_GpfGenuineDate.UTC.apply(_GpfGenuineDate.UTC, values));
        }
        return _gpfNewApply(_GpfGenuineDate, arguments);
    }
1149917
private static int isTodayOrTomorrow(Resources r, long dayMillis,
                                         long currentMillis, long localGmtOffset) {
        int startDay = Time.getJulianDay(dayMillis, localGmtOffset);
        int currentDay = Time.getJulianDay(currentMillis, localGmtOffset);

        int days = startDay - currentDay;
        if (days == 1) {
            return TOMORROW;
        } else if (days == 0) {
            return TODAY;
        } else {
            return NONE;
        }
    }
759514
function clfdate (dateTime) {
  var date = dateTime.getUTCDate()
  var hour = dateTime.getUTCHours()
  var mins = dateTime.getUTCMinutes()
  var secs = dateTime.getUTCSeconds()
  var year = dateTime.getUTCFullYear()

  var month = CLF_MONTH[dateTime.getUTCMonth()]

  return pad2(date) + '/' + month + '/' + year +
    ':' + pad2(hour) + ':' + pad2(mins) + ':' + pad2(secs) +
    ' +0000'
}
556588
function(str, fmt) {

            if ((!str) || (!str.indexOf) || (str.indexOf("mm")==0)) return null;

            var y = 0;
            var m = -1;
            var d = 0;
            var a = str.split(/\W+/);
            var b = fmt.match(/%./g);
            var i = 0, j = 0;
            var hr = 0;
            var min = 0;
            var sec = 0;

            for (i = 0; i < a.length; ++i) {
                if (!a[i])
                    continue;
                switch (b[i]) {
                    case "%d":
                        d = parseInt(a[i], 10);
                        break;

                    case "%m":
                        m = parseInt(a[i], 10) - 1;
                        break;

                    case "%Y":
                    case "%y":
                        y = parseInt(a[i], 10);
                        (y < 100) && (y += (y > 29) ? 1900 : 2000);
                        break;

                    case "%H":
                        hr = parseInt(a[i], 10);
                        break;

                    case "%M":
                        min = parseInt(a[i], 10);
                        break;

                    case "%S":
                        sec = parseInt(a[i], 10);
                        break;

                    default:
                        break;
                }
            }
            if (y != 0 && m != -1 && d != 0) {
                var ourDate = new Date(y, m, d, hr, min, sec);
                return ourDate;
            } else {
                //this.logger.warn('unable to parse date "' + str + '" into "' + fmt + '"');
                return false;
            }
        }
601476
function(offset) {
			var month = this.getOffsetMonth(offset)
			  , year = this.getOffsetYear(offset)

			// checks to see if february is a leap year otherwise return the respective # of days
			return (month == 1 && !(year & 3) && (year % 1e2 || !(year % 4e2))) ? 29 : this.daysInMonth[month]
		}
1095897
function (date) {
                if (date instanceof Date === false) {
                    throw new ArgumentError(
                        Logger.logMessage(Logger.LEVEL_SEVERE, "SunPosition", "computeJulianDate", "missingDate"));
                }

                var year = date.getUTCFullYear();
                var month = date.getUTCMonth() + 1;
                var day = date.getUTCDate();
                var hour = date.getUTCHours();
                var minute = date.getUTCMinutes();
                var second = date.getUTCSeconds();

                var dayFraction = (hour + minute / 60 + second / 3600) / 24;

                if (month <= 2) {
                    year -= 1;
                    month += 12;
                }

                var A = Math.floor(year / 100);
                var B = 2 - A + Math.floor(A / 4);
                var JD0h = Math.floor(365.25 * (year + 4716)) + Math.floor(30.6001 * (month + 1)) + day + B - 1524.5;

                return JD0h + dayFraction;
            }
325221
function GregMonth(month, year) {
	var me = this;
	if (typeof month == 'string') {
		month = greg.lookupMonthNum(month);
	}
	if (typeof month != 'number') {
		throw new TE('month to Hebcal.GregMonth is not a valid type');
	}
	if (typeof year != 'number') {
		throw new TE('year to Hebcal.GregMonth is not a number');
	}

	me.year = year;
	me.month = month;

	me.days = c.range(1, greg.daysInMonth(month, year))[map](function(i){
		var d = new HDate(new Date(year, month - 1, i));
		defProp(d, '__gregmonth', {
			configurable: true,
			writable: true,
			value: me
		});
		return d;
	});

	me[length] = me.days[length];

	me.hebmonths = [
		{month: me[getDay]( 1)[getMonth](), year: me[getDay]( 1)[getFullYear]()},
		{month: me[getDay](-1)[getMonth](), year: me[getDay](-1)[getFullYear]()}
	].filter(function(val, i, arr){
		return i === 0 || val.month != arr[0].month;
	});

	defProp(me, 'il', getset(function(){
		return me[getDay](1).il;
	}, function(il){
		me.days.forEach(function(d){
			d.il = il;
		});
	}));

	defProp(me, 'lat', getset(function(){
		return me[getDay](1).lat;
	}, function(lat){
		me.days.forEach(function(d){
			d.lat = lat;
		});
	}));
	defProp(me, 'long', getset(function(){
		return me[getDay](1).long;
	}, function(lon){
		me.days.forEach(function(d){
			d.long = lon;
		});
	}));

	return me;
}
964796
function jdnToGregorian(jdn, JD_OFFSET = JD_EPOCH_OFFSET_GREGORIAN, leapYear = isGregorianLeap) {
  const nMonths = 12;
  const monthDays = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

  const r2000 = mod((jdn - JD_OFFSET), 730485);
  const r400 = mod((jdn - JD_OFFSET), 146097);
  const r100 = mod(r400, 36524);
  const r4 = mod(r100, 1461);

  let n = mod(r4, 365) + 365 * Math.floor(r4 / 1460);
  const s = Math.floor(r4 / 1095);

  const aprime = 400 * Math.floor((jdn - JD_OFFSET) / 146097)
               + 100 * Math.floor(r400 / 36524)
               + 4 * Math.floor(r100 / 1461)
               + Math.floor(r4 / 365)
               - Math.floor(r4 / 1460)
               - Math.floor(r2000 / 730484);
  const year = aprime + 1;
  const t = Math.floor((364 + s - n) / 306);
  let month = t * (Math.floor(n / 31) + 1) + (1 - t) * (Math.floor((5 * (n - s) + 13) / 153) + 1);
  n += 1 - Math.floor(r2000 / 730484);
  let day = n;

  if ((r100 === 0) && (n === 0) && (r400 !== 0)) {
    month = 12;
    day = 31;
  } else {
    monthDays[2] = (leapYear(year)) ? 29 : 28;
    for (let i = 1; i <= nMonths; i += 1) {
      if (n <= monthDays[i]) {
        day = n;
        break;
      }

      n -= monthDays[i];
    }
  }

  return { year, month, day };
}
1287352
def utcfromtimestamp(cls, t):
        ""
        t, frac = divmod(t, 1.0)
        us = int(frac * 1e6)

        # If timestamp is less than one microsecond smaller than a
        # full second, us can be rounded up to 1000000.  In this case,
        # roll over to seconds, otherwise, ValueError is raised
        # by the constructor.
        if us == 1000000:
            t += 1
            us = 0
        y, m, d, hh, mm, ss, weekday, jday, dst = _time.gmtime(t)
        ss = min(ss, 59)    # clamp out leap seconds if the platform has them
        return cls(y, m, d, hh, mm, ss, us)
335312
function getDate (type, min, max, format, options) {
  var ret;

  // Juggle the arguments if the user didn't supply a format string
  if (!options) {
    options = format;
    format = null;
  }

  if (type === 'date') {
    min = Date.parse(min);
    max = Date.parse(max);
  } else if (type === 'time') {
    min = Date.parse('1970-01-01T' + min);
    max = Date.parse('1970-01-01T' + max);
  }

  ret = utils.randomDate(min, max);

  if (format === 'unix') {
    // We need to undo the timezone offset fix from utils.randomDate()
    ret = Math.floor((ret.getTime() - ret.getTimezoneOffset() * 60000) / 1000);
  } else if (format) {
    ret = fecha.format(ret, format);
  } else if (type === 'time') {
    // Time has a default format if one is not specified
    ret = fecha.format(ret, 'HH:mm');
  }

  return ret;
}
395467
function tlid__toDate(str) {
  // var dt = new Date(str); //@s 181223 Wont work as it require "-"
  var tlidValue = tlid__xtr(str);
  var r = "";

  var y = "20" + getchk_sub(tlidValue, 0, 2); // will bug in 82 years, well, I am not pessimistic here but possibly will not be there or if I do, I wont care so much... I must add a reminder for 2099/12/31 to update tlid.todate.... ;)

  var m = getchk_sub(tlidValue, 2, 4) - 1;
  var d = getchk_sub(tlidValue, 4, 6);

  r = `${y}/${m != "" ? m : 1}/${d != "" ? d : 1}`;

  if (debugDt) console.log(`Year: ${y}`);
  if (debugDt) console.log(`Month: ${m}`);
  if (debugDt) console.log(`Day: ${d}`);
  var h = "00";
  var M = "00";
  var s = "00";
  var ms = "000";

  try {

    h = getchk_sub(tlidValue, 6, 8);
    if (debugDt) console.log(`Hour: ${h}`);




    M = getchk_sub(tlidValue, 8, 10);
    if (debugDt) console.log(`Minutes: ${M}`);



    s = getchk_sub(tlidValue, 10, 12);
    if (debugDt) console.log(`Seconds: ${s}`);



    ms = getchk_sub(tlidValue, 12, 13);
    ms = getchk_sub(tlidValue, 12, 14);
    ms = getchk_sub(tlidValue, 12, 15);
    ms = getchk_sub(tlidValue, 12, 16);

    if (debugDt) console.log(`MiliSeconds: ${ms}`);


  } catch (error) {

  }
  if (debugDt) console.log("R: " + r);

  var dt = new Date(r);

  if (y != "")
    if (m != "")
      if (d != "")
        if (h != "")
          if (M != "")
            if (s != "")
              if (ms != "")
                dt = new Date(Date.UTC(y, m, d, h, M, s, ms));
              else
                dt = new Date(Date.UTC(y, m, d, h, M, s));
            else
              dt = new Date(Date.UTC(y, m, d, h, M));
          else
            dt = new Date(Date.UTC(y, m, d, h));
        else
          dt = new Date(Date.UTC(y, m, d));
      else
        dt = new Date(Date.UTC(y, m));
    else
      dt = new Date(Date.UTC(y));

  if (debugDt) console.log("TZ: " + dt.getTimezoneOffset());

  return dt;
}
966860
function (t, use_UTC) {
		if (!use_UTC) {
			return [
				String("0" + t.getHours()).substr(-2),
				String("0" + t.getMinutes()).substr(-2)
			].join(":");
		}
		return [
			String("0" + t.getUTCHours()).substr(-2),
			String("0" + t.getUTCMinutes()).substr(-2)
		].join(":");
	}
1367435
function (tuple) {
		var line = this.readLine();
		var colon = line.indexOf(":");
		if (colon == -1) throw "Invalid line: " + line;
		var i = 0, lastMatch = colon + 1;
		for (; i < 3; i++) {
			var comma = line.indexOf(",", lastMatch);
			if (comma == -1) break;
			tuple[i] = this.trim(line.substr(lastMatch, comma - lastMatch));
			lastMatch = comma + 1;
		}
		tuple[i] = this.trim(line.substring(lastMatch));
		return i + 1;
	}
460215
def unixtime2str(timestamp, fmt='%Y-%m-%d %H:%M:%S'):
    
    dt = None
    try:
        timestamp = time.localtime(timestamp)
        dt = time.strftime(fmt, timestamp)
    except Exception as err:
        print(err)
    return dt