globalize-rpk 1.7.0 → 1.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/globalize/currency.js +590 -0
  2. package/globalize/date.js +3139 -0
  3. package/globalize/globalize-runtime.js +326 -0
  4. package/globalize/globalize.js +507 -0
  5. package/globalize/message.js +2076 -0
  6. package/globalize/number.js +1727 -0
  7. package/globalize/plural.js +376 -0
  8. package/globalize/relative-time.js +203 -0
  9. package/globalize/unit.js +301 -0
  10. package/node-main.js +27 -0
  11. package/package.json +3 -26
  12. package/CONTRIBUTING.md +0 -5
  13. package/README.md +0 -818
  14. package/doc/api/core/constructor.md +0 -28
  15. package/doc/api/core/load.md +0 -96
  16. package/doc/api/core/locale.md +0 -43
  17. package/doc/api/currency/currency-formatter.md +0 -196
  18. package/doc/api/currency/currency-to-parts-formatter.md +0 -117
  19. package/doc/api/date/date-formatter.md +0 -203
  20. package/doc/api/date/date-parser.md +0 -60
  21. package/doc/api/date/date-to-parts-formatter.md +0 -176
  22. package/doc/api/date/load-iana-time-zone.md +0 -29
  23. package/doc/api/message/load-messages.md +0 -105
  24. package/doc/api/message/message-formatter.md +0 -208
  25. package/doc/api/number/number-formatter.md +0 -202
  26. package/doc/api/number/number-parser.md +0 -130
  27. package/doc/api/number/number-to-parts-formatter.md +0 -140
  28. package/doc/api/plural/plural-generator.md +0 -84
  29. package/doc/api/relative-time/relative-time-formatter.md +0 -60
  30. package/doc/api/unit/unit-formatter.md +0 -72
  31. package/doc/blog-post/2017-07-xx-1.3.0-announcement.md +0 -177
  32. package/doc/cldr.md +0 -114
  33. package/doc/error/e-default-locale-not-defined.md +0 -9
  34. package/doc/error/e-invalid-cldr.md +0 -14
  35. package/doc/error/e-invalid-par-type.md +0 -12
  36. package/doc/error/e-invalid-par-value.md +0 -11
  37. package/doc/error/e-missing-cldr.md +0 -11
  38. package/doc/error/e-missing-parameter.md +0 -10
  39. package/doc/error/e-missing-plural-module.md +0 -9
  40. package/doc/error/e-par-missing-key.md +0 -11
  41. package/doc/error/e-par-out-of-range.md +0 -13
  42. package/doc/error/e-unsupported.md +0 -10
  43. package/doc/migrating-from-0.x.md +0 -64
  44. package/examples/amd-bower/.bowerrc +0 -7
  45. package/examples/amd-bower/README.md +0 -65
  46. package/examples/amd-bower/bower.json +0 -13
  47. package/examples/amd-bower/index.html +0 -46
  48. package/examples/amd-bower/main.js +0 -141
  49. package/examples/amd-bower/messages/en.json +0 -12
  50. package/examples/amd-bower/package.json +0 -14
  51. package/examples/app-npm-webpack/README.md +0 -74
  52. package/examples/app-npm-webpack/app/index.js +0 -89
  53. package/examples/app-npm-webpack/index-template.html +0 -71
  54. package/examples/app-npm-webpack/messages/ar.json +0 -25
  55. package/examples/app-npm-webpack/messages/de.json +0 -21
  56. package/examples/app-npm-webpack/messages/en.json +0 -21
  57. package/examples/app-npm-webpack/messages/es.json +0 -21
  58. package/examples/app-npm-webpack/messages/pt.json +0 -21
  59. package/examples/app-npm-webpack/messages/ru.json +0 -23
  60. package/examples/app-npm-webpack/messages/zh.json +0 -20
  61. package/examples/app-npm-webpack/package.json +0 -17
  62. package/examples/app-npm-webpack/webpack-config.js +0 -63
  63. package/examples/globalize-compiler/README.md +0 -45
  64. package/examples/globalize-compiler/app.js +0 -58
  65. package/examples/globalize-compiler/development.html +0 -121
  66. package/examples/globalize-compiler/messages.json +0 -12
  67. package/examples/globalize-compiler/package.json +0 -15
  68. package/examples/globalize-compiler/production.html +0 -75
  69. package/examples/node-npm/README.md +0 -57
  70. package/examples/node-npm/main.js +0 -65
  71. package/examples/node-npm/messages/en.json +0 -12
  72. package/examples/node-npm/package.json +0 -10
  73. package/examples/plain-javascript/README.md +0 -81
  74. package/examples/plain-javascript/index.html +0 -445
