UNPKG

art-standard-lib

Version:

The Standard Library for JavaScript that aught to be.

5 lines (4 loc) 3.28 kB
"use strict" let Caf = require('caffeine-script-runtime'); Caf.defMod(module, () => {return Caf.importInvoke(["console", "dateformat", "isString", "Date", "isNumber", "isFinite", "Error", "isDate", "formattedInspect"], [global, require('./Core'), require('./Inspect'), {dateformat: require('dateformat')}], (console, dateformat, isString, Date, isNumber, isFinite, Error, isDate, formattedInspect) => {let march1973InMilliseconds, toMilliseconds, toSeconds, toDate, secondsPerHour, secondsPerDay, firstOfHour, firstOfDay, firstOfWeek, firstOfMonth, firstOfYear, firstOfDayLocale, firstOfWeekLocale, firstOfMonthLocale, firstOfYearLocale; march1973InMilliseconds = 100000000000; return {dateFormat: function(...args) {console.warn("dateFormat is DEPRECATED - use formatDate instead"); return dateformat(...args);}, formatDate: function(value, format, utc) {if (isString(value) && !isString(format)) {format = value; value = null;}; return dateformat(toDate(value), format, utc);}, toMilliseconds: toMilliseconds = function(v) {let match, __, year, month, day; if (!(v != null && v !== false)) {return Date.now();}; if (isString(v)) {v = (() => {switch (false) {case !(match = v.match(/^(\d\d\d\d)-(\d\d)(?:-(\d\d))?$/)): ([__, year, month, day = 1] = match); return new Date(year - 0, month - 1, day - 0); case !/^\d+(\.\d+)?$/.test(v): return v - 0; default: return Date.parse(v);};})();}; return isNumber(v) ? (!isFinite(v) ? (() => {throw new Error(`toMilliseconds(${Caf.toString(v)}) - number is not finite`);})() : undefined, (v < march1973InMilliseconds) ? v * 1000 : v) : isDate(v) ? v - 0 : (() => {throw new Error(`invalid timestamp value: ${Caf.toString(v)} (${Caf.toString(formattedInspect(v))})`);})();}, toSeconds: toSeconds = function(v) {if (!(v != null && v !== false)) {return Date.now() / 1000;}; return toMilliseconds(v) / 1000;}, toDate: toDate = function(v) {if (!(v != null && v !== false)) {return new Date;}; return isDate(v) ? v : new Date(toMilliseconds(v));}, secondsPerHour: secondsPerHour = 3600, secondsPerDay: secondsPerDay = secondsPerHour * 24, firstOfHour: firstOfHour = function(time) {return (toSeconds(time) / secondsPerHour | 0) * secondsPerHour;}, firstOfDay: firstOfDay = function(time) {return (toSeconds(time) / secondsPerDay | 0) * secondsPerDay;}, firstOfWeek: firstOfWeek = function(time) {return firstOfDay(time) - Caf.mod(toDate(time).getUTCDay() - 1, 7) * secondsPerDay;}, firstOfMonth: firstOfMonth = function(time) {return firstOfDay(time) - (toDate(time).getUTCDate() - 1) * secondsPerDay;}, firstOfYear: firstOfYear = function(time) {return firstOfMonth(new Date(toDate(time).getUTCFullYear(), 0, 3));}, firstOfDayLocale: firstOfDayLocale = function(time) {return firstOfHour(time) - toDate(time).getHours() * secondsPerHour;}, firstOfWeekLocale: firstOfWeekLocale = function(time, sundayIsFirst) {let day; day = toDate(time).getDay(); if (!sundayIsFirst) {day--;}; return firstOfDayLocale(time) - secondsPerDay * (Caf.mod(day, 7));}, firstOfMonthLocale: firstOfMonthLocale = function(time) {return firstOfDayLocale(time) - (toDate(time).getDate() - 1) * secondsPerDay;}, firstOfYearLocale: firstOfYearLocale = function(time) {return new Date(toDate(time).getFullYear(), 0, 1);}};});}); //# sourceMappingURL=DateExtensions.js.map