pax_global_header 0000666 0000000 0000000 00000000064 13060563012 0014506 g ustar 00root root 0000000 0000000 52 comment=13b91bef3f7474921c9970c5dc0faff3e8bccde7
d3-time-format-2.0.5/ 0000775 0000000 0000000 00000000000 13060563012 0014242 5 ustar 00root root 0000000 0000000 d3-time-format-2.0.5/.eslintrc 0000664 0000000 0000000 00000000147 13060563012 0016070 0 ustar 00root root 0000000 0000000 parserOptions:
sourceType: module
extends:
"eslint:recommended"
rules:
no-cond-assign: 0
d3-time-format-2.0.5/.gitignore 0000664 0000000 0000000 00000000100 13060563012 0016221 0 ustar 00root root 0000000 0000000 *.sublime-workspace
.DS_Store
build/
node_modules
npm-debug.log
d3-time-format-2.0.5/.npmignore 0000664 0000000 0000000 00000000036 13060563012 0016240 0 ustar 00root root 0000000 0000000 *.sublime-*
build/*.zip
test/
d3-time-format-2.0.5/LICENSE 0000664 0000000 0000000 00000002703 13060563012 0015251 0 ustar 00root root 0000000 0000000 Copyright 2010-2016 Mike Bostock
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the author nor the names of contributors may be used to
endorse or promote products derived from this software without specific prior
written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
d3-time-format-2.0.5/README.md 0000664 0000000 0000000 00000030132 13060563012 0015520 0 ustar 00root root 0000000 0000000 # d3-time-format
This module provides a JavaScript implementation of the venerable [strptime](http://pubs.opengroup.org/onlinepubs/009695399/functions/strptime.html) and [strftime](http://pubs.opengroup.org/onlinepubs/007908799/xsh/strftime.html) functions from the C standard library, and can be used to parse or format [dates](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) in a variety of locale-specific representations. To format a date, create a [formatter](#locale_format) from a specifier (a string with the desired format *directives*, indicated by `%`); then pass a date to the formatter, which returns a string. For example, to convert the current date to a human-readable string:
```js
var formatTime = d3.timeFormat("%B %d, %Y");
formatTime(new Date); // "June 30, 2015"
```
Likewise, to convert a string back to a date, create a [parser](#locale_parse):
```js
var parseTime = d3.timeParse("%B %d, %Y");
parseTime("June 30, 2015"); // Tue Jun 30 2015 00:00:00 GMT-0700 (PDT)
```
You can implement more elaborate conditional time formats, too. For example, here’s a [multi-scale time format](http://bl.ocks.org/mbostock/4149176) using [time intervals](https://github.com/d3/d3-time):
```js
var formatMillisecond = d3.timeFormat(".%L"),
formatSecond = d3.timeFormat(":%S"),
formatMinute = d3.timeFormat("%I:%M"),
formatHour = d3.timeFormat("%I %p"),
formatDay = d3.timeFormat("%a %d"),
formatWeek = d3.timeFormat("%b %d"),
formatMonth = d3.timeFormat("%B"),
formatYear = d3.timeFormat("%Y");
function multiFormat(date) {
return (d3.timeSecond(date) < date ? formatMillisecond
: d3.timeMinute(date) < date ? formatSecond
: d3.timeHour(date) < date ? formatMinute
: d3.timeDay(date) < date ? formatHour
: d3.timeMonth(date) < date ? (d3.timeWeek(date) < date ? formatDay : formatWeek)
: d3.timeYear(date) < date ? formatMonth
: formatYear)(date);
}
```
This module is used by D3 [time scales](https://github.com/d3/d3-scale#time-scales) to generate human-readable ticks.
## Installing
If you use NPM, `npm install d3-time-format`. Otherwise, download the [latest release](https://github.com/d3/d3-time-format/releases/latest). You can also load directly from [d3js.org](https://d3js.org), either as a [standalone library](https://d3js.org/d3-time-format.v2.min.js) or as part of [D3 4.0](https://github.com/d3/d3). AMD, CommonJS, and vanilla environments are supported. In vanilla, a `d3` global is exported:
```html
```
Locale files are hosted on [unpkg](https://unpkg.com/) and can be loaded using [d3.json](https://github.com/d3/d3-request/blob/master/README.md#json). For example, to set Russian as the default locale:
```js
d3.json("https://unpkg.com/d3-time-format@2/locale/ru-RU.json", function(error, locale) {
if (error) throw error;
d3.timeFormatDefaultLocale(locale);
var format = d3.timeFormat("%c");
console.log(format(new Date)); // понедельник, 5 декабря 2016 г. 10:31:59
});
```
[Try d3-time-format in your browser.](https://tonicdev.com/npm/d3-time-format)
## API Reference
# d3.timeFormat(specifier) [<>](https://github.com/d3/d3-time-format/blob/master/src/defaultLocale.js#L4 "Source")
An alias for [*locale*.format](#locale_format) on the [default locale](#timeFormatDefaultLocale).
# d3.timeParse(specifier) [<>](https://github.com/d3/d3-time-format/blob/master/src/defaultLocale.js#L5 "Source")
An alias for [*locale*.parse](#locale_parse) on the [default locale](#timeFormatDefaultLocale).
# d3.utcFormat(specifier) [<>](https://github.com/d3/d3-time-format/blob/master/src/defaultLocale.js#L6 "Source")
An alias for [*locale*.utcFormat](#locale_utcFormat) on the [default locale](#timeFormatDefaultLocale).
# d3.utcParse(specifier) [<>](https://github.com/d3/d3-time-format/blob/master/src/defaultLocale.js#L7 "Source")
An alias for [*locale*.utcParse](#locale_utcParse) on the [default locale](#timeFormatDefaultLocale).
# d3.isoFormat [<>](https://github.com/d3/d3-time-format/blob/master/src/isoFormat.js "Source")
The full [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) UTC time formatter. Where available, this method will use [Date.toISOString](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Date/toISOString) to format.
# d3.isoParse [<>](https://github.com/d3/d3-time-format/blob/master/src/isoParse.js "Source")
The full [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) UTC time parser. Where available, this method will use the [Date constructor](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Date) to parse strings. If you depend on strict validation of the input format according to ISO 8601, you should construct a [UTC parser function](#utcParse):
```js
var strictIsoParse = d3.utcParse("%Y-%m-%dT%H:%M:%S.%LZ");
```
# locale.format(specifier) [<>](https://github.com/d3/d3-time-format/blob/master/src/locale.js#L293 "Source")
Returns a new formatter for the given string *specifier*. The specifier string may contain the following directives:
* `%a` - abbreviated weekday name.*
* `%A` - full weekday name.*
* `%b` - abbreviated month name.*
* `%B` - full month name.*
* `%c` - the locale’s date and time, such as `%x, %X`.*
* `%d` - zero-padded day of the month as a decimal number [01,31].
* `%e` - space-padded day of the month as a decimal number [ 1,31]; equivalent to `%_d`.
* `%H` - hour (24-hour clock) as a decimal number [00,23].
* `%I` - hour (12-hour clock) as a decimal number [01,12].
* `%j` - day of the year as a decimal number [001,366].
* `%m` - month as a decimal number [01,12].
* `%M` - minute as a decimal number [00,59].
* `%L` - milliseconds as a decimal number [000, 999].
* `%p` - either AM or PM.*
* `%S` - second as a decimal number [00,61].
* `%U` - Sunday-based week of the year as a decimal number [00,53].
* `%w` - Sunday-based weekday as a decimal number [0,6].
* `%W` - Monday-based week of the year as a decimal number [00,53].
* `%x` - the locale’s date, such as `%-m/%-d/%Y`.*
* `%X` - the locale’s time, such as `%-I:%M:%S %p`.*
* `%y` - year without century as a decimal number [00,99].
* `%Y` - year with century as a decimal number.
* `%Z` - time zone offset, such as `-0700`, `-07:00`, `-07`, or `Z`.
* `%%` - a literal percent sign (`%`).
Directives marked with an asterisk (*) may be affected by the [locale definition](#localeFormat).
For `%U`, all days in a new year preceding the first Sunday are considered to be in week 0. For `%W`, all days in a new year preceding the first Monday are considered to be in week 0. Week numbers are computed using [*interval*.count](https://github.com/d3/d3-time#interval_count). For example, 2015-52 and 2016-00 represent Monday, December 28, 2015, while 2015-53 and 2016-01 represent Monday, January 4, 2016. This differs from the [ISO week date](https://en.wikipedia.org/wiki/ISO_week_date specification), which uses a more complicated definition!
The `%` sign indicating a directive may be immediately followed by a padding modifier:
* `0` - zero-padding
* `_` - space-padding
* `-` - disable padding
If no padding modifier is specified, the default is `0` for all directives except `%e`, which defaults to `_`. (In some implementations of strftime and strptime, a directive may include an optional field width or precision; this feature is not yet implemented.)
The returned function formats a specified *[date](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date)*, returning the corresponding string.
```js
var formatMonth = d3.timeFormat("%B"),
formatDay = d3.timeFormat("%A"),
date = new Date(2014, 4, 1); // Thu May 01 2014 00:00:00 GMT-0700 (PDT)
formatMonth(date); // "May"
formatDay(date); // "Thursday"
```
# locale.parse(specifier) [<>](https://github.com/d3/d3-time-format/blob/master/src/locale.js#L298 "Source")
Returns a new parser for the given string *specifier*. The specifier string may contain the same directives as [*locale*.format](#locale_format). The `%d` and `%e` directives are considered equivalent for parsing.
The returned function parses a specified *string*, returning the corresponding [date](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date) or null if the string could not be parsed according to this format’s specifier. Parsing is strict: if the specified string does not exactly match the associated specifier, this method returns null. For example, if the associated specifier is `%Y-%m-%dT%H:%M:%SZ`, then the string `"2011-07-01T19:15:28Z"` will be parsed as expected, but `"2011-07-01T19:15:28"`, `"2011-07-01 19:15:28"` and `"2011-07-01"` will return null. (Note that the literal `Z` here is different from the time zone offset directive `%Z`.) If a more flexible parser is desired, try multiple formats sequentially until one returns non-null.
# locale.utcFormat(specifier) [<>](https://github.com/d3/d3-time-format/blob/master/src/locale.js#L303 "Source")
Equivalent to [*locale*.format](#locale_format), except all directives are interpreted as [Coordinated Universal Time (UTC)](https://en.wikipedia.org/wiki/Coordinated_Universal_Time) rather than local time.
# locale.utcParse(specifier) [<>](https://github.com/d3/d3-time-format/blob/master/src/locale.js#L308 "Source")
Equivalent to [*locale*.parse](#locale_parse), except all directives are interpreted as [Coordinated Universal Time (UTC)](https://en.wikipedia.org/wiki/Coordinated_Universal_Time) rather than local time.
### Locales
# d3.timeFormatLocale(definition) [<>](https://github.com/d3/d3-time-format/blob/master/src/locale.js "Source")
Returns a *locale* object for the specified *definition* with [*locale*.format](#locale_format), [*locale*.parse](#locale_parse), [*locale*.utcFormat](#locale_utcFormat), [*locale*.utcParse](#locale_utcParse) methods. The *definition* must include the following properties:
* `dateTime` - the date and time (`%c`) format specifier (e.g., `"%a %b %e %X %Y"`).
* `date` - the date (`%x`) format specifier (e.g., `"%m/%d/%Y"`).
* `time` - the time (`%X`) format specifier (e.g., `"%H:%M:%S"`).
* `periods` - the A.M. and P.M. equivalents (e.g., `["AM", "PM"]`).
* `days` - the full names of the weekdays, starting with Sunday.
* `shortDays` - the abbreviated names of the weekdays, starting with Sunday.
* `months` - the full names of the months (starting with January).
* `shortMonths` - the abbreviated names of the months (starting with January).
For an example, see [Localized Time Axis II](https://bl.ocks.org/mbostock/805115ebaa574e771db1875a6d828949).
# d3.timeFormatDefaultLocale(definition) [<>](https://github.com/d3/d3-time-format/blob/master/src/defaultLocale.js "Source")
Equivalent to [d3.timeFormatLocale](#timeFormatLocale), except it also redefines [d3.timeFormat](#timeFormat), [d3.timeParse](#timeParse), [d3.utcFormat](#utcFormat) and [d3.utcParse](#utcParse) to the new locale’s [*locale*.format](#locale_format), [*locale*.parse](#locale_parse), [*locale*.utcFormat](#locale_utcFormat) and [*locale*.utcParse](#locale_utcParse). If you do not set a default locale, it defaults to [U.S. English](https://github.com/d3/d3-time-format/blob/master/locale/en-US.json).
For an example, see [Localized Time Axis](https://bl.ocks.org/mbostock/6f1cc065d4d172bcaf322e399aa8d62f).
d3-time-format-2.0.5/d3-time-format.sublime-project 0000664 0000000 0000000 00000000271 13060563012 0022020 0 ustar 00root root 0000000 0000000 {
"folders": [
{
"path": ".",
"file_exclude_patterns": [
"*.sublime-workspace"
],
"folder_exclude_patterns": [
"build"
]
}
]
}
d3-time-format-2.0.5/index.js 0000664 0000000 0000000 00000000430 13060563012 0015704 0 ustar 00root root 0000000 0000000 export {default as timeFormatDefaultLocale, timeFormat, timeParse, utcFormat, utcParse} from "./src/defaultLocale";
export {default as timeFormatLocale} from "./src/locale";
export {default as isoFormat} from "./src/isoFormat";
export {default as isoParse} from "./src/isoParse";
d3-time-format-2.0.5/locale/ 0000775 0000000 0000000 00000000000 13060563012 0015501 5 ustar 00root root 0000000 0000000 d3-time-format-2.0.5/locale/ca-ES.json 0000664 0000000 0000000 00000001012 13060563012 0017256 0 ustar 00root root 0000000 0000000 {
"dateTime": "%A, %e de %B de %Y, %X",
"date": "%d/%m/%Y",
"time": "%H:%M:%S",
"periods": ["AM", "PM"],
"days": ["diumenge", "dilluns", "dimarts", "dimecres", "dijous", "divendres", "dissabte"],
"shortDays": ["dg.", "dl.", "dt.", "dc.", "dj.", "dv.", "ds."],
"months": ["gener", "febrer", "març", "abril", "maig", "juny", "juliol", "agost", "setembre", "octubre", "novembre", "desembre"],
"shortMonths": ["gen.", "febr.", "març", "abr.", "maig", "juny", "jul.", "ag.", "set.", "oct.", "nov.", "des."]
}
d3-time-format-2.0.5/locale/cs-CZ.json 0000664 0000000 0000000 00000001015 13060563012 0017310 0 ustar 00root root 0000000 0000000 {
"dateTime": "%A,%e.%B %Y, %X",
"date": "%-d.%-m.%Y",
"time": "%H:%M:%S",
"periods": ["AM", "PM"],
"days": ["neděle", "pondělí", "úterý", "středa", "čvrtek", "pátek", "sobota"],
"shortDays": ["ne.", "po.", "út.", "st.", "čt.", "pá.", "so."],
"months": ["leden", "únor", "březen", "duben", "květen", "červen", "červenec", "srpen", "září", "říjen", "listopad", "prosinec"],
"shortMonths": ["led", "úno", "břez", "dub", "kvě", "čer", "červ", "srp", "zář", "říj", "list", "pros"]
}
d3-time-format-2.0.5/locale/de-CH.json 0000664 0000000 0000000 00000000766 13060563012 0017265 0 ustar 00root root 0000000 0000000 {
"dateTime": "%A, der %e. %B %Y, %X",
"date": "%d.%m.%Y",
"time": "%H:%M:%S",
"periods": ["AM", "PM"],
"days": ["Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"],
"shortDays": ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"],
"months": ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"],
"shortMonths": ["Jan", "Feb", "Mrz", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez"]
}
d3-time-format-2.0.5/locale/de-DE.json 0000664 0000000 0000000 00000000766 13060563012 0017263 0 ustar 00root root 0000000 0000000 {
"dateTime": "%A, der %e. %B %Y, %X",
"date": "%d.%m.%Y",
"time": "%H:%M:%S",
"periods": ["AM", "PM"],
"days": ["Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"],
"shortDays": ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"],
"months": ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"],
"shortMonths": ["Jan", "Feb", "Mrz", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez"]
}
d3-time-format-2.0.5/locale/en-CA.json 0000664 0000000 0000000 00000000765 13060563012 0017267 0 ustar 00root root 0000000 0000000 {
"dateTime": "%a %b %e %X %Y",
"date": "%Y-%m-%d",
"time": "%H:%M:%S",
"periods": ["AM", "PM"],
"days": ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
"shortDays": ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
"months": ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
"shortMonths": ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
}
d3-time-format-2.0.5/locale/en-GB.json 0000664 0000000 0000000 00000000765 13060563012 0017274 0 ustar 00root root 0000000 0000000 {
"dateTime": "%a %e %b %X %Y",
"date": "%d/%m/%Y",
"time": "%H:%M:%S",
"periods": ["AM", "PM"],
"days": ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
"shortDays": ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
"months": ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
"shortMonths": ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
}
d3-time-format-2.0.5/locale/en-US.json 0000664 0000000 0000000 00000000763 13060563012 0017331 0 ustar 00root root 0000000 0000000 {
"dateTime": "%x, %X",
"date": "%-m/%-d/%Y",
"time": "%-I:%M:%S %p",
"periods": ["AM", "PM"],
"days": ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
"shortDays": ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
"months": ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
"shortMonths": ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
}
d3-time-format-2.0.5/locale/es-ES.json 0000664 0000000 0000000 00000001000 13060563012 0017277 0 ustar 00root root 0000000 0000000 {
"dateTime": "%A, %e de %B de %Y, %X",
"date": "%d/%m/%Y",
"time": "%H:%M:%S",
"periods": ["AM", "PM"],
"days": ["domingo", "lunes", "martes", "miércoles", "jueves", "viernes", "sábado"],
"shortDays": ["dom", "lun", "mar", "mié", "jue", "vie", "sáb"],
"months": ["enero", "febrero", "marzo", "abril", "mayo", "junio", "julio", "agosto", "septiembre", "octubre", "noviembre", "diciembre"],
"shortMonths": ["ene", "feb", "mar", "abr", "may", "jun", "jul", "ago", "sep", "oct", "nov", "dic"]
}
d3-time-format-2.0.5/locale/es-MX.json 0000664 0000000 0000000 00000000764 13060563012 0017334 0 ustar 00root root 0000000 0000000 {
"dateTime": "%x, %X",
"date": "%d/%m/%Y",
"time": "%-I:%M:%S %p",
"periods": ["AM", "PM"],
"days": ["domingo", "lunes", "martes", "miércoles", "jueves", "viernes", "sábado"],
"shortDays": ["dom", "lun", "mar", "mié", "jue", "vie", "sáb"],
"months": ["enero", "febrero", "marzo", "abril", "mayo", "junio", "julio", "agosto", "septiembre", "octubre", "noviembre", "diciembre"],
"shortMonths": ["ene", "feb", "mar", "abr", "may", "jun", "jul", "ago", "sep", "oct", "nov", "dic"]
}
d3-time-format-2.0.5/locale/fi-FI.json 0000664 0000000 0000000 00000001063 13060563012 0017266 0 ustar 00root root 0000000 0000000 {
"dateTime": "%A, %-d. %Bta %Y klo %X",
"date": "%-d.%-m.%Y",
"time": "%H:%M:%S",
"periods": ["a.m.", "p.m."],
"days": ["sunnuntai", "maanantai", "tiistai", "keskiviikko", "torstai", "perjantai", "lauantai"],
"shortDays": ["Su", "Ma", "Ti", "Ke", "To", "Pe", "La"],
"months": ["tammikuu", "helmikuu", "maaliskuu", "huhtikuu", "toukokuu", "kesäkuu", "heinäkuu", "elokuu", "syyskuu", "lokakuu", "marraskuu", "joulukuu"],
"shortMonths": ["Tammi", "Helmi", "Maalis", "Huhti", "Touko", "Kesä", "Heinä", "Elo", "Syys", "Loka", "Marras", "Joulu"]
}
d3-time-format-2.0.5/locale/fr-CA.json 0000664 0000000 0000000 00000000761 13060563012 0017270 0 ustar 00root root 0000000 0000000 {
"dateTime": "%a %e %b %Y %X",
"date": "%Y-%m-%d",
"time": "%H:%M:%S",
"periods": ["", ""],
"days": ["dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi"],
"shortDays": ["dim", "lun", "mar", "mer", "jeu", "ven", "sam"],
"months": ["janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre"],
"shortMonths": ["jan", "fév", "mar", "avr", "mai", "jui", "jul", "aoû", "sep", "oct", "nov", "déc"]
}
d3-time-format-2.0.5/locale/fr-FR.json 0000664 0000000 0000000 00000001020 13060563012 0017301 0 ustar 00root root 0000000 0000000 {
"dateTime": "%A, le %e %B %Y, %X",
"date": "%d/%m/%Y",
"time": "%H:%M:%S",
"periods": ["AM", "PM"],
"days": ["dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi"],
"shortDays": ["dim.", "lun.", "mar.", "mer.", "jeu.", "ven.", "sam."],
"months": ["janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre"],
"shortMonths": ["janv.", "févr.", "mars", "avr.", "mai", "juin", "juil.", "août", "sept.", "oct.", "nov.", "déc."]
}
d3-time-format-2.0.5/locale/he-IL.json 0000664 0000000 0000000 00000001157 13060563012 0017276 0 ustar 00root root 0000000 0000000 {
"dateTime": "%A, %e ב%B %Y %X",
"date": "%d.%m.%Y",
"time": "%H:%M:%S",
"periods": ["AM", "PM"],
"days": ["ראשון", "שני", "שלישי", "רביעי", "חמישי", "שישי", "שבת"],
"shortDays": ["א׳", "ב׳", "ג׳", "ד׳", "ה׳", "ו׳", "ש׳"],
"months": ["ינואר", "פברואר", "מרץ", "אפריל", "מאי", "יוני", "יולי", "אוגוסט", "ספטמבר", "אוקטובר", "נובמבר", "דצמבר"],
"shortMonths": ["ינו׳", "פבר׳", "מרץ", "אפר׳", "מאי", "יוני", "יולי", "אוג׳", "ספט׳", "אוק׳", "נוב׳", "דצמ׳"]
}
d3-time-format-2.0.5/locale/hu-HU.json 0000664 0000000 0000000 00000001036 13060563012 0017322 0 ustar 00root root 0000000 0000000 {
"dateTime": "%Y. %B %-e., %A %X",
"date": "%Y. %m. %d.",
"time": "%H:%M:%S",
"periods": ["de.", "du."],
"days": ["vasárnap", "hétfő", "kedd", "szerda", "csütörtök", "péntek", "szombat"],
"shortDays": ["V", "H", "K", "Sze", "Cs", "P", "Szo"],
"months": ["január", "február", "március", "április", "május", "június", "július", "augusztus", "szeptember", "október", "november", "december"],
"shortMonths": ["jan.", "feb.", "már.", "ápr.", "máj.", "jún.", "júl.", "aug.", "szept.", "okt.", "nov.", "dec."]
}
d3-time-format-2.0.5/locale/it-IT.json 0000664 0000000 0000000 00000001003 13060563012 0017314 0 ustar 00root root 0000000 0000000 {
"dateTime": "%A %e %B %Y, %X",
"date": "%d/%m/%Y",
"time": "%H:%M:%S",
"periods": ["AM", "PM"],
"days": ["Domenica", "Lunedì", "Martedì", "Mercoledì", "Giovedì", "Venerdì", "Sabato"],
"shortDays": ["Dom", "Lun", "Mar", "Mer", "Gio", "Ven", "Sab"],
"months": ["Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre"],
"shortMonths": ["Gen", "Feb", "Mar", "Apr", "Mag", "Giu", "Lug", "Ago", "Set", "Ott", "Nov", "Dic"]
}
d3-time-format-2.0.5/locale/ja-JP.json 0000664 0000000 0000000 00000001025 13060563012 0017273 0 ustar 00root root 0000000 0000000 {
"dateTime": "%Y %b %e %a %X",
"date": "%Y/%m/%d",
"time": "%H:%M:%S",
"periods": ["AM", "PM"],
"days": ["日曜日", "月曜日", "火曜日", "水曜日", "木曜日", "金曜日", "土曜日"],
"shortDays": ["日", "月", "火", "水", "木", "金", "土"],
"months": ["睦月", "如月", "弥生", "卯月", "皐月", "水無月", "文月", "葉月", "長月", "神無月", "霜月", "師走"],
"shortMonths": ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"]
}
d3-time-format-2.0.5/locale/ko-KR.json 0000664 0000000 0000000 00000001002 13060563012 0017310 0 ustar 00root root 0000000 0000000 {
"dateTime": "%Y/%m/%d %a %X",
"date": "%Y/%m/%d",
"time": "%H:%M:%S",
"periods": ["오전", "오후"],
"days": ["일요일", "월요일", "화요일", "수요일", "목요일", "금요일", "토요일"],
"shortDays": ["일", "월", "화", "수", "목", "금", "토"],
"months": ["1월", "2월", "3월", "4월", "5월", "6월", "7월", "8월", "9월", "10월", "11월", "12월"],
"shortMonths": ["1월", "2월", "3월", "4월", "5월", "6월", "7월", "8월", "9월", "10월", "11월", "12월"]
}
d3-time-format-2.0.5/locale/mk-MK.json 0000664 0000000 0000000 00000001247 13060563012 0017314 0 ustar 00root root 0000000 0000000 {
"dateTime": "%A, %e %B %Y г. %X",
"date": "%d.%m.%Y",
"time": "%H:%M:%S",
"periods": ["AM", "PM"],
"days": ["недела", "понеделник", "вторник", "среда", "четврток", "петок", "сабота"],
"shortDays": ["нед", "пон", "вто", "сре", "чет", "пет", "саб"],
"months": ["јануари", "февруари", "март", "април", "мај", "јуни", "јули", "август", "септември", "октомври", "ноември", "декември"],
"shortMonths": ["јан", "фев", "мар", "апр", "мај", "јун", "јул", "авг", "сеп", "окт", "ное", "дек"]
}
d3-time-format-2.0.5/locale/nl-NL.json 0000664 0000000 0000000 00000000762 13060563012 0017321 0 ustar 00root root 0000000 0000000 {
"dateTime": "%a %e %B %Y %T",
"date": "%d-%m-%Y",
"time": "%H:%M:%S",
"periods": ["AM", "PM"],
"days": ["zondag", "maandag", "dinsdag", "woensdag", "donderdag", "vrijdag", "zaterdag"],
"shortDays": ["zo", "ma", "di", "wo", "do", "vr", "za"],
"months": ["januari", "februari", "maart", "april", "mei", "juni", "juli", "augustus", "september", "oktober", "november", "december"],
"shortMonths": ["jan", "feb", "mrt", "apr", "mei", "jun", "jul", "aug", "sep", "okt", "nov", "dec"]
}
d3-time-format-2.0.5/locale/pl-PL.json 0000664 0000000 0000000 00000001060 13060563012 0017315 0 ustar 00root root 0000000 0000000 {
"dateTime": "%A, %e %B %Y, %X",
"date": "%d/%m/%Y",
"time": "%H:%M:%S",
"periods": ["AM", "PM"],
"days": ["Niedziela", "Poniedziałek", "Wtorek", "Środa", "Czwartek", "Piątek", "Sobota"],
"shortDays": ["Niedz.", "Pon.", "Wt.", "Śr.", "Czw.", "Pt.", "Sob."],
"months": ["Styczeń", "Luty", "Marzec", "Kwiecień", "Maj", "Czerwiec", "Lipiec", "Sierpień", "Wrzesień", "Październik", "Listopad", "Grudzień"],
"shortMonths": ["Stycz.", "Luty", "Marz.", "Kwie.", "Maj", "Czerw.", "Lipc.", "Sierp.", "Wrz.", "Paźdz.", "Listop.", "Grudz."]
}
d3-time-format-2.0.5/locale/pt-BR.json 0000664 0000000 0000000 00000000774 13060563012 0017330 0 ustar 00root root 0000000 0000000 {
"dateTime": "%A, %e de %B de %Y. %X",
"date": "%d/%m/%Y",
"time": "%H:%M:%S",
"periods": ["AM", "PM"],
"days": ["Domingo", "Segunda", "Terça", "Quarta", "Quinta", "Sexta", "Sábado"],
"shortDays": ["Dom", "Seg", "Ter", "Qua", "Qui", "Sex", "Sáb"],
"months": ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"],
"shortMonths": ["Jan", "Fev", "Mar", "Abr", "Mai", "Jun", "Jul", "Ago", "Set", "Out", "Nov", "Dez"]
}
d3-time-format-2.0.5/locale/ru-RU.json 0000664 0000000 0000000 00000001243 13060563012 0017346 0 ustar 00root root 0000000 0000000 {
"dateTime": "%A, %e %B %Y г. %X",
"date": "%d.%m.%Y",
"time": "%H:%M:%S",
"periods": ["AM", "PM"],
"days": ["воскресенье", "понедельник", "вторник", "среда", "четверг", "пятница", "суббота"],
"shortDays": ["вс", "пн", "вт", "ср", "чт", "пт", "сб"],
"months": ["января", "февраля", "марта", "апреля", "мая", "июня", "июля", "августа", "сентября", "октября", "ноября", "декабря"],
"shortMonths": ["янв", "фев", "мар", "апр", "май", "июн", "июл", "авг", "сен", "окт", "ноя", "дек"]
}
d3-time-format-2.0.5/locale/sv-SE.json 0000664 0000000 0000000 00000000770 13060563012 0017335 0 ustar 00root root 0000000 0000000 {
"dateTime": "%A den %d %B %Y %X",
"date": "%Y-%m-%d",
"time": "%H:%M:%S",
"periods": ["fm", "em"],
"days": ["Söndag", "Måndag", "Tisdag", "Onsdag", "Torsdag", "Fredag", "Lördag"],
"shortDays": ["Sön", "Mån", "Tis", "Ons", "Tor", "Fre", "Lör"],
"months": ["Januari", "Februari", "Mars", "April", "Maj", "Juni", "Juli", "Augusti", "September", "Oktober", "November", "December"],
"shortMonths": ["Jan", "Feb", "Mar", "Apr", "Maj", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dec"]
}
d3-time-format-2.0.5/locale/uk-UA.json 0000664 0000000 0000000 00000001276 13060563012 0017324 0 ustar 00root root 0000000 0000000 {
"dateTime": "%A, %e %B %Y р. %X",
"date": "%d.%m.%Y",
"time": "%H:%M:%S",
"periods": ["дп", "пп"],
"days": ["неділя", "понеділок", "вівторок", "середа", "четвер", "п'ятниця", "субота"],
"shortDays": ["нд", "пн", "вт", "ср", "чт", "пт", "сб"],
"months": ["січня", "лютого", "березня", "квітня", "травня", "червня", "липня", "серпня", "вересня", "жовтня", "листопада", "грудня"],
"shortMonths": ["січ.", "лют.", "бер.", "квіт.", "трав.", "черв.", "лип.", "серп.", "вер.", "жовт.", "лист.", "груд."]
}
d3-time-format-2.0.5/locale/zh-CN.json 0000664 0000000 0000000 00000001120 13060563012 0017305 0 ustar 00root root 0000000 0000000 {
"dateTime": "%x %A %X",
"date": "%Y年%-m月%-d日",
"time": "%H:%M:%S",
"periods": ["上午", "下午"],
"days": ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"],
"shortDays": ["周日", "周一", "周二", "周三", "周四", "周五", "周六"],
"months": ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
"shortMonths": ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"]
}
d3-time-format-2.0.5/package.json 0000664 0000000 0000000 00000003203 13060563012 0016526 0 ustar 00root root 0000000 0000000 {
"name": "d3-time-format",
"version": "2.0.5",
"description": "A JavaScript time formatter and parser inspired by strftime and strptime.",
"keywords": [
"d3",
"d3-module",
"time",
"format",
"strftime",
"strptime"
],
"homepage": "https://d3js.org/d3-time-format/",
"license": "BSD-3-Clause",
"author": {
"name": "Mike Bostock",
"url": "http://bost.ocks.org/mike"
},
"main": "build/d3-time-format.js",
"module": "index",
"jsnext:main": "index",
"repository": {
"type": "git",
"url": "https://github.com/d3/d3-time-format.git"
},
"scripts": {
"pretest": "rm -rf build && mkdir build && rollup --banner \"$(preamble)\" -f umd -g d3-time:d3 -n d3 -o build/d3-time-format.js -- index.js",
"test": "TZ=America/Los_Angeles tape 'test/**/*-test.js' && eslint index.js src",
"prepublish": "npm run test && uglifyjs --preamble \"$(preamble)\" build/d3-time-format.js -c -m -o build/d3-time-format.min.js",
"postpublish": "git push && git push --tags && cd ../d3.github.com && git pull && cp ../d3-time-format/build/d3-time-format.js d3-time-format.v2.js && cp ../d3-time-format/build/d3-time-format.min.js d3-time-format.v2.min.js && git add d3-time-format.v2.js d3-time-format.v2.min.js && git commit -m \"d3-time-format ${npm_package_version}\" && git push && cd - && zip -j build/d3-time-format.zip -- LICENSE README.md build/d3-time-format.js build/d3-time-format.min.js"
},
"dependencies": {
"d3-time": "1"
},
"devDependencies": {
"d3-queue": "3",
"eslint": "3",
"package-preamble": "0.0",
"rollup": "0.41",
"tape": "4",
"uglify-js": "^2.8.11"
}
}
d3-time-format-2.0.5/src/ 0000775 0000000 0000000 00000000000 13060563012 0015031 5 ustar 00root root 0000000 0000000 d3-time-format-2.0.5/src/defaultLocale.js 0000664 0000000 0000000 00000001543 13060563012 0020136 0 ustar 00root root 0000000 0000000 import formatLocale from "./locale";
var locale;
export var timeFormat;
export var timeParse;
export var utcFormat;
export var utcParse;
defaultLocale({
dateTime: "%x, %X",
date: "%-m/%-d/%Y",
time: "%-I:%M:%S %p",
periods: ["AM", "PM"],
days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
shortDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
shortMonths: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
});
export default function defaultLocale(definition) {
locale = formatLocale(definition);
timeFormat = locale.format;
timeParse = locale.parse;
utcFormat = locale.utcFormat;
utcParse = locale.utcParse;
return locale;
}
d3-time-format-2.0.5/src/isoFormat.js 0000664 0000000 0000000 00000000434 13060563012 0017333 0 ustar 00root root 0000000 0000000 import {utcFormat} from "./defaultLocale";
export var isoSpecifier = "%Y-%m-%dT%H:%M:%S.%LZ";
function formatIsoNative(date) {
return date.toISOString();
}
var formatIso = Date.prototype.toISOString
? formatIsoNative
: utcFormat(isoSpecifier);
export default formatIso;
d3-time-format-2.0.5/src/isoParse.js 0000664 0000000 0000000 00000000477 13060563012 0017164 0 ustar 00root root 0000000 0000000 import {isoSpecifier} from "./isoFormat";
import {utcParse} from "./defaultLocale";
function parseIsoNative(string) {
var date = new Date(string);
return isNaN(date) ? null : date;
}
var parseIso = +new Date("2000-01-01T00:00:00.000Z")
? parseIsoNative
: utcParse(isoSpecifier);
export default parseIso;
d3-time-format-2.0.5/src/locale.js 0000664 0000000 0000000 00000033064 13060563012 0016634 0 ustar 00root root 0000000 0000000 import {timeDay, timeSunday, timeMonday, timeYear, utcDay, utcSunday, utcMonday, utcYear} from "d3-time";
function localDate(d) {
if (0 <= d.y && d.y < 100) {
var date = new Date(-1, d.m, d.d, d.H, d.M, d.S, d.L);
date.setFullYear(d.y);
return date;
}
return new Date(d.y, d.m, d.d, d.H, d.M, d.S, d.L);
}
function utcDate(d) {
if (0 <= d.y && d.y < 100) {
var date = new Date(Date.UTC(-1, d.m, d.d, d.H, d.M, d.S, d.L));
date.setUTCFullYear(d.y);
return date;
}
return new Date(Date.UTC(d.y, d.m, d.d, d.H, d.M, d.S, d.L));
}
function newYear(y) {
return {y: y, m: 0, d: 1, H: 0, M: 0, S: 0, L: 0};
}
export default function formatLocale(locale) {
var locale_dateTime = locale.dateTime,
locale_date = locale.date,
locale_time = locale.time,
locale_periods = locale.periods,
locale_weekdays = locale.days,
locale_shortWeekdays = locale.shortDays,
locale_months = locale.months,
locale_shortMonths = locale.shortMonths;
var periodRe = formatRe(locale_periods),
periodLookup = formatLookup(locale_periods),
weekdayRe = formatRe(locale_weekdays),
weekdayLookup = formatLookup(locale_weekdays),
shortWeekdayRe = formatRe(locale_shortWeekdays),
shortWeekdayLookup = formatLookup(locale_shortWeekdays),
monthRe = formatRe(locale_months),
monthLookup = formatLookup(locale_months),
shortMonthRe = formatRe(locale_shortMonths),
shortMonthLookup = formatLookup(locale_shortMonths);
var formats = {
"a": formatShortWeekday,
"A": formatWeekday,
"b": formatShortMonth,
"B": formatMonth,
"c": null,
"d": formatDayOfMonth,
"e": formatDayOfMonth,
"H": formatHour24,
"I": formatHour12,
"j": formatDayOfYear,
"L": formatMilliseconds,
"m": formatMonthNumber,
"M": formatMinutes,
"p": formatPeriod,
"S": formatSeconds,
"U": formatWeekNumberSunday,
"w": formatWeekdayNumber,
"W": formatWeekNumberMonday,
"x": null,
"X": null,
"y": formatYear,
"Y": formatFullYear,
"Z": formatZone,
"%": formatLiteralPercent
};
var utcFormats = {
"a": formatUTCShortWeekday,
"A": formatUTCWeekday,
"b": formatUTCShortMonth,
"B": formatUTCMonth,
"c": null,
"d": formatUTCDayOfMonth,
"e": formatUTCDayOfMonth,
"H": formatUTCHour24,
"I": formatUTCHour12,
"j": formatUTCDayOfYear,
"L": formatUTCMilliseconds,
"m": formatUTCMonthNumber,
"M": formatUTCMinutes,
"p": formatUTCPeriod,
"S": formatUTCSeconds,
"U": formatUTCWeekNumberSunday,
"w": formatUTCWeekdayNumber,
"W": formatUTCWeekNumberMonday,
"x": null,
"X": null,
"y": formatUTCYear,
"Y": formatUTCFullYear,
"Z": formatUTCZone,
"%": formatLiteralPercent
};
var parses = {
"a": parseShortWeekday,
"A": parseWeekday,
"b": parseShortMonth,
"B": parseMonth,
"c": parseLocaleDateTime,
"d": parseDayOfMonth,
"e": parseDayOfMonth,
"H": parseHour24,
"I": parseHour24,
"j": parseDayOfYear,
"L": parseMilliseconds,
"m": parseMonthNumber,
"M": parseMinutes,
"p": parsePeriod,
"S": parseSeconds,
"U": parseWeekNumberSunday,
"w": parseWeekdayNumber,
"W": parseWeekNumberMonday,
"x": parseLocaleDate,
"X": parseLocaleTime,
"y": parseYear,
"Y": parseFullYear,
"Z": parseZone,
"%": parseLiteralPercent
};
// These recursive directive definitions must be deferred.
formats.x = newFormat(locale_date, formats);
formats.X = newFormat(locale_time, formats);
formats.c = newFormat(locale_dateTime, formats);
utcFormats.x = newFormat(locale_date, utcFormats);
utcFormats.X = newFormat(locale_time, utcFormats);
utcFormats.c = newFormat(locale_dateTime, utcFormats);
function newFormat(specifier, formats) {
return function(date) {
var string = [],
i = -1,
j = 0,
n = specifier.length,
c,
pad,
format;
if (!(date instanceof Date)) date = new Date(+date);
while (++i < n) {
if (specifier.charCodeAt(i) === 37) {
string.push(specifier.slice(j, i));
if ((pad = pads[c = specifier.charAt(++i)]) != null) c = specifier.charAt(++i);
else pad = c === "e" ? " " : "0";
if (format = formats[c]) c = format(date, pad);
string.push(c);
j = i + 1;
}
}
string.push(specifier.slice(j, i));
return string.join("");
};
}
function newParse(specifier, newDate) {
return function(string) {
var d = newYear(1900),
i = parseSpecifier(d, specifier, string += "", 0);
if (i != string.length) return null;
// The am-pm flag is 0 for AM, and 1 for PM.
if ("p" in d) d.H = d.H % 12 + d.p * 12;
// Convert day-of-week and week-of-year to day-of-year.
if ("W" in d || "U" in d) {
if (!("w" in d)) d.w = "W" in d ? 1 : 0;
var day = "Z" in d ? utcDate(newYear(d.y)).getUTCDay() : newDate(newYear(d.y)).getDay();
d.m = 0;
d.d = "W" in d ? (d.w + 6) % 7 + d.W * 7 - (day + 5) % 7 : d.w + d.U * 7 - (day + 6) % 7;
}
// If a time zone is specified, all fields are interpreted as UTC and then
// offset according to the specified time zone.
if ("Z" in d) {
d.H += d.Z / 100 | 0;
d.M += d.Z % 100;
return utcDate(d);
}
// Otherwise, all fields are in local time.
return newDate(d);
};
}
function parseSpecifier(d, specifier, string, j) {
var i = 0,
n = specifier.length,
m = string.length,
c,
parse;
while (i < n) {
if (j >= m) return -1;
c = specifier.charCodeAt(i++);
if (c === 37) {
c = specifier.charAt(i++);
parse = parses[c in pads ? specifier.charAt(i++) : c];
if (!parse || ((j = parse(d, string, j)) < 0)) return -1;
} else if (c != string.charCodeAt(j++)) {
return -1;
}
}
return j;
}
function parsePeriod(d, string, i) {
var n = periodRe.exec(string.slice(i));
return n ? (d.p = periodLookup[n[0].toLowerCase()], i + n[0].length) : -1;
}
function parseShortWeekday(d, string, i) {
var n = shortWeekdayRe.exec(string.slice(i));
return n ? (d.w = shortWeekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
}
function parseWeekday(d, string, i) {
var n = weekdayRe.exec(string.slice(i));
return n ? (d.w = weekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
}
function parseShortMonth(d, string, i) {
var n = shortMonthRe.exec(string.slice(i));
return n ? (d.m = shortMonthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
}
function parseMonth(d, string, i) {
var n = monthRe.exec(string.slice(i));
return n ? (d.m = monthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
}
function parseLocaleDateTime(d, string, i) {
return parseSpecifier(d, locale_dateTime, string, i);
}
function parseLocaleDate(d, string, i) {
return parseSpecifier(d, locale_date, string, i);
}
function parseLocaleTime(d, string, i) {
return parseSpecifier(d, locale_time, string, i);
}
function formatShortWeekday(d) {
return locale_shortWeekdays[d.getDay()];
}
function formatWeekday(d) {
return locale_weekdays[d.getDay()];
}
function formatShortMonth(d) {
return locale_shortMonths[d.getMonth()];
}
function formatMonth(d) {
return locale_months[d.getMonth()];
}
function formatPeriod(d) {
return locale_periods[+(d.getHours() >= 12)];
}
function formatUTCShortWeekday(d) {
return locale_shortWeekdays[d.getUTCDay()];
}
function formatUTCWeekday(d) {
return locale_weekdays[d.getUTCDay()];
}
function formatUTCShortMonth(d) {
return locale_shortMonths[d.getUTCMonth()];
}
function formatUTCMonth(d) {
return locale_months[d.getUTCMonth()];
}
function formatUTCPeriod(d) {
return locale_periods[+(d.getUTCHours() >= 12)];
}
return {
format: function(specifier) {
var f = newFormat(specifier += "", formats);
f.toString = function() { return specifier; };
return f;
},
parse: function(specifier) {
var p = newParse(specifier += "", localDate);
p.toString = function() { return specifier; };
return p;
},
utcFormat: function(specifier) {
var f = newFormat(specifier += "", utcFormats);
f.toString = function() { return specifier; };
return f;
},
utcParse: function(specifier) {
var p = newParse(specifier, utcDate);
p.toString = function() { return specifier; };
return p;
}
};
}
var pads = {"-": "", "_": " ", "0": "0"},
numberRe = /^\s*\d+/, // note: ignores next directive
percentRe = /^%/,
requoteRe = /[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g;
function pad(value, fill, width) {
var sign = value < 0 ? "-" : "",
string = (sign ? -value : value) + "",
length = string.length;
return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
}
function requote(s) {
return s.replace(requoteRe, "\\$&");
}
function formatRe(names) {
return new RegExp("^(?:" + names.map(requote).join("|") + ")", "i");
}
function formatLookup(names) {
var map = {}, i = -1, n = names.length;
while (++i < n) map[names[i].toLowerCase()] = i;
return map;
}
function parseWeekdayNumber(d, string, i) {
var n = numberRe.exec(string.slice(i, i + 1));
return n ? (d.w = +n[0], i + n[0].length) : -1;
}
function parseWeekNumberSunday(d, string, i) {
var n = numberRe.exec(string.slice(i));
return n ? (d.U = +n[0], i + n[0].length) : -1;
}
function parseWeekNumberMonday(d, string, i) {
var n = numberRe.exec(string.slice(i));
return n ? (d.W = +n[0], i + n[0].length) : -1;
}
function parseFullYear(d, string, i) {
var n = numberRe.exec(string.slice(i, i + 4));
return n ? (d.y = +n[0], i + n[0].length) : -1;
}
function parseYear(d, string, i) {
var n = numberRe.exec(string.slice(i, i + 2));
return n ? (d.y = +n[0] + (+n[0] > 68 ? 1900 : 2000), i + n[0].length) : -1;
}
function parseZone(d, string, i) {
var n = /^(Z)|([+-]\d\d)(?:\:?(\d\d))?/.exec(string.slice(i, i + 6));
return n ? (d.Z = n[1] ? 0 : -(n[2] + (n[3] || "00")), i + n[0].length) : -1;
}
function parseMonthNumber(d, string, i) {
var n = numberRe.exec(string.slice(i, i + 2));
return n ? (d.m = n[0] - 1, i + n[0].length) : -1;
}
function parseDayOfMonth(d, string, i) {
var n = numberRe.exec(string.slice(i, i + 2));
return n ? (d.d = +n[0], i + n[0].length) : -1;
}
function parseDayOfYear(d, string, i) {
var n = numberRe.exec(string.slice(i, i + 3));
return n ? (d.m = 0, d.d = +n[0], i + n[0].length) : -1;
}
function parseHour24(d, string, i) {
var n = numberRe.exec(string.slice(i, i + 2));
return n ? (d.H = +n[0], i + n[0].length) : -1;
}
function parseMinutes(d, string, i) {
var n = numberRe.exec(string.slice(i, i + 2));
return n ? (d.M = +n[0], i + n[0].length) : -1;
}
function parseSeconds(d, string, i) {
var n = numberRe.exec(string.slice(i, i + 2));
return n ? (d.S = +n[0], i + n[0].length) : -1;
}
function parseMilliseconds(d, string, i) {
var n = numberRe.exec(string.slice(i, i + 3));
return n ? (d.L = +n[0], i + n[0].length) : -1;
}
function parseLiteralPercent(d, string, i) {
var n = percentRe.exec(string.slice(i, i + 1));
return n ? i + n[0].length : -1;
}
function formatDayOfMonth(d, p) {
return pad(d.getDate(), p, 2);
}
function formatHour24(d, p) {
return pad(d.getHours(), p, 2);
}
function formatHour12(d, p) {
return pad(d.getHours() % 12 || 12, p, 2);
}
function formatDayOfYear(d, p) {
return pad(1 + timeDay.count(timeYear(d), d), p, 3);
}
function formatMilliseconds(d, p) {
return pad(d.getMilliseconds(), p, 3);
}
function formatMonthNumber(d, p) {
return pad(d.getMonth() + 1, p, 2);
}
function formatMinutes(d, p) {
return pad(d.getMinutes(), p, 2);
}
function formatSeconds(d, p) {
return pad(d.getSeconds(), p, 2);
}
function formatWeekNumberSunday(d, p) {
return pad(timeSunday.count(timeYear(d), d), p, 2);
}
function formatWeekdayNumber(d) {
return d.getDay();
}
function formatWeekNumberMonday(d, p) {
return pad(timeMonday.count(timeYear(d), d), p, 2);
}
function formatYear(d, p) {
return pad(d.getFullYear() % 100, p, 2);
}
function formatFullYear(d, p) {
return pad(d.getFullYear() % 10000, p, 4);
}
function formatZone(d) {
var z = d.getTimezoneOffset();
return (z > 0 ? "-" : (z *= -1, "+"))
+ pad(z / 60 | 0, "0", 2)
+ pad(z % 60, "0", 2);
}
function formatUTCDayOfMonth(d, p) {
return pad(d.getUTCDate(), p, 2);
}
function formatUTCHour24(d, p) {
return pad(d.getUTCHours(), p, 2);
}
function formatUTCHour12(d, p) {
return pad(d.getUTCHours() % 12 || 12, p, 2);
}
function formatUTCDayOfYear(d, p) {
return pad(1 + utcDay.count(utcYear(d), d), p, 3);
}
function formatUTCMilliseconds(d, p) {
return pad(d.getUTCMilliseconds(), p, 3);
}
function formatUTCMonthNumber(d, p) {
return pad(d.getUTCMonth() + 1, p, 2);
}
function formatUTCMinutes(d, p) {
return pad(d.getUTCMinutes(), p, 2);
}
function formatUTCSeconds(d, p) {
return pad(d.getUTCSeconds(), p, 2);
}
function formatUTCWeekNumberSunday(d, p) {
return pad(utcSunday.count(utcYear(d), d), p, 2);
}
function formatUTCWeekdayNumber(d) {
return d.getUTCDay();
}
function formatUTCWeekNumberMonday(d, p) {
return pad(utcMonday.count(utcYear(d), d), p, 2);
}
function formatUTCYear(d, p) {
return pad(d.getUTCFullYear() % 100, p, 2);
}
function formatUTCFullYear(d, p) {
return pad(d.getUTCFullYear() % 10000, p, 4);
}
function formatUTCZone() {
return "+0000";
}
function formatLiteralPercent() {
return "%";
}
d3-time-format-2.0.5/test/ 0000775 0000000 0000000 00000000000 13060563012 0015221 5 ustar 00root root 0000000 0000000 d3-time-format-2.0.5/test/date.js 0000664 0000000 0000000 00000002200 13060563012 0016466 0 ustar 00root root 0000000 0000000 exports.local = function(year, month, day, hours, minutes, seconds, milliseconds) {
if (year == null) year = 0;
if (month == null) month = 0;
if (day == null) day = 1;
if (hours == null) hours = 0;
if (minutes == null) minutes = 0;
if (seconds == null) seconds = 0;
if (milliseconds == null) milliseconds = 0;
if (0 <= year && year < 100) {
var date = new Date(-1, month, day, hours, minutes, seconds, milliseconds);
date.setFullYear(year);
return date;
}
return new Date(year, month, day, hours, minutes, seconds, milliseconds);
};
exports.utc = function(year, month, day, hours, minutes, seconds, milliseconds) {
if (year == null) year = 0;
if (month == null) month = 0;
if (day == null) day = 1;
if (hours == null) hours = 0;
if (minutes == null) minutes = 0;
if (seconds == null) seconds = 0;
if (milliseconds == null) milliseconds = 0;
if (0 <= year && year < 100) {
var date = new Date(Date.UTC(-1, month, day, hours, minutes, seconds, milliseconds));
date.setUTCFullYear(year);
return date;
}
return new Date(Date.UTC(year, month, day, hours, minutes, seconds, milliseconds));
};
d3-time-format-2.0.5/test/defaultLocale-test.js 0000664 0000000 0000000 00000005103 13060563012 0021277 0 ustar 00root root 0000000 0000000 var tape = require("tape"),
d3 = require("../"),
enUs = require("../locale/en-US"),
frFr = require("../locale/fr-FR");
tape("d3.timeFormat(specifier) defaults to en-US", function(test) {
test.equal(d3.timeFormat("%c")(new Date(2000, 0, 1)), "1/1/2000, 12:00:00 AM");
test.end();
});
tape("d3.timeParse(specifier) defaults to en-US", function(test) {
test.equal(+d3.timeParse("%c")("1/1/2000, 12:00:00 AM"), +new Date(2000, 0, 1));
test.end();
});
tape("d3.utcFormat(specifier) defaults to en-US", function(test) {
test.equal(d3.utcFormat("%c")(new Date(Date.UTC(2000, 0, 1))), "1/1/2000, 12:00:00 AM");
test.end();
});
tape("d3.utcParse(specifier) defaults to en-US", function(test) {
test.equal(+d3.utcParse("%c")("1/1/2000, 12:00:00 AM"), +new Date(Date.UTC(2000, 0, 1)));
test.end();
});
tape("d3.timeFormatDefaultLocale(definition) returns the new default locale", function(test) {
var locale = d3.timeFormatDefaultLocale(frFr);
try {
test.equal(locale.format("%c")(new Date(2000, 0, 1)), "samedi, le 1 janvier 2000, 00:00:00");
test.end();
} finally {
d3.timeFormatDefaultLocale(enUs);
}
});
tape("d3.timeFormatDefaultLocale(definition) affects d3.timeFormat", function(test) {
var locale = d3.timeFormatDefaultLocale(frFr);
try {
test.equal(d3.timeFormat, locale.format);
test.equal(d3.timeFormat("%c")(new Date(2000, 0, 1)), "samedi, le 1 janvier 2000, 00:00:00");
test.end();
} finally {
d3.timeFormatDefaultLocale(enUs);
}
});
tape("d3.timeFormatDefaultLocale(definition) affects d3.timeParse", function(test) {
var locale = d3.timeFormatDefaultLocale(frFr);
try {
test.equal(d3.timeParse, locale.parse);
test.equal(+d3.timeParse("%c")("samedi, le 1 janvier 2000, 00:00:00"), +new Date(2000, 0, 1));
test.end();
} finally {
d3.timeFormatDefaultLocale(enUs);
}
});
tape("d3.timeFormatDefaultLocale(definition) affects d3.utcFormat", function(test) {
var locale = d3.timeFormatDefaultLocale(frFr);
try {
test.equal(d3.utcFormat, locale.utcFormat);
test.equal(d3.utcFormat("%c")(new Date(Date.UTC(2000, 0, 1))), "samedi, le 1 janvier 2000, 00:00:00");
test.end();
} finally {
d3.timeFormatDefaultLocale(enUs);
}
});
tape("d3.timeFormatDefaultLocale(definition) affects d3.utcParse", function(test) {
var locale = d3.timeFormatDefaultLocale(frFr);
try {
test.equal(d3.utcParse, locale.utcParse);
test.equal(+d3.utcParse("%c")("samedi, le 1 janvier 2000, 00:00:00"), +new Date(Date.UTC(2000, 0, 1)));
test.end();
} finally {
d3.timeFormatDefaultLocale(enUs);
}
});
d3-time-format-2.0.5/test/format-test.js 0000664 0000000 0000000 00000024001 13060563012 0020021 0 ustar 00root root 0000000 0000000 var tape = require("tape"),
time = require("d3-time"),
timeFormat = require("../"),
date = require("./date");
var formatMillisecond = timeFormat.timeFormat(".%L"),
formatSecond = timeFormat.timeFormat(":%S"),
formatMinute = timeFormat.timeFormat("%I:%M"),
formatHour = timeFormat.timeFormat("%I %p"),
formatDay = timeFormat.timeFormat("%a %d"),
formatWeek = timeFormat.timeFormat("%b %d"),
formatMonth = timeFormat.timeFormat("%B"),
formatYear = timeFormat.timeFormat("%Y");
function multi(d) {
return (time.timeSecond(d) < d ? formatMillisecond
: time.timeMinute(d) < d ? formatSecond
: time.timeHour(d) < d ? formatMinute
: time.timeDay(d) < d ? formatHour
: time.timeMonth(d) < d ? (time.timeWeek(d) < d ? formatDay : formatWeek)
: time.timeYear(d) < d ? formatMonth
: formatYear)(d);
}
tape("timeFormat(date) coerces the specified date to a Date", function(test) {
var f = timeFormat.timeFormat("%c");
test.equal(f(+date.local(1990, 0, 1)), "1/1/1990, 12:00:00 AM");
test.equal(f(+date.local(1990, 0, 2)), "1/2/1990, 12:00:00 AM");
test.equal(f(+date.local(1990, 0, 3)), "1/3/1990, 12:00:00 AM");
test.equal(f(+date.local(1990, 0, 4)), "1/4/1990, 12:00:00 AM");
test.equal(f(+date.local(1990, 0, 5)), "1/5/1990, 12:00:00 AM");
test.equal(f(+date.local(1990, 0, 6)), "1/6/1990, 12:00:00 AM");
test.equal(f(+date.local(1990, 0, 7)), "1/7/1990, 12:00:00 AM");
test.end();
});
tape("timeFormat(\"%a\")(date) formats abbreviated weekdays", function(test) {
var f = timeFormat.timeFormat("%a");
test.equal(f(date.local(1990, 0, 1)), "Mon");
test.equal(f(date.local(1990, 0, 2)), "Tue");
test.equal(f(date.local(1990, 0, 3)), "Wed");
test.equal(f(date.local(1990, 0, 4)), "Thu");
test.equal(f(date.local(1990, 0, 5)), "Fri");
test.equal(f(date.local(1990, 0, 6)), "Sat");
test.equal(f(date.local(1990, 0, 7)), "Sun");
test.end();
});
tape("timeFormat(\"%A\")(date) formats weekdays", function(test) {
var f = timeFormat.timeFormat("%A");
test.equal(f(date.local(1990, 0, 1)), "Monday");
test.equal(f(date.local(1990, 0, 2)), "Tuesday");
test.equal(f(date.local(1990, 0, 3)), "Wednesday");
test.equal(f(date.local(1990, 0, 4)), "Thursday");
test.equal(f(date.local(1990, 0, 5)), "Friday");
test.equal(f(date.local(1990, 0, 6)), "Saturday");
test.equal(f(date.local(1990, 0, 7)), "Sunday");
test.end();
});
tape("timeFormat(\"%b\")(date) formats abbreviated months", function(test) {
var f = timeFormat.timeFormat("%b");
test.equal(f(date.local(1990, 0, 1)), "Jan");
test.equal(f(date.local(1990, 1, 1)), "Feb");
test.equal(f(date.local(1990, 2, 1)), "Mar");
test.equal(f(date.local(1990, 3, 1)), "Apr");
test.equal(f(date.local(1990, 4, 1)), "May");
test.equal(f(date.local(1990, 5, 1)), "Jun");
test.equal(f(date.local(1990, 6, 1)), "Jul");
test.equal(f(date.local(1990, 7, 1)), "Aug");
test.equal(f(date.local(1990, 8, 1)), "Sep");
test.equal(f(date.local(1990, 9, 1)), "Oct");
test.equal(f(date.local(1990, 10, 1)), "Nov");
test.equal(f(date.local(1990, 11, 1)), "Dec");
test.end();
});
tape("timeFormat(\"%B\")(date) formats months", function(test) {
var f = timeFormat.timeFormat("%B");
test.equal(f(date.local(1990, 0, 1)), "January");
test.equal(f(date.local(1990, 1, 1)), "February");
test.equal(f(date.local(1990, 2, 1)), "March");
test.equal(f(date.local(1990, 3, 1)), "April");
test.equal(f(date.local(1990, 4, 1)), "May");
test.equal(f(date.local(1990, 5, 1)), "June");
test.equal(f(date.local(1990, 6, 1)), "July");
test.equal(f(date.local(1990, 7, 1)), "August");
test.equal(f(date.local(1990, 8, 1)), "September");
test.equal(f(date.local(1990, 9, 1)), "October");
test.equal(f(date.local(1990, 10, 1)), "November");
test.equal(f(date.local(1990, 11, 1)), "December");
test.end();
});
tape("timeFormat(\"%c\")(date) formats localized dates and times", function(test) {
var f = timeFormat.timeFormat("%c");
test.equal(f(date.local(1990, 0, 1)), "1/1/1990, 12:00:00 AM");
test.end();
});
tape("timeFormat(\"%d\")(date) formats zero-padded dates", function(test) {
var f = timeFormat.timeFormat("%d");
test.equal(f(date.local(1990, 0, 1)), "01");
test.end();
});
tape("timeFormat(\"%e\")(date) formats space-padded dates", function(test) {
var f = timeFormat.timeFormat("%e");
test.equal(f(date.local(1990, 0, 1)), " 1");
test.end();
});
tape("timeFormat(\"%H\")(date) formats zero-padded hours (24)", function(test) {
var f = timeFormat.timeFormat("%H");
test.equal(f(date.local(1990, 0, 1, 0)), "00");
test.equal(f(date.local(1990, 0, 1, 13)), "13");
test.end();
});
tape("timeFormat(\"%I\")(date) formats zero-padded hours (12)", function(test) {
var f = timeFormat.timeFormat("%I");
test.equal(f(date.local(1990, 0, 1, 0)), "12");
test.equal(f(date.local(1990, 0, 1, 13)), "01");
test.end();
});
tape("timeFormat(\"%j\")(date) formats zero-padded day of year numbers", function(test) {
var f = timeFormat.timeFormat("%j");
test.equal(f(date.local(1990, 0, 1)), "001");
test.equal(f(date.local(1990, 5, 1)), "152");
test.equal(f(date.local(2010, 2, 13)), "072");
test.equal(f(date.local(2010, 2, 14)), "073"); // DST begins
test.equal(f(date.local(2010, 2, 15)), "074");
test.equal(f(date.local(2010, 10, 6)), "310");
test.equal(f(date.local(2010, 10, 7)), "311"); // DST ends
test.equal(f(date.local(2010, 10, 8)), "312");
test.end();
});
tape("timeFormat(\"%m\")(date) formats zero-padded months", function(test) {
var f = timeFormat.timeFormat("%m");
test.equal(f(date.local(1990, 0, 1)), "01");
test.equal(f(date.local(1990, 9, 1)), "10");
test.end();
});
tape("timeFormat(\"%M\")(date) formats zero-padded minutes", function(test) {
var f = timeFormat.timeFormat("%M");
test.equal(f(date.local(1990, 0, 1, 0, 0)), "00");
test.equal(f(date.local(1990, 0, 1, 0, 32)), "32");
test.end();
});
tape("timeFormat(\"%p\")(date) formats AM or PM", function(test) {
var f = timeFormat.timeFormat("%p");
test.equal(f(date.local(1990, 0, 1, 0)), "AM");
test.equal(f(date.local(1990, 0, 1, 13)), "PM");
test.end();
});
tape("timeFormat(\"%S\")(date) formats zero-padded seconds", function(test) {
var f = timeFormat.timeFormat("%S");
test.equal(f(date.local(1990, 0, 1, 0, 0, 0)), "00");
test.equal(f(date.local(1990, 0, 1, 0, 0, 32)), "32");
var f = timeFormat.timeFormat("%0S");
test.equal(f(date.local(1990, 0, 1, 0, 0, 0)), "00");
test.equal(f(date.local(1990, 0, 1, 0, 0, 32)), "32");
test.end();
});
tape("timeFormat(\"%_S\")(date) formats space-padded seconds", function(test) {
var f = timeFormat.timeFormat("%_S");
test.equal(f(date.local(1990, 0, 1, 0, 0, 0)), " 0");
test.equal(f(date.local(1990, 0, 1, 0, 0, 3)), " 3");
test.equal(f(date.local(1990, 0, 1, 0, 0, 32)), "32");
test.end();
});
tape("timeFormat(\"-S\")(date) formats no-padded seconds", function(test) {
var f = timeFormat.timeFormat("%-S");
test.equal(f(date.local(1990, 0, 1, 0, 0, 0)), "0");
test.equal(f(date.local(1990, 0, 1, 0, 0, 3)), "3");
test.equal(f(date.local(1990, 0, 1, 0, 0, 32)), "32");
test.end();
});
tape("timeFormat(\"%L\")(date) formats zero-padded milliseconds", function(test) {
var f = timeFormat.timeFormat("%L");
test.equal(f(date.local(1990, 0, 1, 0, 0, 0, 0)), "000");
test.equal(f(date.local(1990, 0, 1, 0, 0, 0, 432)), "432");
test.end();
});
tape("timeFormat(\"%U\")(date) formats zero-padded week numbers", function(test) {
var f = timeFormat.timeFormat("%U");
test.equal(f(date.local(1990, 0, 1, 0)), "00");
test.equal(f(date.local(1990, 5, 1, 0)), "21");
test.equal(f(date.local(2010, 2, 13, 23)), "10");
test.equal(f(date.local(2010, 2, 14, 0)), "11"); // DST begins
test.equal(f(date.local(2010, 2, 15, 0)), "11");
test.equal(f(date.local(2010, 10, 6, 23)), "44");
test.equal(f(date.local(2010, 10, 7, 0)), "45"); // DST ends
test.equal(f(date.local(2010, 10, 8, 0)), "45");
test.end();
});
tape("timeFormat(\"%x\")(date) formats localized dates", function(test) {
var f = timeFormat.timeFormat("%x");
test.equal(f(date.local(1990, 0, 1)), "1/1/1990");
test.equal(f(date.local(2010, 5, 1)), "6/1/2010");
test.end();
});
tape("timeFormat(\"%X\")(date) formats localized times", function(test) {
var f = timeFormat.timeFormat("%X");
test.equal(f(date.local(1990, 0, 1, 0, 0, 0)), "12:00:00 AM");
test.equal(f(date.local(1990, 0, 1, 13, 34, 59)), "1:34:59 PM");
test.end();
});
tape("timeFormat(\"%y\")(date) formats zero-padded two-digit years", function(test) {
var f = timeFormat.timeFormat("%y");
test.equal(f(date.local(+1990, 0, 1)), "90");
test.equal(f(date.local(+2002, 0, 1)), "02");
test.equal(f(date.local(-0002, 0, 1)), "-02");
test.end();
});
tape("timeFormat(\"%Y\")(date) formats zero-padded four-digit years", function(test) {
var f = timeFormat.timeFormat("%Y");
test.equal(f(date.local( 123, 0, 1)), "0123");
test.equal(f(date.local( 1990, 0, 1)), "1990");
test.equal(f(date.local( 2002, 0, 1)), "2002");
test.equal(f(date.local(10002, 0, 1)), "0002");
test.equal(f(date.local( -2, 0, 1)), "-0002");
test.end();
});
tape("timeFormat(\"%Z\")(date) formats time zones", function(test) {
var f = timeFormat.timeFormat("%Z");
test.equal(f(date.local(1990, 0, 1)), "-0800");
test.end();
});
tape("timeFormat(\"%%\")(date) formats literal percent signs", function(test) {
var f = timeFormat.timeFormat("%%");
test.equal(f(date.local(1990, 0, 1)), "%");
test.end();
});
tape("timeFormat(…) can be used to create a conditional multi-format", function(test) {
test.equal(multi(date.local(1990, 0, 1, 0, 0, 0, 12)), ".012");
test.equal(multi(date.local(1990, 0, 1, 0, 0, 1, 0)), ":01");
test.equal(multi(date.local(1990, 0, 1, 0, 1, 0, 0)), "12:01");
test.equal(multi(date.local(1990, 0, 1, 1, 0, 0, 0)), "01 AM");
test.equal(multi(date.local(1990, 0, 2, 0, 0, 0, 0)), "Tue 02");
test.equal(multi(date.local(1990, 1, 1, 0, 0, 0, 0)), "February");
test.equal(multi(date.local(1990, 0, 1, 0, 0, 0, 0)), "1990");
test.end();
});
d3-time-format-2.0.5/test/isoFormat-test.js 0000664 0000000 0000000 00000000571 13060563012 0020502 0 ustar 00root root 0000000 0000000 var tape = require("tape"),
timeFormat = require("../"),
date = require("./date");
tape("isoFormat(date) returns an ISO 8601 UTC string", function(test) {
test.equal(timeFormat.isoFormat(date.utc(1990, 0, 1, 0, 0, 0)), "1990-01-01T00:00:00.000Z");
test.equal(timeFormat.isoFormat(date.utc(2011, 11, 31, 23, 59, 59)), "2011-12-31T23:59:59.000Z");
test.end();
});
d3-time-format-2.0.5/test/isoParse-test.js 0000664 0000000 0000000 00000000652 13060563012 0020324 0 ustar 00root root 0000000 0000000 var tape = require("tape"),
timeFormat = require("../"),
date = require("./date");
tape("isoParse as ISO 8601", function(test) {
test.deepEqual(timeFormat.isoParse("1990-01-01T00:00:00.000Z"), date.utc(1990, 0, 1, 0, 0, 0));
test.deepEqual(timeFormat.isoParse("2011-12-31T23:59:59.000Z"), date.utc(2011, 11, 31, 23, 59, 59));
test.equal(timeFormat.isoParse("1990-01-01T00:00:00.000X"), null);
test.end();
});
d3-time-format-2.0.5/test/locale-test.js 0000664 0000000 0000000 00000001646 13060563012 0020002 0 ustar 00root root 0000000 0000000 var fs = require("fs"),
path = require("path"),
tape = require("tape"),
queue = require("d3-queue"),
d3 = require("../");
tape("locale data is valid", function(test) {
fs.readdir("locale", function(error, locales) {
if (error) throw error;
var q = queue.queue(1);
locales.forEach(function(locale) {
if (!/\.json$/i.test(locale)) return;
q.defer(testLocale, path.join("locale", locale));
});
q.awaitAll(function(error) {
if (error) throw error;
test.end();
});
});
function testLocale(locale, callback) {
fs.readFile(locale, "utf8", function(error, locale) {
if (error) return void callback(error);
locale = JSON.parse(locale);
test.deepEqual(Object.keys(locale).sort(), ["date", "dateTime", "days", "months", "periods", "shortDays", "shortMonths", "time"]);
locale = d3.timeFormatLocale(locale);
callback(null);
});
}
});
d3-time-format-2.0.5/test/parse-test.js 0000664 0000000 0000000 00000025072 13060563012 0017654 0 ustar 00root root 0000000 0000000 var tape = require("tape"),
timeFormat = require("../"),
date = require("./date"),
FiFi = require("../locale/fi-FI");
tape("parse(string) coerces the specified string to a string", function(test) {
var p = timeFormat.timeParse("%c");
test.deepEqual(p({toString: function() { return "1/1/1990, 12:00:00 AM"; }}), date.local(1990, 0, 1));
test.deepEqual(p({toString: function() { return "1/2/1990, 12:00:00 AM"; }}), date.local(1990, 0, 2));
test.deepEqual(p({toString: function() { return "1/3/1990, 12:00:00 AM"; }}), date.local(1990, 0, 3));
test.deepEqual(p({toString: function() { return "1/4/1990, 12:00:00 AM"; }}), date.local(1990, 0, 4));
test.deepEqual(p({toString: function() { return "1/5/1990, 12:00:00 AM"; }}), date.local(1990, 0, 5));
test.deepEqual(p({toString: function() { return "1/6/1990, 12:00:00 AM"; }}), date.local(1990, 0, 6));
test.deepEqual(p({toString: function() { return "1/7/1990, 12:00:00 AM"; }}), date.local(1990, 0, 7));
test.end();
});
tape("timeParse(\"%a %m/%d/%Y\")(date) parses abbreviated weekday and date", function(test) {
var p = timeFormat.timeParse("%a %m/%d/%Y");
test.deepEqual(p("Sun 01/01/1990"), date.local(1990, 0, 1));
test.deepEqual(p("Wed 02/03/1991"), date.local(1991, 1, 3));
test.equal(p("XXX 03/10/2010"), null);
test.end();
});
tape("timeParse(\"%A %m/%d/%Y\")(date) parses weekday and date", function(test) {
var p = timeFormat.timeParse("%A %m/%d/%Y");
test.deepEqual(p("Sunday 01/01/1990"), date.local(1990, 0, 1));
test.deepEqual(p("Wednesday 02/03/1991"), date.local(1991, 1, 3));
test.equal(p("Caturday 03/10/2010"), null);
test.end();
});
tape("timeParse(\"%U %Y\")(date) parses week number (Sunday) and year", function(test) {
var p = timeFormat.timeParse("%U %Y");
test.deepEqual(p("00 1990"), date.local(1989, 11, 31));
test.deepEqual(p("05 1991"), date.local(1991, 1, 3));
test.deepEqual(p("01 1995"), date.local(1995, 0, 1));
test.end();
});
tape("timeParse(\"%a %U %Y\")(date) parses abbreviated weekday, week number (Sunday) and year", function(test) {
var p = timeFormat.timeParse("%a %U %Y");
test.deepEqual(p("Mon 00 1990"), date.local(1990, 0, 1));
test.deepEqual(p("Sun 05 1991"), date.local(1991, 1, 3));
test.deepEqual(p("Sun 01 1995"), date.local(1995, 0, 1));
test.equal(p("XXX 03 2010"), null);
test.end();
});
tape("timeParse(\"%A %U %Y\")(date) parses weekday, week number (Sunday) and year", function(test) {
var p = timeFormat.timeParse("%A %U %Y");
test.deepEqual(p("Monday 00 1990"), date.local(1990, 0, 1));
test.deepEqual(p("Sunday 05 1991"), date.local(1991, 1, 3));
test.deepEqual(p("Sunday 01 1995"), date.local(1995, 0, 1));
test.equal(p("Caturday 03 2010"), null);
test.end();
});
tape("timeParse(\"%w %U %Y\")(date) parses numeric weekday, week number (Sunday) and year", function(test) {
var p = timeFormat.timeParse("%w %U %Y");
test.deepEqual(p("1 00 1990"), date.local(1990, 0, 1));
test.deepEqual(p("0 05 1991"), date.local(1991, 1, 3));
test.deepEqual(p("0 01 1995"), date.local(1995, 0, 1));
test.equal(p("X 03 2010"), null);
test.end();
});
tape("timeParse(\"%W %Y\")(date) parses week number (Monday) and year", function(test) {
var p = timeFormat.timeParse("%W %Y");
test.deepEqual(p("01 1990"), date.local(1990, 0, 1));
test.deepEqual(p("04 1991"), date.local(1991, 0, 28));
test.deepEqual(p("00 1995"), date.local(1994, 11, 26));
test.end();
});
tape("timeParse(\"%a %W %Y\")(date) parses abbreviated weekday, week number (Monday) and year", function(test) {
var p = timeFormat.timeParse("%a %W %Y");
test.deepEqual(p("Mon 01 1990"), date.local(1990, 0, 1));
test.deepEqual(p("Sun 04 1991"), date.local(1991, 1, 3));
test.deepEqual(p("Sun 00 1995"), date.local(1995, 0, 1));
test.equal(p("XXX 03 2010"), null);
test.end();
});
tape("timeParse(\"%A %W %Y\")(date) parses weekday, week number (Monday) and year", function(test) {
var p = timeFormat.timeParse("%A %W %Y");
test.deepEqual(p("Monday 01 1990"), date.local(1990, 0, 1));
test.deepEqual(p("Sunday 04 1991"), date.local(1991, 1, 3));
test.deepEqual(p("Sunday 00 1995"), date.local(1995, 0, 1));
test.equal(p("Caturday 03 2010"), null);
test.end();
});
tape("timeParse(\"%w %W %Y\")(date) parses numeric weekday, week number (Monday) and year", function(test) {
var p = timeFormat.timeParse("%w %W %Y");
test.deepEqual(p("1 01 1990"), date.local(1990, 0, 1));
test.deepEqual(p("0 04 1991"), date.local(1991, 1, 3));
test.deepEqual(p("0 00 1995"), date.local(1995, 0, 1));
test.equal(p("X 03 2010"), null);
test.end();
});
tape("timeParse(\"%m/%d/%y\")(date) parses month, date and two-digit year", function(test) {
var p = timeFormat.timeParse("%m/%d/%y");
test.deepEqual(p("02/03/69"), date.local(1969, 1, 3));
test.deepEqual(p("01/01/90"), date.local(1990, 0, 1));
test.deepEqual(p("02/03/91"), date.local(1991, 1, 3));
test.deepEqual(p("02/03/68"), date.local(2068, 1, 3));
test.equal(p("03/10/2010"), null);
test.end();
});
tape("timeParse(\"%x\")(date) parses locale date", function(test) {
var p = timeFormat.timeParse("%x");
test.deepEqual(p("1/1/1990"), date.local(1990, 0, 1));
test.deepEqual(p("2/3/1991"), date.local(1991, 1, 3));
test.deepEqual(p("3/10/2010"), date.local(2010, 2, 10));
test.end();
});
tape("timeParse(\"%b %d, %Y\")(date) parses abbreviated month, date and year", function(test) {
var p = timeFormat.timeParse("%b %d, %Y");
test.deepEqual(p("jan 01, 1990"), date.local(1990, 0, 1));
test.deepEqual(p("feb 2, 2010"), date.local(2010, 1, 2));
test.equal(p("jan. 1, 1990"), null);
test.end();
});
tape("timeParse(\"%B %d, %Y\")(date) parses month, date and year", function(test) {
var p = timeFormat.timeParse("%B %d, %Y");
test.deepEqual(p("january 01, 1990"), date.local(1990, 0, 1));
test.deepEqual(p("February 2, 2010"), date.local(2010, 1, 2));
test.equal(p("jan 1, 1990"), null);
test.end();
});
tape("timeParse(\"%j %m/%d/%Y\")(date) parses day of year and date", function(test) {
var p = timeFormat.timeParse("%j %m/%d/%Y");
test.deepEqual(p("001 01/01/1990"), date.local(1990, 0, 1));
test.deepEqual(p("034 02/03/1991"), date.local(1991, 1, 3));
test.equal(p("2012 03/10/2010"), null);
test.end();
});
tape("timeParse(\"%c\")(date) parses locale date and time", function(test) {
var p = timeFormat.timeParse("%c");
test.deepEqual(p("1/1/1990, 12:00:00 AM"), date.local(1990, 0, 1));
test.end();
});
tape("timeParse(\"%H:%M:%S\")(date) parses twenty-four hour, minute and second", function(test) {
var p = timeFormat.timeParse("%H:%M:%S");
test.deepEqual(p("00:00:00"), date.local(1900, 0, 1, 0, 0, 0));
test.deepEqual(p("11:59:59"), date.local(1900, 0, 1, 11, 59, 59));
test.deepEqual(p("12:00:00"), date.local(1900, 0, 1, 12, 0, 0));
test.deepEqual(p("12:00:01"), date.local(1900, 0, 1, 12, 0, 1));
test.deepEqual(p("23:59:59"), date.local(1900, 0, 1, 23, 59, 59));
test.end();
});
tape("timeParse(\"%X\")(date) parses locale time", function(test) {
var p = timeFormat.timeParse("%X");
test.deepEqual(p("12:00:00 AM"), date.local(1900, 0, 1, 0, 0, 0));
test.deepEqual(p("11:59:59 AM"), date.local(1900, 0, 1, 11, 59, 59));
test.deepEqual(p("12:00:00 PM"), date.local(1900, 0, 1, 12, 0, 0));
test.deepEqual(p("12:00:01 PM"), date.local(1900, 0, 1, 12, 0, 1));
test.deepEqual(p("11:59:59 PM"), date.local(1900, 0, 1, 23, 59, 59));
test.end();
});
tape("timeParse(\"%I:%M:%S %p\")(date) parses twelve hour, minute and second", function(test) {
var p = timeFormat.timeParse("%I:%M:%S %p");
test.deepEqual(p("12:00:00 am"), date.local(1900, 0, 1, 0, 0, 0));
test.deepEqual(p("11:59:59 AM"), date.local(1900, 0, 1, 11, 59, 59));
test.deepEqual(p("12:00:00 pm"), date.local(1900, 0, 1, 12, 0, 0));
test.deepEqual(p("12:00:01 pm"), date.local(1900, 0, 1, 12, 0, 1));
test.deepEqual(p("11:59:59 PM"), date.local(1900, 0, 1, 23, 59, 59));
test.end();
});
tape("timeParse(\"%I %p\")(date) parses period in non-English locales", function(test) {
var p = timeFormat.timeFormatLocale(FiFi).parse("%I:%M:%S %p");
test.deepEqual(p("12:00:00 a.m."), date.local(1900, 0, 1, 0, 0, 0));
test.deepEqual(p("11:59:59 A.M."), date.local(1900, 0, 1, 11, 59, 59));
test.deepEqual(p("12:00:00 p.m."), date.local(1900, 0, 1, 12, 0, 0));
test.deepEqual(p("12:00:01 p.m."), date.local(1900, 0, 1, 12, 0, 1));
test.deepEqual(p("11:59:59 P.M."), date.local(1900, 0, 1, 23, 59, 59));
test.end();
});
tape("timeParse(\"%% %m/%d/%Y\")(date) parses literal %", function(test) {
var p = timeFormat.timeParse("%% %m/%d/%Y");
test.deepEqual(p("% 01/01/1990"), date.local(1990, 0, 1));
test.deepEqual(p("% 02/03/1991"), date.local(1991, 1, 3));
test.equal(p("%% 03/10/2010"), null);
test.end();
});
tape("timeParse(\"%m/%d/%Y %Z\")(date) parses timezone offset", function(test) {
var p = timeFormat.timeParse("%m/%d/%Y %Z");
test.deepEqual(p("01/02/1990 +0000"), date.local(1990, 0, 1, 16));
test.deepEqual(p("01/02/1990 +0100"), date.local(1990, 0, 1, 15));
test.deepEqual(p("01/02/1990 +0130"), date.local(1990, 0, 1, 14, 30));
test.deepEqual(p("01/02/1990 -0100"), date.local(1990, 0, 1, 17));
test.deepEqual(p("01/02/1990 -0130"), date.local(1990, 0, 1, 17, 30));
test.deepEqual(p("01/02/1990 -0800"), date.local(1990, 0, 2, 0));
test.end();
});
tape("timeParse(\"%m/%d/%Y %Z\")(date) parses timezone offset in the form '+-hh:mm'", function(test) {
var p = timeFormat.timeParse("%m/%d/%Y %Z");
test.deepEqual(p("01/02/1990 +01:30"), date.local(1990, 0, 1, 14, 30));
test.deepEqual(p("01/02/1990 -01:30"), date.local(1990, 0, 1, 17, 30));
test.end();
});
tape("timeParse(\"%m/%d/%Y %Z\")(date) parses timezone offset in the form '+-hh'", function(test) {
var p = timeFormat.timeParse("%m/%d/%Y %Z");
test.deepEqual(p("01/02/1990 +01"), date.local(1990, 0, 1, 15));
test.deepEqual(p("01/02/1990 -01"), date.local(1990, 0, 1, 17));
test.end();
});
tape("timeParse(\"%m/%d/%Y %Z\")(date) parses timezone offset in the form 'Z'", function(test) {
var p = timeFormat.timeParse("%m/%d/%Y %Z");
test.deepEqual(p("01/02/1990 Z"), date.local(1990, 0, 1, 16));
test.end();
});
tape("timeParse(\"%-m/%0d/%_Y\")(date) ignores optional padding modifier, skipping zeroes and spaces", function(test) {
var p = timeFormat.timeParse("%-m/%0d/%_Y");
test.deepEqual(p("01/ 1/1990"), date.local(1990, 0, 1));
test.end();
});
tape("timeParse(\"%b %d, %Y\")(date) doesn't crash when given weird strings", function(test) {
try {
Object.prototype.foo = 10;
var p = timeFormat.timeParse("%b %d, %Y");
test.equal(p("foo 1, 1990"), null);
} finally {
delete Object.prototype.foo;
}
test.end();
});
d3-time-format-2.0.5/test/utcFormat-test.js 0000664 0000000 0000000 00000022232 13060563012 0020501 0 ustar 00root root 0000000 0000000 var tape = require("tape"),
time = require("d3-time"),
timeFormat = require("../"),
date = require("./date");
var formatMillisecond = timeFormat.utcFormat(".%L"),
formatSecond = timeFormat.utcFormat(":%S"),
formatMinute = timeFormat.utcFormat("%I:%M"),
formatHour = timeFormat.utcFormat("%I %p"),
formatDay = timeFormat.utcFormat("%a %d"),
formatWeek = timeFormat.utcFormat("%b %d"),
formatMonth = timeFormat.utcFormat("%B"),
formatYear = timeFormat.utcFormat("%Y");
function multi(d) {
return (time.utcSecond(d) < d ? formatMillisecond
: time.utcMinute(d) < d ? formatSecond
: time.utcHour(d) < d ? formatMinute
: time.utcDay(d) < d ? formatHour
: time.utcMonth(d) < d ? (time.utcWeek(d) < d ? formatDay : formatWeek)
: time.utcYear(d) < d ? formatMonth
: formatYear)(d);
}
tape("utcFormat(\"%a\")(date) formats abbreviated weekdays", function(test) {
var f = timeFormat.utcFormat("%a");
test.equal(f(date.utc(1990, 0, 1)), "Mon");
test.equal(f(date.utc(1990, 0, 2)), "Tue");
test.equal(f(date.utc(1990, 0, 3)), "Wed");
test.equal(f(date.utc(1990, 0, 4)), "Thu");
test.equal(f(date.utc(1990, 0, 5)), "Fri");
test.equal(f(date.utc(1990, 0, 6)), "Sat");
test.equal(f(date.utc(1990, 0, 7)), "Sun");
test.end();
});
tape("utcFormat(\"%A\")(date) formats weekdays", function(test) {
var f = timeFormat.utcFormat("%A");
test.equal(f(date.utc(1990, 0, 1)), "Monday");
test.equal(f(date.utc(1990, 0, 2)), "Tuesday");
test.equal(f(date.utc(1990, 0, 3)), "Wednesday");
test.equal(f(date.utc(1990, 0, 4)), "Thursday");
test.equal(f(date.utc(1990, 0, 5)), "Friday");
test.equal(f(date.utc(1990, 0, 6)), "Saturday");
test.equal(f(date.utc(1990, 0, 7)), "Sunday");
test.end();
});
tape("utcFormat(\"%b\")(date) formats abbreviated months", function(test) {
var f = timeFormat.utcFormat("%b");
test.equal(f(date.utc(1990, 0, 1)), "Jan");
test.equal(f(date.utc(1990, 1, 1)), "Feb");
test.equal(f(date.utc(1990, 2, 1)), "Mar");
test.equal(f(date.utc(1990, 3, 1)), "Apr");
test.equal(f(date.utc(1990, 4, 1)), "May");
test.equal(f(date.utc(1990, 5, 1)), "Jun");
test.equal(f(date.utc(1990, 6, 1)), "Jul");
test.equal(f(date.utc(1990, 7, 1)), "Aug");
test.equal(f(date.utc(1990, 8, 1)), "Sep");
test.equal(f(date.utc(1990, 9, 1)), "Oct");
test.equal(f(date.utc(1990, 10, 1)), "Nov");
test.equal(f(date.utc(1990, 11, 1)), "Dec");
test.end();
});
tape("utcFormat(\"%B\")(date) formats months", function(test) {
var f = timeFormat.utcFormat("%B");
test.equal(f(date.utc(1990, 0, 1)), "January");
test.equal(f(date.utc(1990, 1, 1)), "February");
test.equal(f(date.utc(1990, 2, 1)), "March");
test.equal(f(date.utc(1990, 3, 1)), "April");
test.equal(f(date.utc(1990, 4, 1)), "May");
test.equal(f(date.utc(1990, 5, 1)), "June");
test.equal(f(date.utc(1990, 6, 1)), "July");
test.equal(f(date.utc(1990, 7, 1)), "August");
test.equal(f(date.utc(1990, 8, 1)), "September");
test.equal(f(date.utc(1990, 9, 1)), "October");
test.equal(f(date.utc(1990, 10, 1)), "November");
test.equal(f(date.utc(1990, 11, 1)), "December");
test.end();
});
tape("utcFormat(\"%c\")(date) formats localized dates and times", function(test) {
var f = timeFormat.utcFormat("%c");
test.equal(f(date.utc(1990, 0, 1)), "1/1/1990, 12:00:00 AM");
test.end();
});
tape("utcFormat(\"%d\")(date) formats zero-padded dates", function(test) {
var f = timeFormat.utcFormat("%d");
test.equal(f(date.utc(1990, 0, 1)), "01");
test.end();
});
tape("utcFormat(\"%e\")(date) formats space-padded dates", function(test) {
var f = timeFormat.utcFormat("%e");
test.equal(f(date.utc(1990, 0, 1)), " 1");
test.end();
});
tape("utcFormat(\"%H\")(date) formats zero-padded hours (24)", function(test) {
var f = timeFormat.utcFormat("%H");
test.equal(f(date.utc(1990, 0, 1, 0)), "00");
test.equal(f(date.utc(1990, 0, 1, 13)), "13");
test.end();
});
tape("utcFormat(\"%I\")(date) formats zero-padded hours (12)", function(test) {
var f = timeFormat.utcFormat("%I");
test.equal(f(date.utc(1990, 0, 1, 0)), "12");
test.equal(f(date.utc(1990, 0, 1, 13)), "01");
test.end();
});
tape("utcFormat(\"%j\")(date) formats zero-padded day of year numbers", function(test) {
var f = timeFormat.utcFormat("%j");
test.equal(f(date.utc(1990, 0, 1)), "001");
test.equal(f(date.utc(1990, 5, 1)), "152");
test.equal(f(date.utc(2010, 2, 13)), "072");
test.equal(f(date.utc(2010, 2, 14)), "073"); // DST begins
test.equal(f(date.utc(2010, 2, 15)), "074");
test.equal(f(date.utc(2010, 10, 6)), "310");
test.equal(f(date.utc(2010, 10, 7)), "311"); // DST ends
test.equal(f(date.utc(2010, 10, 8)), "312");
test.end();
});
tape("utcFormat(\"%m\")(date) formats zero-padded months", function(test) {
var f = timeFormat.utcFormat("%m");
test.equal(f(date.utc(1990, 0, 1)), "01");
test.equal(f(date.utc(1990, 9, 1)), "10");
test.end();
});
tape("utcFormat(\"%M\")(date) formats zero-padded minutes", function(test) {
var f = timeFormat.utcFormat("%M");
test.equal(f(date.utc(1990, 0, 1, 0, 0)), "00");
test.equal(f(date.utc(1990, 0, 1, 0, 32)), "32");
test.end();
});
tape("utcFormat(\"%p\")(date) formats AM or PM", function(test) {
var f = timeFormat.utcFormat("%p");
test.equal(f(date.utc(1990, 0, 1, 0)), "AM");
test.equal(f(date.utc(1990, 0, 1, 13)), "PM");
test.end();
});
tape("utcFormat(\"%S\")(date) formats zero-padded seconds", function(test) {
var f = timeFormat.utcFormat("%S");
test.equal(f(date.utc(1990, 0, 1, 0, 0, 0)), "00");
test.equal(f(date.utc(1990, 0, 1, 0, 0, 32)), "32");
var f = timeFormat.utcFormat("%0S");
test.equal(f(date.utc(1990, 0, 1, 0, 0, 0)), "00");
test.equal(f(date.utc(1990, 0, 1, 0, 0, 32)), "32");
test.end();
});
tape("utcFormat(\"%_S\")(date) formats space-padded seconds", function(test) {
var f = timeFormat.utcFormat("%_S");
test.equal(f(date.utc(1990, 0, 1, 0, 0, 0)), " 0");
test.equal(f(date.utc(1990, 0, 1, 0, 0, 3)), " 3");
test.equal(f(date.utc(1990, 0, 1, 0, 0, 32)), "32");
test.end();
});
tape("utcFormat(\"-S\")(date) formats no-padded seconds", function(test) {
var f = timeFormat.utcFormat("%-S");
test.equal(f(date.utc(1990, 0, 1, 0, 0, 0)), "0");
test.equal(f(date.utc(1990, 0, 1, 0, 0, 3)), "3");
test.equal(f(date.utc(1990, 0, 1, 0, 0, 32)), "32");
test.end();
});
tape("utcFormat(\"%L\")(date) formats zero-padded milliseconds", function(test) {
var f = timeFormat.utcFormat("%L");
test.equal(f(date.utc(1990, 0, 1, 0, 0, 0, 0)), "000");
test.equal(f(date.utc(1990, 0, 1, 0, 0, 0, 432)), "432");
test.end();
});
tape("utcFormat(\"%U\")(date) formats zero-padded week numbers", function(test) {
var f = timeFormat.utcFormat("%U");
test.equal(f(date.utc(1990, 0, 1, 0)), "00");
test.equal(f(date.utc(1990, 5, 1, 0)), "21");
test.equal(f(date.utc(2010, 2, 13, 23)), "10");
test.equal(f(date.utc(2010, 2, 14, 0)), "11"); // DST begins
test.equal(f(date.utc(2010, 2, 15, 0)), "11");
test.equal(f(date.utc(2010, 10, 6, 23)), "44");
test.equal(f(date.utc(2010, 10, 7, 0)), "45"); // DST ends
test.equal(f(date.utc(2010, 10, 8, 0)), "45");
test.end();
});
tape("utcFormat(\"%x\")(date) formats localized dates", function(test) {
var f = timeFormat.utcFormat("%x");
test.equal(f(date.utc(1990, 0, 1)), "1/1/1990");
test.equal(f(date.utc(2010, 5, 1)), "6/1/2010");
test.end();
});
tape("utcFormat(\"%X\")(date) formats localized times", function(test) {
var f = timeFormat.utcFormat("%X");
test.equal(f(date.utc(1990, 0, 1, 0, 0, 0)), "12:00:00 AM");
test.equal(f(date.utc(1990, 0, 1, 13, 34, 59)), "1:34:59 PM");
test.end();
});
tape("utcFormat(\"%y\")(date) formats zero-padded two-digit years", function(test) {
var f = timeFormat.utcFormat("%y");
test.equal(f(date.utc(+1990, 0, 1)), "90");
test.equal(f(date.utc(+2002, 0, 1)), "02");
test.equal(f(date.utc(-0002, 0, 1)), "-02");
test.end();
});
tape("utcFormat(\"%Y\")(date) formats zero-padded four-digit years", function(test) {
var f = timeFormat.utcFormat("%Y");
test.equal(f(date.utc( 123, 0, 1)), "0123");
test.equal(f(date.utc( 1990, 0, 1)), "1990");
test.equal(f(date.utc( 2002, 0, 1)), "2002");
test.equal(f(date.utc(10002, 0, 1)), "0002");
test.equal(f(date.utc( -2, 0, 1)), "-0002");
test.end();
});
tape("utcFormat(\"%Z\")(date) formats time zones", function(test) {
var f = timeFormat.utcFormat("%Z");
test.equal(f(date.utc(1990, 0, 1)), "+0000");
test.end();
});
tape("utcFormat(\"%%\")(date) formats literal percent signs", function(test) {
var f = timeFormat.utcFormat("%%");
test.equal(f(date.utc(1990, 0, 1)), "%");
test.end();
});
tape("utcFormat(…) can be used to create a conditional multi-format", function(test) {
test.equal(multi(date.utc(1990, 0, 1, 0, 0, 0, 12)), ".012");
test.equal(multi(date.utc(1990, 0, 1, 0, 0, 1, 0)), ":01");
test.equal(multi(date.utc(1990, 0, 1, 0, 1, 0, 0)), "12:01");
test.equal(multi(date.utc(1990, 0, 1, 1, 0, 0, 0)), "01 AM");
test.equal(multi(date.utc(1990, 0, 2, 0, 0, 0, 0)), "Tue 02");
test.equal(multi(date.utc(1990, 1, 1, 0, 0, 0, 0)), "February");
test.equal(multi(date.utc(1990, 0, 1, 0, 0, 0, 0)), "1990");
test.end();
});
d3-time-format-2.0.5/test/utcParse-test.js 0000664 0000000 0000000 00000011171 13060563012 0020323 0 ustar 00root root 0000000 0000000 var tape = require("tape"),
timeFormat = require("../"),
date = require("./date");
tape("utcParse(\"\")(date) parses abbreviated weekday and numeric date", function(test) {
var p = timeFormat.utcParse("%a %m/%d/%Y");
test.deepEqual(p("Sun 01/01/1990"), date.utc(1990, 0, 1));
test.deepEqual(p("Wed 02/03/1991"), date.utc(1991, 1, 3));
test.equal(p("XXX 03/10/2010"), null);
test.end();
});
tape("utcParse(\"\")(date) parses weekday and numeric date", function(test) {
var p = timeFormat.utcParse("%A %m/%d/%Y");
test.deepEqual(p("Sunday 01/01/1990"), date.utc(1990, 0, 1));
test.deepEqual(p("Wednesday 02/03/1991"), date.utc(1991, 1, 3));
test.equal(p("Caturday 03/10/2010"), null);
test.end();
});
tape("utcParse(\"\")(date) parses numeric date", function(test) {
var p = timeFormat.utcParse("%m/%d/%y");
test.deepEqual(p("01/01/90"), date.utc(1990, 0, 1));
test.deepEqual(p("02/03/91"), date.utc(1991, 1, 3));
test.equal(p("03/10/2010"), null);
test.end();
});
tape("utcParse(\"\")(date) parses locale date", function(test) {
var p = timeFormat.utcParse("%x");
test.deepEqual(p("01/01/1990"), date.utc(1990, 0, 1));
test.deepEqual(p("02/03/1991"), date.utc(1991, 1, 3));
test.deepEqual(p("03/10/2010"), date.utc(2010, 2, 10));
test.end();
});
tape("utcParse(\"\")(date) parses abbreviated month, date and year", function(test) {
var p = timeFormat.utcParse("%b %d, %Y");
test.deepEqual(p("jan 01, 1990"), date.utc(1990, 0, 1));
test.deepEqual(p("feb 2, 2010"), date.utc(2010, 1, 2));
test.equal(p("jan. 1, 1990"), null);
test.end();
});
tape("utcParse(\"\")(date) parses month, date and year", function(test) {
var p = timeFormat.utcParse("%B %d, %Y");
test.deepEqual(p("january 01, 1990"), date.utc(1990, 0, 1));
test.deepEqual(p("February 2, 2010"), date.utc(2010, 1, 2));
test.equal(p("jan 1, 1990"), null);
test.end();
});
tape("utcParse(\"\")(date) parses locale date and time", function(test) {
var p = timeFormat.utcParse("%c");
test.deepEqual(p("1/1/1990, 12:00:00 AM"), date.utc(1990, 0, 1));
test.end();
});
tape("utcParse(\"\")(date) parses twenty-four hour, minute and second", function(test) {
var p = timeFormat.utcParse("%H:%M:%S");
test.deepEqual(p("00:00:00"), date.utc(1900, 0, 1, 0, 0, 0));
test.deepEqual(p("11:59:59"), date.utc(1900, 0, 1, 11, 59, 59));
test.deepEqual(p("12:00:00"), date.utc(1900, 0, 1, 12, 0, 0));
test.deepEqual(p("12:00:01"), date.utc(1900, 0, 1, 12, 0, 1));
test.deepEqual(p("23:59:59"), date.utc(1900, 0, 1, 23, 59, 59));
test.end();
});
tape("utcParse(\"\")(date) parses locale time", function(test) {
var p = timeFormat.utcParse("%X");
test.deepEqual(p("12:00:00 AM"), date.utc(1900, 0, 1, 0, 0, 0));
test.deepEqual(p("11:59:59 AM"), date.utc(1900, 0, 1, 11, 59, 59));
test.deepEqual(p("12:00:00 PM"), date.utc(1900, 0, 1, 12, 0, 0));
test.deepEqual(p("12:00:01 PM"), date.utc(1900, 0, 1, 12, 0, 1));
test.deepEqual(p("11:59:59 PM"), date.utc(1900, 0, 1, 23, 59, 59));
test.end();
});
tape("utcParse(\"\")(date) parses twelve hour, minute and second", function(test) {
var p = timeFormat.utcParse("%I:%M:%S %p");
test.deepEqual(p("12:00:00 am"), date.utc(1900, 0, 1, 0, 0, 0));
test.deepEqual(p("11:59:59 AM"), date.utc(1900, 0, 1, 11, 59, 59));
test.deepEqual(p("12:00:00 pm"), date.utc(1900, 0, 1, 12, 0, 0));
test.deepEqual(p("12:00:01 pm"), date.utc(1900, 0, 1, 12, 0, 1));
test.deepEqual(p("11:59:59 PM"), date.utc(1900, 0, 1, 23, 59, 59));
test.end();
});
tape("utcParse(\"\")(date) parses timezone offset", function(test) {
var p = timeFormat.utcParse("%m/%d/%Y %Z");
test.deepEqual(p("01/02/1990 +0000"), date.utc(1990, 0, 2));
test.deepEqual(p("01/02/1990 +0100"), date.utc(1990, 0, 1, 23));
test.deepEqual(p("01/02/1990 -0100"), date.utc(1990, 0, 2, 1));
test.deepEqual(p("01/02/1990 -0800"), date.local(1990, 0, 2));
test.end();
});
tape("utcParse(\"\")(date) parses timezone offset (in the form '+-hh:mm')", function(test) {
var p = timeFormat.utcParse("%m/%d/%Y %Z");
test.deepEqual(p("01/02/1990 +01:30"), date.utc(1990, 0, 1, 22, 30));
test.deepEqual(p("01/02/1990 -01:30"), date.utc(1990, 0, 2, 1, 30));
test.end();
});
tape("utcParse(\"\")(date) parses timezone offset (in the form '+-hh')", function(test) {
var p = timeFormat.utcParse("%m/%d/%Y %Z");
test.deepEqual(p("01/02/1990 +01"), date.utc(1990, 0, 1, 23));
test.deepEqual(p("01/02/1990 -01"), date.utc(1990, 0, 2, 1));
test.end();
});
tape("utcParse(\"\")(date) parses timezone offset (in the form 'Z')", function(test) {
var p = timeFormat.utcParse("%m/%d/%Y %Z");
test.deepEqual(p("01/02/1990 Z"), date.utc(1990, 0, 2));
test.end();
});