@@ -1,28 +0,0 @@
1
- ## [new] Globalize( locale|cldr )
2
-
3
- Create a Globalize instance.
4
-
5
- ### Parameters
6
-
7
- #### locale|cldr
8
-
9
- Locale string or [Cldr instance](https://github.com/rxaviers/cldrjs) of the instance.
10
-
11
- ### Example
12
-
13
- Prior to creating any Globalize instance, you must load `cldr/supplemental/likelySubtags.json`. Read [CLDR content][] if you need more information.
14
-
15
- [CLDR content]: ../../../README.md#2-cldr-content
16
-
17
- ```javascript
18
- var en = new Globalize( "en" );
19
-
20
- // You can optionally omit the `new` operator.
21
- var pt = Globalize( "pt" );
22
-
23
- en.formatNumber( 3.1415 );
24
- // > 3.142
25
-
26
- pt.formatNumber( 3.1415 );
27
- // > 3,142
28
- ```
@@ -1,96 +0,0 @@
1
- ## Globalize.load( cldrJSONData, ... )
2
-
3
- This method allows you to load CLDR JSON locale data. `Globalize.load()` is a proxy to `Cldr.load()`.
4
-
5
- This method can be called as many times as needed. All passed JSON objects are deeply merged internally.
6
-
7
- For more information, see https://github.com/rxaviers/cldrjs#readme.
8
-
9
- ### Parameters
10
-
11
- #### cldrJSONData
12
-
13
- A JSON object with CLDR data. See [Getting Started](#../../../README.md#2-cldr-content) for more information.
14
-
15
- ### Example
16
-
17
- ```javascript
18
- Globalize.load({
19
- "main": {
20
- "en": {
21
- "identity": {
22
- "version": {
23
- "_cldrVersion": "25",
24
- "_number": "$Revision: 91 $"
25
- },
26
- "generation": {
27
- "_date": "$Date: 2014-03-13 22:27:12 -0500 (Thu, 13 Mar 2014) $"
28
- },
29
- "language": "en"
30
- },
31
- "dates": {
32
- "calendars": {
33
- "gregorian": {
34
- "months": {
35
- "format": {
36
- "abbreviated": {
37
- "1": "Jan",
38
- "2": "Feb",
39
- "3": "Mar",
40
- "4": "Apr",
41
- "5": "May",
42
- "6": "Jun",
43
- "7": "Jul",
44
- "8": "Aug",
45
- "9": "Sep",
46
- "10": "Oct",
47
- "11": "Nov",
48
- "12": "Dec"
49
- }
50
- }
51
- },
52
- "dayPeriods": {
53
- "format": {
54
- "wide": {
55
- "am": "AM",
56
- "am-alt-variant": "am",
57
- "noon": "noon",
58
- "pm": "PM",
59
- "pm-alt-variant": "pm"
60
- }
61
- }
62
- },
63
- "dateFormats": {
64
- "medium": "MMM d, y"
65
- },
66
- "timeFormats": {
67
- "medium": "h:mm:ss a",
68
- },
69
- "dateTimeFormats": {
70
- "medium": "{1}, {0}"
71
- }
72
- }
73
- }
74
- },
75
- "numbers": {
76
- "defaultNumberingSystem": "latn",
77
- "symbols-numberSystem-latn": {
78
- "group": ","
79
- },
80
- "decimalFormats-numberSystem-latn": {
81
- "standard": "#,##0.###"
82
- }
83
- }
84
- }
85
- },
86
- "supplemental": {
87
- "version": {
88
- "_cldrVersion": "25",
89
- "_number": "$Revision: 91 $"
90
- },
91
- "likelySubtags": {
92
- "en": "en-Latn-US",
93
- }
94
- }
95
- });
96
- ```
@@ -1,43 +0,0 @@
1
- ## Globalize.locale( [locale|cldr] )
2
-
3
- Set default locale, or get it if locale argument is omitted.
4
-
5
- Return the default [Cldr instance](https://github.com/rxaviers/cldrjs).
6
-
7
- An application that supports globalization and/or localization will need to have a way to determine the user's preference. Attempting to automatically determine the appropriate locale is useful, but it is good practice to always offer the user a choice, by whatever means.
8
-
9
- Whatever your mechanism, it is likely that you will have to correlate the user's preferences with the list of locale data supported in the app. This method allows you to select the best match given the locale data that you have included and to set the Globalize locale to the one which the user prefers.
10
-
11
- LanguageMatching TBD (CLDR's spec http://www.unicode.org/reports/tr35/#LanguageMatching).
12
-
13
- ### Parameters
14
-
15
- #### locale|cldr
16
-
17
- - The locale string, e.g., `"en"`, `"pt-BR"`, or `"zh-Hant-TW"`. Or,
18
- - The [Cldr instance](https://github.com/rxaviers/cldrjs), e.g., new `Cldr( "en" )`.
19
-
20
- ### Example
21
-
22
- Prior to using this function, you must load `cldr/supplemental/likelySubtags.json`. Read [CLDR content][] if you need more information.
23
-
24
- [CLDR content]: ../../../README.md#2-cldr-content
25
-
26
- ```javascript
27
- // Set "pt" as our default locale.
28
- Globalize.locale( "pt" );
29
-
30
- // Get default locale.
31
- Globalize.locale();
32
- // > {
33
- // attributes: {
34
- // "languageId": "pt",
35
- // "maxLanguageId": "pt_Latn_BR",
36
- // "language": "pt",
37
- // "script": "Latn",
38
- // "territory": "BR",
39
- // "region": "BR"
40
- // },
41
- // some more stuff...
42
- // }
43
- ```
@@ -1,196 +0,0 @@
1
- ## .currencyFormatter( currency [, options] ) ➜ function( value )
2
-
3
- Return a function that formats a `currency` according to the given `options` or locale's defaults.
4
-
5
- The returned function is invoked with one argument: the Number `value` to be formatted.
6
-
7
- ### Parameters
8
-
9
- #### currency
10
-
11
- 3-letter currency code as defined by ISO 4217, eg. `"USD"`.
12
-
13
- #### options.style
14
-
15
- Optional. String `"symbol"` (default), `"accounting"`, `"code"` or `"name"`. See [`.numberFormatter( [options] )`](../number/number-formatter.md) for more options.
16
-
17
- #### value
18
-
19
- Number to be formatted, eg. `9.99`.
20
-
21
- ### Example
22
-
23
- #### Static Formatter
24
-
25
- Prior to using any currency methods, you must load `cldr/main/{locale}/currencies.json`, `cldr/supplemental/currencyData.json`, and the CLDR content required by the number module. If using plural messages, you also must load the CLDR content required by the plural module. Read [CLDR content][] if you need more information.
26
-
27
- [CLDR content]: ../../../README.md#2-cldr-content
28
-
29
- #### Using the default options
30
-
31
- You can use the static method `Globalize.currencyFormatter()`, which uses the default locale.
32
-
33
- ```javascript
34
- var formatter;
35
-
36
- Globalize.locale( "en" );
37
- formatter = Globalize.currencyFormatter( "USD" );
38
-
39
- formatter( 9.99 );
40
- // > "$9.99"
41
- ```
42
-
43
- #### Instance Formatter
44
-
45
- You can use the instance method `.currencyFormatter()`, which uses the instance locale.
46
-
47
- ```javascript
48
- var deFormatter = Globalize( "de" ).currencyFormatter( "EUR" ),
49
- zhFormatter = Globalize( "zh" ).currencyFormatter( "EUR" );
50
-
51
- deFormatter( 9.99 );
52
- // > "9,99 €"
53
-
54
- zhFormatter( 9.99 );
55
- // > "€ 9.99"
56
-
57
- ```
58
-
59
- For comparison, follow the formatting output of different symbols in different locales.
60
-
61
- | 3-letter currency code | en (English) | de (German) | zh (Chinese) |
62
- | ---------------------------------- | ------------ | ----------- | ------------ |
63
- | `.currencyFormatter( "USD" )( 1 )` | `$1.00` | `1,00 $` | `US$ 1.00` |
64
- | `.currencyFormatter( "EUR" )( 1 )` | `€1.00` | `1,00 €` | `€ 1.00` |
65
- | `.currencyFormatter( "CNY" )( 1 )` | `CN¥1.00` | `1,00 CN¥` | `¥ 1.00` |
66
- | `.currencyFormatter( "JPY" )( 1 )` | `¥1` | `1 ¥` | `JP¥ 1` |
67
- | `.currencyFormatter( "GBP" )( 1 )` | `£1.00` | `1,00 £` | `£ 1.00` |
68
- | `.currencyFormatter( "BRL" )( 1 )` | `R$1.00` | `1,00 R$` | `R$ 1.00` |
69
-
70
- #### Using alternative `options.symbolForm`
71
-
72
- Using the narrow symbol form, the same symbols may be used for multiple currencies. Thus the symbol may be ambiguous, and should only be used where the context is clear.
73
-
74
- ```js
75
- Globalize( "en" ).currencyFormatter( "HKD" )( 1 );
76
- // > "HK$1.00"
77
-
78
- Globalize( "en" ).currencyFormatter( "HKD", { symbolForm: "narrow" } )( 1 );
79
- // > "$1.00"
80
- ```
81
-
82
- #### Configuring style
83
-
84
- For the accounting variation of the symbol format, use `style: "accounting"`.
85
-
86
- ```javascript
87
- var formatter = Globalize( "en" ).currencyFormatter( "USD", {
88
- style: "accounting"
89
- });
90
-
91
- formatter( -1 );
92
- // > "($1.00)"
93
- ```
94
-
95
- For plural messages, use `style: "name"`.
96
-
97
- ```javascript
98
- var formatter = Globalize( "en" ).currencyFormatter( "USD", {
99
- style: "name"
100
- });
101
-
102
- formatter( 0 );
103
- // > "0.00 US dollars"
104
-
105
- formatter( 1 );
106
- // > "1.00 US dollar"
107
- ```
108
-
109
- For comparison, follow the formatting output of different symbols in different locales using the plural messages `Globalize( locale ).currencyFormatter( currency, { style: "name" } )( 1 )`.
110
-
111
- | 3-letter currency code | en (English) | de (German) | zh (Chinese) |
112
- | ---------------------- | ----------------------------- | -------------------------------- | ------------ |
113
- | `USD` | `1.00 US dollar` | `1,00 US-Dollar` | `1.00美元` |
114
- | `EUR` | `1.00 euro` | `1,00 Euro` | `1.00欧元` |
115
- | `CNY` | `1.00 Chinese yuan` | `1,00 Chinesischer Yuan` | `1.00人民币` |
116
- | `JPY` | `1 Japanese yen` | `1 Japanischer Yen` | `1日元` |
117
- | `GBP` | `1.00 British pound sterling` | `1,00 Britisches Pfund Sterling` | `1.00英镑` |
118
- | `BRL` | `1.00 Brazilian real` | `1,00 Brasilianischer Real` | `1.00巴西雷亚尔` |
119
-
120
- For the international currency code, use `style: "code"`.
121
-
122
- ```javascript
123
- var formatter = Globalize( "en" ).currencyFormatter( "USD", {
124
- style: "code"
125
- });
126
-
127
- formatter( 9.99 );
128
- // > "9.99 USD"
129
- ```
130
-
131
- #### Configuring inherited number options
132
-
133
- Override the number of digits, grouping separators, rounding function or any other [`.numberFormatter()` options](../number/number-formatter.md).
134
-
135
- ```javascript
136
- var formatter;
137
-
138
- Globalize.locale( "en" );
139
- formatter = Globalize.currencyFormatter( "USD", {
140
- minimumFractionDigits: 0,
141
- style: "name"
142
- });
143
-
144
- formatter( 1 );
145
- // > "1 US dollar"
146
-
147
- formatter = Globalize.currencyFormatter( "USD", {
148
- round: "ceil"
149
- });
150
-
151
- formatter( 1.491 );
152
- // > "$1.50"
153
- ```
154
-
155
- #### Formatting Compact Currencies
156
-
157
- ```js
158
- var shortFormatter = Globalize( "en" ).currencyFormatter( "USD", {
159
- compact: "short"
160
- });
161
-
162
- var longFormatter = Globalize( "en" ).currencyFormatter( "USD", {
163
- compact: "long"
164
- });
165
-
166
- shortFormatter( 12830000000 );
167
- // > "$13B"
168
-
169
- longFormatter( 12830000000 );
170
- // > "$13 billion"
171
- ```
172
-
173
- The minimumSignificantDigits and maximumSignificantDigits options are specially useful to control the number of digits to display.
174
-
175
- ```js
176
- Globalize( "en" ).formatCurrency( 12830000000, "USD", {
177
- compact: "short",
178
- minimumSignificantDigits: 3,
179
- maximumSignificantDigits: 3
180
- });
181
- // > "$12.8B"
182
- ```
183
-
184
- #### Performance Suggestion
185
-
186
- For improved performance on iterations, first create the formatter. Then, reuse it on each loop.
187
-
188
- ```javascript
189
- var formatter = Globalize( "en" ).currencyFormatter( "USD" );
190
-
191
- renderInvoice({
192
- prices: prices.map(function( price ) {
193
- return formatter( price );
194
- })
195
- });
196
- ```
@@ -1,117 +0,0 @@
1
- ## .currencyToPartsFormatter( currency [, options] ) ➜ function( value )
2
-
3
- Return a function that formats a `currency` into parts tokens according to the given `options` or locale's defaults.
4
-
5
- The returned function is invoked with one argument: the Number `value` to be formatted.
6
-
7
- ### Parameters
8
-
9
- #### currency
10
-
11
- 3-letter currency code as defined by ISO 4217, eg. `"USD"`.
12
-
13
- #### options
14
-
15
- Please, see [.currencyFormatter() options](./currency-formatter.md#parameters).
16
-
17
- #### value
18
-
19
- Number to be formatted, eg. `9.99`.
20
-
21
- ### Returns
22
-
23
- An Array of objects containing the formatted currency in parts. The returned structure looks like this:
24
-
25
- ```js
26
- [
27
- { type: "day", value: "17" },
28
- { type: "weekday", value: "Monday" }
29
- ]
30
- ```
31
-
32
- Possible types are the following:
33
-
34
- - `currency`
35
-
36
- The currency string, such as the symbols `"$"` and `"€"` or the name `"Dollar"`, `"Euro"` depending on which style is used.
37
-
38
- Please, see [.numberToPartsFormatter()](../number/number-to-parts-formatter.md#returns) for details about the inherited number parts such as `decimal`, `fraction`, `group`, `infinity`, `integer`, `literal`, `minusSign`, `nan`, `plusSign`, `percentSign`, and `compact`.
39
-
40
- ### Example
41
-
42
- Prior to using any currency methods, you must load `cldr/main/{locale}/currencies.json`, `cldr/supplemental/currencyData.json`, and the CLDR content required by the number module. If using plural messages, you also must load the CLDR content required by the plural module. Read [CLDR content][] if you need more information.
43
-
44
- [CLDR content]: ../../../README.md#2-cldr-content
45
-
46
- #### Static Formatter
47
-
48
- #### Using the default options
49
-
50
- You can use the static method `Globalize.currencyToPartsFormatter()`, which uses the default locale.
51
-
52
- ```javascript
53
- var formatter;
54
-
55
- Globalize.locale( "en" );
56
- formatter = Globalize.currencyToPartsFormatter( "USD" );
57
-
58
- formatter( 9.99 );
59
- // > [
60
- // { "type": "currency", "value": "$" },
61
- // { "type": "integer", "value": "9" },
62
- // { "type": "decimal", "value": "." },
63
- // { "type": "fraction", "value": "99" }
64
- // ]
65
- ```
66
-
67
- #### Instance Formatter
68
-
69
- You can use the instance method `.currencyFormatter()`, which uses the instance locale.
70
-
71
- ```javascript
72
- var deFormatter = Globalize( "de" ).currencyToPartsFormatter( "EUR" ),
73
- zhFormatter = Globalize( "zh" ).currencyToPartsFormatter( "EUR" );
74
-
75
- deFormatter( 9.99 );
76
- // > [
77
- // { "type": "integer", "value": "9" },
78
- // { "type": "decimal", "value": "," },
79
- // { "type": "fraction", "value": "99" },
80
- // { "type": "literal", "value": " " },
81
- // { "type": "currency", "value": "€" }
82
- // ]
83
-
84
- zhFormatter( 9.99 );
85
- // > [
86
- // { "type": "currency", "value": "€" },
87
- // { "type": "integer", "value": "9" },
88
- // { "type": "decimal", "value": "." },
89
- // { "type": "fraction", "value": "99" }
90
- // ]
91
- ```
92
-
93
- The information is available separately and it can be formatted and concatenated again in a customized way. For example by using [`Array.prototype.map()`][], [arrow functions][], a [switch statement][], [template literals][], and [`Array.prototype.reduce()`][].
94
-
95
- [`Array.prototype.map()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map
96
- [arrow functions]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions
97
- [switch statement]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch
98
- [template literals]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
99
- [`Array.prototype.reduce()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce
100
-
101
- #### More Examples
102
-
103
- Please, see [.currencyFormatter() example](./currency-formatter.md#example) for additional examples such as using alternative `symbolForm`, configuring `style` (symbol, accounting, and name styles), and the inherited number options (e.g., compact numbers).
104
-
105
- #### Performance Suggestion
106
-
107
- For improved performance on iterations, first create the formatter. Then, reuse it on each loop.
108
-
109
- ```javascript
110
- var formatter = Globalize( "en" ).currencyToPartsFormatter( "USD" );
111
-
112
- renderInvoice({
113
- prices: prices.map(function( price ) {
114
- return formatter( price );
115
- })
116
- });
117
- ```
@@ -1,203 +0,0 @@
1
- ## .dateFormatter( [options] ) ➜ function( value )
2
-
3
- Return a function that formats a date according to the given `options`. The default formatting is numeric year, month, and day (i.e., `{ skeleton: "yMd" }`.
4
-
5
- The returned function is invoked with one argument: the Date instance `value` to be formatted.
6
-
7
- ### Parameters
8
-
9
- #### options.skeleton
10
-
11
- String value indicating a skeleton (see description above), eg. `{ skeleton: "GyMMMd" }`.
12
-
13
- Skeleton provides a more flexible formatting mechanism than the predefined list `full`, `long`, `medium`, or `short` represented by date, time, or datetime. Instead, they are an open-ended list of patterns containing only date field information, and in a canonical order. For a complete list of skeleton patterns [check the unicode CLDR documentation](http://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table).
14
-
15
- For example:
16
-
17
- | locale | `"GyMMMd"` skeleton |
18
- | ------ | ------------------------- |
19
- | *en* | `"Apr 9, 2014 AD"` |
20
- | *zh* | `"公元2014年4月9日"` |
21
- | *es* | `"9 abr. de 2014 d. C."` |
22
- | *ar* | `"٩ أبريل، ٢٠١٤ م"` |
23
- | *pt* | `"9 de abr de 2014 d.C."` |
24
-
25
- #### options.date
26
-
27
- One of the following String values: `full`, `long`, `medium`, or `short`, eg., `{ date: "full" }`.
28
-
29
- #### options.time
30
-
31
- One of the following String values: `full`, `long`, `medium`, or `short`, eg., `{ time: "full" }`.
32
-
33
- #### options.datetime
34
-
35
- One of the following String values: `full`, `long`, `medium`, or `short`, eg., `{ datetime: "full" }`.
36
-
37
- #### options.raw
38
-
39
- String value indicating a machine [raw pattern (anything in the "Sym." column)](http://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table) eg. `{ raw: "dd/mm" }`. Note this is NOT recommended for i18n in general. Use `skeleton` instead.
40
-
41
- #### options.timeZone
42
-
43
- String based on the time zone names of the [IANA time zone database](https://www.iana.org/time-zones), such as `"Asia/Shanghai"`, `"Asia/Kolkata"`, `"America/New_York"`.
44
-
45
- #### value
46
-
47
- Date instance to be formatted, eg. `new Date()`;
48
-
49
- ### Example
50
-
51
- Prior to using any date methods, you must load `cldr/main/{locale}/ca-gregorian.json`, `cldr/main/{locale}/timeZoneNames.json`, `cldr/supplemental/metaZones.json`, `cldr/supplemental/timeData.json`, `cldr/supplemental/weekData.json`, and the CLDR content required by the number module. Read [CLDR content][] if you need more information.
52
-
53
- [CLDR content]: ../../../README.md#2-cldr-content
54
-
55
- ```javascript
56
- var formatter;
57
-
58
- Globalize.locale( "en" );
59
- formatter = Globalize.dateFormatter();
60
-
61
- formatter( new Date( 2010, 10, 30, 17, 55 ) );
62
- // > "11/30/2010"
63
- ```
64
-
65
- You can use the instance method `.dateFormatter()`, which uses the instance locale.
66
-
67
- ```javascript
68
- var enFormatter = Globalize( "en" ).dateFormatter(),
69
- deFormatter = Globalize( "de" ).dateFormatter();
70
-
71
- enFormatter( new Date( 2010, 10, 30, 17, 55 ) );
72
- // > "11/30/2010"
73
-
74
- deFormatter( new Date( 2010, 10, 30, 17, 55 ) );
75
- // > "30.11.2010"
76
- ```
77
-
78
- #### Using short, medium, long, and full presets
79
-
80
- Use convenient presets for `date`, `time`, or `datetime`. Their possible values are: `short`, `medium`, `long`, and `full`.
81
-
82
- | `presetValue` | `Globalize( "en" ).dateFormatter( presetValue )( new Date( 2010, 10, 1, 17, 55 ) )` |
83
- | ------------------------ | ---------------------------------------- |
84
- | `{ date: "short" }` | `"11/1/10"` |
85
- | `{ date: "medium" }` | `"Nov 1, 2010"` |
86
- | `{ date: "long" }` | `"November 1, 2010"` |
87
- | `{ date: "full" }` | `"Monday, November 1, 2010"` |
88
- | `{ time: "short" }` | `"5:55 PM"` |
89
- | `{ time: "medium" }` | `"5:55:00 PM"` |
90
- | `{ time: "long" }` | `"5:55:00 PM PST"` |
91
- | `{ time: "full" }` | `"5:55:00 PM Pacific Standard Time"` |
92
- | `{ datetime: "short" }` | `"11/1/10, 5:55 PM"` |
93
- | `{ datetime: "medium" }` | `"Nov 1, 2010, 5:55:00 PM"` |
94
- | `{ datetime: "long" }` | `"November 1, 2010 at 5:55:00 PM PST"` |
95
- | `{ datetime: "full" }` | `"Monday, November 1, 2010 at 5:55:00 PM Pacific Standard Time"` |
96
-
97
- For comparison, follow the same formatter `{ datetime: "short" }` on different locales.
98
-
99
- | locale | `Globalize( locale ).dateFormatter({ datetime: "short" })( new Date( 2010, 10, 1, 17, 55 ) )` |
100
- | ---------------- | ---------------------------------------- |
101
- | *en* | `"11/1/10, 5:55 PM"` |
102
- | *en_GB* | `"01/11/2010 17:55"` |
103
- | *zh* | `"10/11/1 下午5:55"` |
104
- | *zh-u-nu-native* | `"一〇/一一/一 下午五:五五"` |
105
- | *es* | `"1/11/10 17:55"` |
106
- | *de* | `"01.11.10 17:55"` |
107
- | *pt* | `"01/11/10 17:55"` |
108
- | *ar* | `"١‏/١١‏/٢٠١٠ ٥،٥٥ م"` |
109
-
110
- #### Using open-ended skeletons
111
-
112
- Use open-ended skeletons for more flexibility (see its description [above](#parameters)). See some examples below.
113
-
114
- | `skeleton` | `Globalize( "en" ).dateFormatter( skeleton )( new Date( 2010, 10, 1, 17, 55 ) )` |
115
- | ---------------------------- | ---------------------------------------- |
116
- | `{ skeleton: "E" }` | `"Tue"` |
117
- | `{ skeleton: "EHm" }` | `"Tue 17:55"` |
118
- | `{ skeleton: "EHms" }` | `"Tue 17:55:00"` |
119
- | `{ skeleton: "Ed" }` | `"30 Tue"` |
120
- | `{ skeleton: "Ehm" }` | `"Tue 5:55 PM"` |
121
- | `{ skeleton: "Ehms" }` | `"Tue 5:55:00 PM"` |
122
- | `{ skeleton: "Gy" }` | `"2010 AD"` |
123
- | `{ skeleton: "GyMMM" }` | `"Nov 2010 AD"` |
124
- | `{ skeleton: "GyMMMEd" }` | `"Tue, Nov 30, 2010 AD"` |
125
- | `{ skeleton: "GyMMMd" }` | `"Nov 30, 2010 AD"` |
126
- | `{ skeleton: "H" }` | `"17"` |
127
- | `{ skeleton: "Hm" }` | `"17:55"` |
128
- | `{ skeleton: "Hms" }` | `"17:55:00"` |
129
- | `{ skeleton: "M" }` | `"11"` |
130
- | `{ skeleton: "MEd" }` | `"Tue, 11/30"` |
131
- | `{ skeleton: "MMM" }` | `"Nov"` |
132
- | `{ skeleton: "MMMEd" }` | `"Tue, Nov 30"` |
133
- | `{ skeleton: "MMMd" }` | `"Nov 30"` |
134
- | `{ skeleton: "Md" }` | `"11/30"` |
135
- | `{ skeleton: "d" }` | `"30"` |
136
- | `{ skeleton: "h" }` | `"5 PM"` |
137
- | `{ skeleton: "hm" }` | `"5:55 PM"` |
138
- | `{ skeleton: "hms" }` | `"5:55:00 PM"` |
139
- | `{ skeleton: "ms" }` | `"55:00"` |
140
- | `{ skeleton: "y" }` | `"2010"` |
141
- | `{ skeleton: "yM" }` | `"11/2010"` |
142
- | `{ skeleton: "yMEd" }` | `"Tue, 11/30/2010"` |
143
- | `{ skeleton: "yMMM" }` | `"Nov 2010"` |
144
- | `{ skeleton: "yMMMEd" }` | `"Tue, Nov 30, 2010"` |
145
- | `{ skeleton: "yMMMd" }` | `"Nov 30, 2010"` |
146
- | `{ skeleton: "yMd" }` | `"11/30/2010"` |
147
- | `{ skeleton: "yQQQ" }` | `"Q4 2010"` |
148
- | `{ skeleton: "yQQQQ" }` | `"4th quarter 2010"` |
149
- | `{ skeleton: "GyMMMEdhms" }` | `"Tue, Nov 30, 2010 AD, 5:55:00 PM"` |
150
- | `{ skeleton: "Ehms" }` | `"Tue 5:55:00 PM"` |
151
- | `{ skeleton: "yQQQHm" }` | `"Q4 2010, 17:55"` |
152
- | `{ skeleton: "MMMEdhm" }` | `"Tue, Nov 30, 5:55 PM"` |
153
- | `{ skeleton: "yMMMdhm" }` | `"Nov 30, 2010, 5:55 PM"` |
154
-
155
-
156
- ```javascript
157
- var globalize = Globalize( "en" ),
158
- date = new Date( 2010, 10, 30, 17, 55 ),
159
- monthDayFormatter = globalize.dateFormatter({ skeleton: "MMMd" }),
160
- hourMinuteSecondFormatter = globalize.dateFormatter({ skeleton: "Hms" });
161
-
162
- monthDayFormatter( date );
163
- // > "Nov 30"
164
-
165
- hourMinuteSecondFormatter( date );
166
- // > "17:55:00"
167
- ```
168
-
169
- #### Using time zones
170
-
171
- Using specific timeZones, i.e., using `options.timezone`. Note that prior to using it, you must load IANA time zone data.
172
-
173
- ```js
174
- Globalize.loadTimeZone( require( "iana-tz-data" ) );
175
- ```
176
-
177
- ```js
178
- Globalize.locale( "en" );
179
-
180
- Globalize.dateFormatter({ datetime: "medium", timeZone: "America/Los_Angeles" })( new Date() );
181
- // > "Nov 1, 2010, 12:55:00 PM"
182
-
183
- Globalize.dateFormatter({ datetime: "medium", timeZone: "America/Sao_Paulo" })( new Date() )
184
- // > "Nov 1, 2010, 5:55:00 PM"
185
-
186
- Globalize.dateFormatter({ datetime: "full", timeZone: "Europe/Berlin" })( new Date() )
187
- // > "Monday, November 1, 2010 at 8:55:00 PM Central European Standard Time"
188
- ```
189
-
190
- #### Note on performance
191
-
192
- For improved performance on iterations, first create the formatter. Then, reuse it on each loop.
193
-
194
- ```javascript
195
- // In an application, this array could have a few hundred entries
196
- var dates = [ new Date( 2010, 10, 30, 17, 55 ), new Date( 2015, 3, 18, 4, 25 ) ];
197
- var formatter = Globalize( "en" ).dateFormatter({ time: "short" });
198
-
199
- var formattedDates = dates.map(function( date ) {
200
- return formatter( date );
201
- });
202
- // > Array [ "5:55 PM", "4:25 AM" ]
203
- ```