WIP: try to convert to ES modules
This commit is contained in:
parent
ec5b050496
commit
299a08b6a3
29 changed files with 3003 additions and 2014 deletions
|
|
@ -1,5 +1,17 @@
|
|||
'use strict';
|
||||
|
||||
import * as OxObject from './Object.js';
|
||||
import * as OxConstants from './Constants.js';
|
||||
import * as OxMath from './Math.js';
|
||||
|
||||
const Ox = {};
|
||||
|
||||
Object.assign(Ox,
|
||||
OxObject,
|
||||
OxConstants,
|
||||
OxMath
|
||||
);
|
||||
|
||||
//@ Ox.getDate <f> Get the day of a date, optionally UTC
|
||||
// see Ox.setSeconds for source code
|
||||
|
||||
|
|
@ -21,7 +33,7 @@ Ox.getDateInWeek <f> Get the date that falls on a given weekday in the same week
|
|||
"Monday, December 27, 1999"
|
||||
@*/
|
||||
// fixme: why is this Monday first? shouldn't it then be "getDateInISOWeek"??
|
||||
Ox.getDateInWeek = function(date, weekday, utc) {
|
||||
export function getDateInWeek(date, weekday, utc) {
|
||||
date = Ox.makeDate(date);
|
||||
var sourceWeekday = Ox.getISODay(date, utc),
|
||||
targetWeekday = Ox.isNumber(weekday) ? weekday
|
||||
|
|
@ -50,7 +62,7 @@ Ox.getDayOfTheYear <f> Get the day of the year for a given date
|
|||
> Ox.getDayOfTheYear(new Date("12/31/2004"))
|
||||
366
|
||||
@*/
|
||||
Ox.getDayOfTheYear = function(date, utc) {
|
||||
export function getDayOfTheYear(date, utc) {
|
||||
date = Ox.makeDate(date);
|
||||
var month = Ox.getMonth(date, utc),
|
||||
year = Ox.getFullYear(date, utc);
|
||||
|
|
@ -68,7 +80,7 @@ Ox.getDaysInMonth <f> Get the number of days in a given month
|
|||
> Ox.getDaysInMonth(new Date('01/01/2004'), "February")
|
||||
29
|
||||
@*/
|
||||
Ox.getDaysInMonth = function(year, month) {
|
||||
export function getDaysInMonth(year, month) {
|
||||
year = Ox.makeYear(year);
|
||||
month = Ox.isNumber(month) ? month
|
||||
: Ox.indexOf(Ox.MONTHS, function(v) {
|
||||
|
|
@ -87,7 +99,7 @@ Ox.getDaysInYear <f> Get the number of days in a given year
|
|||
> Ox.getDaysInYear(new Date('01/01/2004'))
|
||||
366
|
||||
@*/
|
||||
Ox.getDaysInYear = function(year, utc) {
|
||||
export function getDaysInYear(year, utc) {
|
||||
return 365 + Ox.isLeapYear(Ox.makeYear(year, utc));
|
||||
};
|
||||
|
||||
|
|
@ -97,7 +109,7 @@ Ox.getFirstDayOfTheYear <f> Get the weekday of the first day of a given year
|
|||
> Ox.getFirstDayOfTheYear(new Date('01/01/2000'))
|
||||
6
|
||||
@*/
|
||||
Ox.getFirstDayOfTheYear = function(date, utc) {
|
||||
export function getFirstDayOfTheYear(date, utc) {
|
||||
date = Ox.makeDate(date);
|
||||
date = Ox.setMonth(date, 0, utc);
|
||||
date = Ox.setDate(date, 1, utc);
|
||||
|
|
@ -114,7 +126,7 @@ Ox.getISODate <f> Get the ISO date string for a given date
|
|||
> Ox.getISODate(new Date('01/01/2000'))
|
||||
'2000-01-01T00:00:00Z'
|
||||
@*/
|
||||
Ox.getISODate = function(date, utc) {
|
||||
export function getISODate(date, utc) {
|
||||
return Ox.formatDate(Ox.makeDate(date), '%FT%TZ', utc);
|
||||
};
|
||||
|
||||
|
|
@ -128,7 +140,7 @@ Ox.getISODay <f> Get the ISO weekday of a given date
|
|||
> Ox.getISODay(new Date('01/03/2000'))
|
||||
1
|
||||
@*/
|
||||
Ox.getISODay = function(date, utc) {
|
||||
export function getISODay(date, utc) {
|
||||
return Ox.getDay(Ox.makeDate(date), utc) || 7;
|
||||
};
|
||||
|
||||
|
|
@ -143,7 +155,7 @@ Ox.getISOWeek <f> Get the ISO week of a given date
|
|||
1
|
||||
@*/
|
||||
|
||||
Ox.getISOWeek = function(date, utc) {
|
||||
export function getISOWeek(date, utc) {
|
||||
date = Ox.makeDate(date);
|
||||
// set date to Thursday of the same week
|
||||
return Math.floor((Ox.getDayOfTheYear(Ox.setDate(
|
||||
|
|
@ -162,7 +174,7 @@ Ox.getISOYear <f> Get the ISO year of a given date
|
|||
2000
|
||||
@*/
|
||||
|
||||
Ox.getISOYear = function(date, utc) {
|
||||
export function getISOYear(date, utc) {
|
||||
date = Ox.makeDate(date);
|
||||
// set date to Thursday of the same week
|
||||
return Ox.getFullYear(Ox.setDate(
|
||||
|
|
@ -180,7 +192,7 @@ Ox.getISOYear = function(date, utc) {
|
|||
// see Ox.setSeconds for source code
|
||||
|
||||
//@ Ox.getTime <f> Alias for `+new Date()`
|
||||
Ox.getTime = function(utc) {
|
||||
export function getTime(utc) {
|
||||
return +new Date() - (utc ? Ox.getTimezoneOffset() : 0);
|
||||
};
|
||||
|
||||
|
|
@ -189,7 +201,7 @@ Ox.getTimezoneOffset <f> Get the local time zone offset in milliseconds
|
|||
([date]) -> <n> Offset in milliseconds
|
||||
date <d|u> Return offset at this date (if undefined, return current offset)
|
||||
@*/
|
||||
Ox.getTimezoneOffset = function(date) {
|
||||
export function getTimezoneOffset(date) {
|
||||
return Ox.makeDate(date).getTimezoneOffset() * 60000;
|
||||
};
|
||||
|
||||
|
|
@ -201,7 +213,7 @@ Ox.getTimezoneOffsetString <f> Get the local time zone offset as a string
|
|||
> Ox.getTimezoneOffsetString(new Date('01/01/2000')).length
|
||||
5
|
||||
@*/
|
||||
Ox.getTimezoneOffsetString = function(date) {
|
||||
export function getTimezoneOffsetString(date) {
|
||||
var offset = Ox.makeDate(date).getTimezoneOffset();
|
||||
return (offset <= 0 ? '+' : '-')
|
||||
+ Ox.pad(Math.floor(Math.abs(offset) / 60), 2)
|
||||
|
|
@ -218,7 +230,7 @@ Ox.getWeek <f> Get the week of a given day
|
|||
> Ox.getWeek(new Date('01/03/2000'))
|
||||
1
|
||||
@*/
|
||||
Ox.getWeek = function(date, utc) {
|
||||
export function getWeek(date, utc) {
|
||||
date = Ox.makeDate(date);
|
||||
return Math.floor((Ox.getDayOfTheYear(date, utc)
|
||||
+ Ox.getFirstDayOfTheYear(date, utc) - 1) / 7);
|
||||
|
|
@ -233,7 +245,7 @@ Ox.isLeapYear <f> Returns true if a given year is a leap year
|
|||
> Ox.isLeapYear(new Date('01/01/2004'))
|
||||
true
|
||||
@*/
|
||||
Ox.isLeapYear = function(year, utc) {
|
||||
export function isLeapYear(year, utc) {
|
||||
year = Ox.makeYear(year, utc);
|
||||
return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
|
||||
};
|
||||
|
|
@ -255,7 +267,7 @@ Ox.makeDate <f> Takes a date, number or string, returns a date
|
|||
> Ox.formatDate(Ox.makeDate(Ox.parseDate('-50')), '%Y')
|
||||
'-50'
|
||||
@*/
|
||||
Ox.makeDate = function(date) {
|
||||
export function makeDate(date) {
|
||||
// Safari 4/5 (<= 534.59.10) doesn't parse YYYY, YYYY-MM or YYYY-MM-DD
|
||||
if (Ox.isString(date) && Ox.isInvalidDate(new Date(date))) {
|
||||
if (/^\d{4}$/.test(date)) {
|
||||
|
|
@ -280,7 +292,7 @@ Ox.makeYear <f> Takes a date, number or string, returns a year
|
|||
> Ox.makeYear('1970')
|
||||
1970
|
||||
@*/
|
||||
Ox.makeYear = function(date, utc) {
|
||||
export function makeYear(date, utc) {
|
||||
return Ox.isDate(date) ? Ox.getFullYear(date, utc) : parseInt(date, 10);
|
||||
};
|
||||
|
||||
|
|
@ -295,7 +307,7 @@ Ox.parseDate <f> Takes a string ('YYYY-MM-DD HH:MM:SS.MMM') and returns a date
|
|||
> Ox.parseDate('50', true).getUTCFullYear()
|
||||
50
|
||||
@*/
|
||||
Ox.parseDate = function(string, utc) {
|
||||
export function parseDate(string, utc) {
|
||||
var date,
|
||||
defaults = [, 1, 1, 0, 0, 0, 0],
|
||||
values = /(-?\d+)-?(\d+)?-?(\d+)? ?(\d+)?:?(\d+)?:?(\d+)?\.?(\d+)?/
|
||||
|
|
@ -320,7 +332,7 @@ Ox.parseDate = function(string, utc) {
|
|||
};
|
||||
|
||||
/*
|
||||
Ox.parseDateRange = function(start, end, utc) {
|
||||
export function parseDateRange(start, end, utc) {
|
||||
var dates = [
|
||||
Ox.parseDate(start, utc),
|
||||
Ox.parseDate(end, utc)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue