0.7.10 • Published 9 years ago

astrodate v0.7.10

Weekly downloads
3
License
-
Repository
github
Last release
9 years ago

Master

Build Status

Dependency Status

Dev Dependency Status

Coverage Status

NPM version

browser support

#AstroDate 0.7.10

Graham Fairweather xotic750@gmail.com

Still very much work in progress, so there are bugs and the API has not been fully defined (or documented) and is subject to major changes.

The idea behind the project is to not rely on Javascript's rather flaky Date object, give better accuracy, flexibility and be cross-browser.

Besides the standard Gregorian calendar, the Julian calendar is also available. This allows for AstroDate to be used in astronomical calculations. A set of routines will be made available for changing between systems and methods for obtaining Julian Day Numbers, Julian Dates, Modified Julian Dates, Delta Time and Terestrial Time etc.

For dates beyond the normal Date range and Javascript's limited number arithmetic, it is necessary to do the Math using arbitrary-precision arithmetic, BigNumber.js is the library chosen for this.

Both calendars can be extrapolated to dates prior to their first adoption and hence are a Proleptic Gregorian calendar and Proleptic Julian Calendar.

AstroDate includes an ISO 8601 parser as one means of setting the date and time, other methods will be available, ie. using an Array and Object of discrete values.

As with ISO 8601 and the Proleptic calendars, Astronomical year numbering will be used for input and so have a year zero. Outputs may be formated to use either Astronomical year numbering or Calendar Era numbering, ie. BC/AD.

It is not intended for AstroDate to be a generic date parser and handle formats like 13/10/12. Though in future it will be possible to develop addons to do this.

Times beginning 1961 will be assumed to be UTC before this it is assumed to be Universal Time, specifically UT1.

You can see AstroDate in use (jsFiddle) to get an idea of how things are currently functioning until the API and documentation are standardised.

CLDR Languages available.

  • ar
  • ca
  • cs
  • da
  • de
  • el
  • en
  • en_AU
  • en_CA
  • en_GB
  • en_HK
  • en_IN
  • es
  • fi
  • fr
  • he
  • hi
  • hr
  • hu
  • it
  • ja
  • ko
  • nb
  • nl
  • pl
  • pt
  • pt_PT
  • ro
  • root
  • ru
  • sk
  • sl
  • sr
  • sv
  • th
  • tr
  • uk
  • vi
  • zh
  • zh_Hant

The defaut language is 'en'.

Once loaded use AstroDate.lang('en'); to set the default application language, or change a particular instance new AstroDate().lang('en-GB');

CLDR locale modifiers

Loaded languages may be modified for locale, use AstroDate.locale('sr_ME'); to set the default application locale, or change a particular instance new AstroDate().locale('sr_RO');

toString methods

By default .toString(), .toDateString() and .toTimeString() use 'full' locale format, options are 'full', 'long', 'medium' and 'short'.

.toISOString() has no modifiers and will produce a standard ISO 8601 time-stamp string, ie. 1972-07-01T00:00:00.000Z

Pattern formatting

.format("YYYY'-W'ww'-'E") // 2013-W46-3

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)

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.