new AstroDate(arguments) → {AstroDate}
new AstroDate();
new AstroDate(value);
new AstroDate(dateString);
new AstroDate(dateObject);
new AstroDate(astroDateObject);
new AstroDate(year[, month, day, hour, minute, second, millisecond, offset][, options]);
- value
Integer value representing the number of milliseconds since 1 January 1970 00:00:00 UTC (Unix Epoch). - dateString
String value representing a date. The string must be in the format of ISO8601. - dateObject
A Javascript Date object. - astroDateObject
An AstroDate object. - year
Integer or string value representing the year. The year must always be provided in full (e.g. 98 is treated as 98, not 1998). - month
Integer or string value representing the month, beginning with 0 for January to 11 for December. - day
Integer or string value representing the day of the month. - hour
Integer or string value representing the hour of the day. - minute
Integer or string value representing the minute segment of a time. - second
Integer or string value representing the second segment of a time. - millisecond
Integer or string value representing the millisecond segment of a time. - offset
Integer or string value representing the offset from UT in seconds. - options
null or object Must be used when only year is specified. Allows date to be specified in Julian Calender (more/changes coming).
This:
Parameters:
Name | Type | Argument | Description |
---|---|---|---|
arguments |
* |
<optional> <repeatable> |
Returns:
- Type
- AstroDate
Example
// If no arguments are provided, the constructor creates an AstroDate object for the
// current date and time according to system settings.
new AstroDate();
// Integer value representing the number of milliseconds since 1 January 1970 00:00:00 UTC (Unix Epoch).
// -9,007,199,254,740,992 to 9,007,199,254,740,992 or NaN
new AstroDate(819170640000); //1995-12-17T03:24:00.000Z
new AstroDate(NaN); //Invalid Date
// String value representing a date. The string must be in the format of ISO8601.
new AstroDate('1995-12-17T03:24:00.000Z');
// A Javascript Date object.
new AstroDate(new Date(1995, 12, 17, 3, 24, 0, 0));
// An AstroDate object.
new AstroDate(new AstroDate(1995, 12, 17, 3, 24, 0, 0, 3600)); // offset is same as '-01:00:00'
// Using an arguments list.
new AstroDate(1995, null);
new AstroDate(1995, {offset: -3600}); // offset is same as '+01:00:00'
new AstroDate(55, {julian: true, offset: -3600});
// year 55 of the Julian Calendar, offset is same as '+01:00:00'
new AstroDate(1995, 12, 17, 3, 24, 0, 0, -3600); // offset is same as '+01:00:00'
new AstroDate('1995', '12', '17', '3', '24', '0', '0', '-5400'); // offset is same as '+01:30:00'
new AstroDate('1995', '12', '17', '3', '24', '0', '0', '+01:30:00'); // offset is same as -5400
new AstroDate('-10', '5', '7', {julian: true}); // year -10 of the Julian Calendar
Members
-
<static> BigNumber :object
-
A JavaScript library for arbitrary-precision decimal and non-decimal arithmetic
Type:
- object
-
<static> utilx :object
-
The Javascript library that AstroDate is built on for cross environment compatability.
Type:
- object
Methods
-
<static> isAstroDate(inputArg) → {boolean}
-
Tests if the provided input is an instance of AstroDate.
Parameters:
Name Type Description inputArg
object Returns:
- Type
- boolean
-
<static> jd() → {string}
-
The Julian Date (JD) of any instant is the Julian day number for the preceding noon plus the fraction of the day since that instant. Julian Dates are expressed as a Julian day number with a decimal fraction added. For example, the Julian Date for 00:30:00.0 UT 1 January 2013 is 2456293.520833334
Returns:
- Type
- string
-
<static> jdn() → {string}
-
The Julian Day Number (JDN) is the integer assigned to a whole solar day in the Julian day count starting from noon Greenwich Mean Time, with Julian day number 0 assigned to the day starting at noon on 1 January 4713 BC proleptic Julian calendar (24 November 4714 BC, in the proleptic Gregorian calendar). For example, the Julian day number for 1 January 2000 was 2,451,545.0
Returns:
- Type
- string
-
<static> lang(id, object, freeze) → {string}
-
Parameters:
Name Type Argument Description id
string <optional>
object
object <optional>
freeze
boolean <optional>
Returns:
- Type
- string
-
<static> langs() → {array.<String>}
-
Returns:
- Type
- array.<String>
-
<static> leapSeconds(object, freeze) → {object}
-
Parameters:
Name Type Description object
object freeze
boolean Returns:
- Type
- object
-
<static> locale(id) → {string}
-
Parameters:
Name Type Argument Description id
string <optional>
The string representing the required locale, e.g. 'en_GB' Returns:
Returns the current locale, e.g. 'en_GB'- Type
- string
-
<static> mjd() → {string}
-
The Modified Julian Date (MJD) was introduced by the Smithsonian Astrophysical Observatory in 1957 to record the orbit of Sputnik via an IBM 704 (36-bit machine) and using only 18 bits until August 7, 2576. MJD is the epoch of OpenVMS, using 63-bit date/time postponing the next Y2K campaign to July 31, 31086 02:48:05.47. MJD is defined relative to midnight, rather than noon.
Returns:
- Type
- string
-
<static> normaliseUnits(unitString)
-
Parameters:
Name Type Description unitString
string -
<static> now() → {string}
-
Time is measured in ECMAScript in milliseconds since 01 January, 1970 UTC. In time values leap seconds are ignored. It is assumed that there are exactly 86,400,000 milliseconds per day.
Returns:
- Type
- string
-
<static> supplemental(object, freeze) → {object}
-
Parameters:
Name Type Description object
object freeze
boolean Returns:
- Type
- object
-
<static> unix() → {string}
-
The time now represented in Unix time. Unix time, or POSIX time, is a system for describing instants in time, defined as the number of seconds that have elapsed since 00:00:00 Coordinated Universal Time (UTC), Thursday, 1 January 1970, not counting leap seconds. It is used widely in Unix-like and many other operating systems and file formats. Due to its handling of leap seconds, it is neither a linear representation of time nor a true representation of UTC. Unix time may be checked on most Unix systems by typing date +%s on the command line.
Returns:
- Type
- string
-
<static> version() → {string}
-
Returns:
- Type
- string
-
array(dateArray)
-
This:
Parameters:
Name Type Argument Description dateArray
array <optional>
-
calendarToWeekDate()
-
This:
-
civil() → {boolean}
-
This:
Returns:
- Type
- boolean
-
clone() → {AstroDate}
-
This:
Returns:
- Type
- AstroDate
-
currentLang() → {string}
-
This:
Returns:
- Type
- string
-
date(date)
-
This:
Parameters:
Name Type Argument Description date
window.Date <optional>
-
daysInMonth() → {number}
-
This:
Returns:
- Type
- number
-
daysInYear() → {number}
-
This:
Returns:
- Type
- number
-
deltaTime()
-
This:
-
easter()
-
This:
-
format(pattern)
-
Date and time formats are specified by date and time pattern strings. Within date and time pattern strings, all unquoted ASCII letters [A-Za-z] are reserved as pattern letters representing calendar fields.
astrodate
supports the date and time formatting algorithm and pattern letters defined by UTS#35 Unicode Locale Data Markup Language (LDML). The following pattern letters are currently available:Field Sym. No. Example Description era G 1..3 AD Era - Replaced with the Era string for the current date. One to three letters for the abbreviated form, four letters for the long form, five for the narrow form. 4 Anno Domini 5 A year y 1..n 1996 Year. Normally the length specifies the padding, but for two letters it also specifies the maximum length. Example: Year y yy yyy yyyy yyyyy AD 1 1 01 001 0001 00001 AD 12 12 12 012 0012 00012 AD 123 123 23 123 0123 00123 AD 1234 1234 34 1234 1234 01234 AD 12345 12345 45 12345 12345 12345 Y 1..n 1997 Year (in "Week of Year" based calendars). Normally the length specifies the padding, but for two letters it also specifies the maximum length. This year designation is used in ISO year-week calendar as defined by ISO 8601, but can be used in non-Gregorian based calendar systems where week date processing is desired. May not always be the same value as calendar year. u 1..n 4601 Extended year. This is a single number designating the year of this calendar system, encompassing all supra-year fields. For example, for the Julian calendar system, year numbers are positive, with an era of BCE or CE. An extended year value for the Julian calendar system assigns positive values to CE years and negative values to BCE years, with 1 BCE being year 0. U 1..3 甲子 Cyclic year name. Calendars such as the Chinese lunar calendar (and related calendars) and the Hindu calendars use 60-year cycles of year names. Use one through three letters for the abbreviated name, four for the full name, or five for the narrow name (currently the data only provides abbreviated names, which will be used for all requested name widths). If the calendar does not provide cyclic year name data, or if the year value to be formatted is out of the range of years for which cyclic name data is provided, then numeric formatting is used (behaves like 'y'). 4 (currently also 甲子) 5 (currently also 甲子) quarter Q 1..2 02 Quarter - Use one or two for the numerical quarter, three for the abbreviation, or four for the full name. 3 Q2 4 2nd quarter q 1..2 02 Stand-Alone Quarter - Use one or two for the numerical quarter, three for the abbreviation, or four for the full name. 3 Q2 4 2nd quarter month M 1..2 09 Month - Use one or two for the numerical month, three for the abbreviation, four for the full name, or five for the narrow name. 3 Sept 4 September 5 S L 1..2 09 Stand-Alone Month - Use one or two for the numerical month, three for the abbreviation, or four for the full name, or 5 for the narrow name. 3 Sept 4 September 5 S week w 1..2 27 Week of Year. W 1 3 Week of Month. From 0..5. The first week of the month is the first week that contains a Thursday. This is based on the ICU definition of week of month, and correlates to the ISO8601 week of year definition. A day in the week before the week with the first Thursday will be week 0. day d 1..2 1 Date - Day of the month D 1..3 345 Day of year F 1 2 Day of Week in Month. The example is for the 2nd Wed in July g 1..n 2451334 Modified Julian day. This is different from the conventional Julian day number in two regards. First, it demarcates days at local zone midnight, rather than noon GMT. Second, it is a local number; that is, it depends on the local time zone. It can be thought of as a single number that encompasses all the date-related fields. week
dayE 1..2 2 Day of week - Use one through two for ISO number, or three for the short day, or four for the full name, five for the narrow name, or six for the short name. 3 Tue 4 Tuesday 5 T 6 Tu e 1..2 2 Local day of week. Same as E except adds a numeric value that will depend on the local starting day of the week, using one or two letters. For this example, Monday is the first day of the week. 3 Tue 4 Tuesday 5 T 6 Tu c 1..2 2 Stand-Alone local day of week - Use one or two letters for the local numeric value (same as 'e'), three for the short day, four for the full name, five for the narrow name, or six for the short name. 3 Tue 4 Tuesday 5 T 6 Tu period a 1 AM AM or PM hour h 1..2 11 Hour [1-12]. When used in skeleton data or in a skeleton passed in an API for flexible data pattern generation, it should match the 12-hour-cycle format preferred by the locale (h or K); it should not match a 24-hour-cycle format (H or k). Use hh for zero padding. H 1..2 13 Hour [0-23]. When used in skeleton data or in a skeleton passed in an API for flexible data pattern generation, it should match the 24-hour-cycle format preferred by the locale (H or k); it should not match a 12-hour-cycle format (h or K). Use HH for zero padding. K 1..2 0 Hour [0-11]. When used in a skeleton, only matches K or h, see above. Use KK for zero padding. k 1..2 24 Hour [1-24]. When used in a skeleton, only matches k or H, see above. Use kk for zero padding. minute m 1..2 59 Minute. Use one or two for zero padding. second s 1..2 12 Second. Use one or two for zero padding. S 1..n 3456 Fractional Second - truncates (like other time fields) to the count of letters. (example shows display using pattern SSSS for seconds value 12.34567) A 1..n 69540000 Milliseconds in day. This field behaves exactly like a composite of all time-related fields, not including the zone fields. As such, it also reflects discontinuities of those fields on DST transition days. On a day of DST onset, it will jump forward. On a day of DST cessation, it will jump backward. This reflects the fact that is must be combined with the offset field to obtain a unique local time value. zone z 1..3 PDT The short specific non-location format. Where that is unavailable, falls back to the short localized GMT format ("O"). 4 Pacific Daylight Time The long specific non-location format. Where that is unavailable, falls back to the long localized GMT format ("OOOO"). Z 1..3 -0800 The ISO8601 basic format with hours, minutes and optional seconds fields. The format is equivalent to RFC 822 zone format (when optional seconds field is absent). This is equivalent to the "xxxx" specifier. 4 GMT-8:00 The long localized GMT format. This is equivalent to the "OOOO" specifier. 5 -08:00
-07:52:58The ISO8601 extended format with hours, minutes and optional seconds fields. The ISO8601 UTC indicator "Z" is used when local time offset is 0. This is equivalent to the "XXXXX" specifier. O 1 GMT-8 The short localized GMT format. 4 GMT-08:00 The long localized GMT format. v 1 PT The short generic non-location format. Where that is unavailable, falls back to the generic location format ("VVVV"), then the short localized GMT format as the final fallback. 4 Pacific Time The long generic non-location format. Where that is unavailable, falls back to generic location format ("VVVV"). V 1 uslax NOT SUPPORTED! The short time zone ID. Where that is unavailable, the special short time zone ID unk (Unknown Zone) is used.
Note: This specifier was originally used for a variant of the short specific non-location format, but it was deprecated in the later version of the LDML specification. In CLDR 23/ICU 51, the definition of the specifier was changed to designate a short time zone ID.2 America/Los_Angeles NOT SUPPORTED! The long time zone ID. 3 Los Angeles NOT SUPPORTED! The exemplar city (location) for the time zone. Where that is unavailable, the localized exemplar city name for the special zone Etc/Unknown is used as the fallback (for example, "Unknown City"). 4 Los Angeles Time The generic location format. Where that is unavailable, falls back to the long localized GMT format ("OOOO"; Note: Fallback is only necessary with a GMT-style Time Zone ID, like Etc/GMT-830.)
This is especially useful when presenting possible timezone choices for user selection, since the naming is more uniform than the "v" format.X 1 -08
+0530
ZThe ISO8601 basic format with hours field and optional minutes field. The ISO8601 UTC indicator "Z" is used when local time offset is 0. 2 -0800
ZThe ISO8601 basic format with hours and minutes fields. The ISO8601 UTC indicator "Z" is used when local time offset is 0. 3 -08:00
ZThe ISO8601 extended format with hours and minutes fields. The ISO8601 UTC indicator "Z" is used when local time offset is 0. 4 -0800
-075258
ZThe ISO8601 basic format with hours, minutes and optional seconds fields. (Note: The seconds field is not supported by the ISO8601 specification.) The ISO8601 UTC indicator "Z" is used when local time offset is 0. 5 -08:00
-07:52:58
ZThe ISO8601 extended format with hours, minutes and optional seconds fields. (Note: The seconds field is not supported by the ISO8601 specification.) The ISO8601 UTC indicator "Z" is used when local time offset is 0. x 1 -08
+0530The ISO8601 basic format with hours field and optional minutes field. 2 -0800 The ISO8601 basic format with hours and minutes fields. 3 -08:00 The ISO8601 extended format with hours and minutes fields. 4 -0800
-075258The ISO8601 basic format with hours, minutes and optional seconds fields. (Note: The seconds field is not supported by the ISO8601 specification.) 5 -08:00
-07:52:58The ISO8601 extended format with hours, minutes and optional seconds fields. (Note: The seconds field is not supported by the ISO8601 specification.) Any characters in the pattern that are not in the ranges of ['a'..'z'] and ['A'..'Z'] will be treated as quoted text. For instance, characters like ':', '.', ' ', '#' and '@' will appear in the resulting time text even they are not embraced within single quotes.
A pattern containing any invalid pattern letter will result in a thrown exception during formatting.
This:
Parameters:
Name Type Description pattern
string -
<protected> getter(key) → {*}
-
Gets the value of a specific internal property.
Parameters:
Name Type Description key
* Returns:
- Type
- *
-
getTime()
-
This:
-
gregorian() → {boolean}
-
This:
Returns:
- Type
- boolean
-
isCivil() → {boolean}
-
This:
Returns:
- Type
- boolean
-
isDT() → {boolean}
-
This:
Returns:
- Type
- boolean
-
isGregorian() → {boolean}
-
This:
Returns:
- Type
- boolean
-
isJulian() → {boolean}
-
This:
Returns:
- Type
- boolean
-
isLeapYear()
-
This:
-
isLocal() → {boolean}
-
This:
Returns:
- Type
- boolean
-
isRaw() → {boolean}
-
This:
Returns:
- Type
- boolean
-
isTT() → {boolean}
-
This:
Returns:
- Type
- boolean
-
isTT2UT() → {boolean}
-
This:
Returns:
- Type
- boolean
-
isUT() → {boolean}
-
This:
Returns:
- Type
- boolean
-
isUT2TT() → {boolean}
-
This:
Returns:
- Type
- boolean
-
isValid() → {boolean}
-
This:
Returns:
- Type
- boolean
-
isWeekDay()
-
This:
-
isWeekend()
-
This:
-
jd(jd) → {string|undefined}
-
The Julian Date (JD) of any instant is the Julian day number for the preceding noon plus the fraction of the day since that instant. Julian Dates are expressed as a Julian day number with a decimal fraction added. For example, the Julian Date for 00:30:00.0 UT 1 January 2013 is 2456293.520833334 If argument is passed then this function acts as a setter; otherwise it is a getter. If AstroDate is invalid then undefined is returned. Throws an error if the argument is not of the correct type.
This:
Parameters:
Name Type Argument Description jd
number | string <optional>
Returns:
- Type
- string | undefined
-
jdn()
-
This:
-
json(jsonString) → {string}
-
This:
Parameters:
Name Type Argument Description jsonString
string <optional>
Returns:
- Type
- string
-
julian() → {boolean}
-
This:
Returns:
- Type
- boolean
-
lang(id) → {string}
-
This:
Parameters:
Name Type Argument Description id
string <optional>
Returns:
- Type
- string
-
local() → {AstroDate}
-
This:
Returns:
- Type
- AstroDate
-
locale(id) → {string}
-
This:
Parameters:
Name Type Argument Description id
string <optional>
Returns:
- Type
- string
-
mjd()
-
This:
-
object(dateObject)
-
This:
Parameters:
Name Type Argument Description dateObject
object <optional>
-
parse(isoString)
-
This:
Parameters:
Name Type Description isoString
string -
raw() → {AstroDate}
-
This:
Returns:
- Type
- AstroDate
-
<protected> setter(key, value) → {AstroDate}
-
Sets the value of a specific internal property.
This:
Parameters:
Name Type Description key
* value
* Returns:
- Type
- AstroDate
-
timeTo(unit)
-
This:
Parameters:
Name Type Description unit
string -
toDateString(pattern) → {string}
-
This:
Parameters:
Name Type Argument Description pattern
string <optional>
Returns:
- Type
- string
-
toISOString() → {string}
-
This:
Returns:
- Type
- string
-
toJSON() → {string}
-
This:
Returns:
- Type
- string
-
toString(pattern) → {string}
-
This:
Parameters:
Name Type Argument Description pattern
string <optional>
Returns:
- Type
- string
-
toTimeString(pattern) → {string}
-
This:
Parameters:
Name Type Argument Description pattern
string <optional>
Returns:
- Type
- string
-
TT() → {boolean}
-
This:
Returns:
- Type
- boolean
-
TT2UT() → {boolean}
-
This:
Returns:
- Type
- boolean
-
unix()
-
This:
-
UT() → {AstroDate}
-
This:
Returns:
- Type
- AstroDate
-
UT2TT() → {boolean}
-
This:
Returns:
- Type
- boolean
-
valueOf() → {string}
-
This:
Returns:
- Type
- string
-
zone()
-
This: