docs(API): 翻译 date_pipe

This commit is contained in:
Zhicheng Wang 2018-08-31 18:18:05 +08:00
parent 3961af4fea
commit b3991897d8
2 changed files with 137 additions and 55 deletions

View File

@ -13,7 +13,7 @@
[x] |router/Router | 4,049 | 1.26
[ ] |animations/animate | 3,817 | 1.19
[x] |common/NgClass | 3,715 | 1.15
[ ] |common/DatePipe | 3,576 | 1.11
[x] |common/DatePipe | 3,576 | 1.11
[ ] |forms/FormsModule | 3,381 | 1.05
[x] |core/Input | 3,354 | 1.04
[x] |core/EventEmitter | 3,202 | 0.99

View File

@ -17,10 +17,15 @@ import {invalidPipeArgumentError} from './invalid_pipe_argument_error';
*
* Formats a date value according to locale rules.
*
*
*
* Only the `en-US` locale data comes with Angular. To localize dates
* in another language, you must import the corresponding locale data.
* See the [I18n guide](guide/i18n#i18n-pipes) for more information.
*
* Angular `en-US`
* [I18n guide](guide/i18n#i18n-pipes)
*
* @see `formatDate()`
*
*
@ -30,97 +35,154 @@ import {invalidPipeArgumentError} from './invalid_pipe_argument_error';
* reformat the date on every change-detection cycle, treat the date as an immutable object
* and change the reference when the pipe needs to run again.
*
*
*
*
* ### Pre-defined format options
*
* ###
*
* Examples are given in `en-US` locale.
*
* `en-US`
*
* - `'short'`: equivalent to `'M/d/yy, h:mm a'` (`6/15/15, 9:03 AM`).
*
* `'short'`: `'M/d/yy, h:mm a'` (`6/15/15, 9:03 AM`).
*
* - `'medium'`: equivalent to `'MMM d, y, h:mm:ss a'` (`Jun 15, 2015, 9:03:01 AM`).
*
* `'medium'`: `'MMM d, y, h:mm:ss a'` (`Jun 15, 2015, 9:03:01 AM`).
*
* - `'long'`: equivalent to `'MMMM d, y, h:mm:ss a z'` (`June 15, 2015 at 9:03:01 AM
*
* `'long'`: `'MMMM d, y, h:mm:ss a z'` (`June 15, 2015 at 9:03:01 AM
*
* GMT+1`).
* - `'full'`: equivalent to `'EEEE, MMMM d, y, h:mm:ss a zzzz'` (`Monday, June 15, 2015 at
*
* `'full'`: `'EEEE, MMMM d, y, h:mm:ss a zzzz'` (`Monday, June 15, 2015 at
*
* 9:03:01 AM GMT+01:00`).
* - `'shortDate'`: equivalent to `'M/d/yy'` (`6/15/15`).
*
* `'shortDate'`: `'M/d/yy'` (`6/15/15`).
*
* - `'mediumDate'`: equivalent to `'MMM d, y'` (`Jun 15, 2015`).
*
* `'mediumDate'`: `'MMM d, y'` (`Jun 15, 2015`).
*
* - `'longDate'`: equivalent to `'MMMM d, y'` (`June 15, 2015`).
*
* `'longDate'`: `'MMMM d, y'` (`June 15, 2015`).
*
* - `'fullDate'`: equivalent to `'EEEE, MMMM d, y'` (`Monday, June 15, 2015`).
*
* `'fullDate'`: `'EEEE, MMMM d, y'` (`Monday, June 15, 2015`).
*
* - `'shortTime'`: equivalent to `'h:mm a'` (`9:03 AM`).
*
* `'shortTime'`: `'h:mm a'` (`9:03 AM`).
*
* - `'mediumTime'`: equivalent to `'h:mm:ss a'` (`9:03:01 AM`).
*
* `'mediumTime'`: `'h:mm:ss a'` (`9:03:01 AM`).
*
* - `'longTime'`: equivalent to `'h:mm:ss a z'` (`9:03:01 AM GMT+1`).
*
* `'longTime'`: `'h:mm:ss a z'` (`9:03:01 AM GMT+1`).
*
* - `'fullTime'`: equivalent to `'h:mm:ss a zzzz'` (`9:03:01 AM GMT+01:00`).
*
* `'fullTime'`: `'h:mm:ss a zzzz'` (`9:03:01 AM GMT+01:00`).
*
*
* ### Custom format options
*
* ###
*
* You can construct a format string using symbols to specify the components
* of a date-time value, as described in the following table.
* Format details depend on the locale.
* Fields marked with (*) are only available in the extra data set for the given locale.
*
* | Field type | Format | Description | Example Value |
* 使-
*
* `*`
*
* | <t>Field type</t><t></t> | <t>Format</t><t></t> | <t>Description</t><t></t> | <t>Example Value</t><t></t> |
* |--------------------|-------------|---------------------------------------------------------------|------------------------------------------------------------|
* | Era | G, GG & GGG | Abbreviated | AD |
* | | GGGG | Wide | Anno Domini |
* | | GGGGG | Narrow | A |
* | Year | y | Numeric: minimum digits | 2, 20, 201, 2017, 20173 |
* | | yy | Numeric: 2 digits + zero padded | 02, 20, 01, 17, 73 |
* | | yyy | Numeric: 3 digits + zero padded | 002, 020, 201, 2017, 20173 |
* | | yyyy | Numeric: 4 digits or more + zero padded | 0002, 0020, 0201, 2017, 20173 |
* | Month | M | Numeric: 1 digit | 9, 12 |
* | | MM | Numeric: 2 digits + zero padded | 09, 12 |
* | | MMM | Abbreviated | Sep |
* | | MMMM | Wide | September |
* | | MMMMM | Narrow | S |
* | Month standalone | L | Numeric: 1 digit | 9, 12 |
* | | LL | Numeric: 2 digits + zero padded | 09, 12 |
* | | LLL | Abbreviated | Sep |
* | | LLLL | Wide | September |
* | | LLLLL | Narrow | S |
* | Week of year | w | Numeric: minimum digits | 1... 53 |
* | | ww | Numeric: 2 digits + zero padded | 01... 53 |
* | Week of month | W | Numeric: 1 digit | 1... 5 |
* | Day of month | d | Numeric: minimum digits | 1 |
* | | dd | Numeric: 2 digits + zero padded | 01 |
* | Week day | E, EE & EEE | Abbreviated | Tue |
* | | EEEE | Wide | Tuesday |
* | | EEEEE | Narrow | T |
* | | EEEEEE | Short | Tu |
* | Period | a, aa & aaa | Abbreviated | am/pm or AM/PM |
* | | aaaa | Wide (fallback to `a` when missing) | ante meridiem/post meridiem |
* | | aaaaa | Narrow | a/p |
* | Period* | B, BB & BBB | Abbreviated | mid. |
* | | BBBB | Wide | am, pm, midnight, noon, morning, afternoon, evening, night |
* | | BBBBB | Narrow | md |
* | Period standalone* | b, bb & bbb | Abbreviated | mid. |
* | | bbbb | Wide | am, pm, midnight, noon, morning, afternoon, evening, night |
* | | bbbbb | Narrow | md |
* | Hour 1-12 | h | Numeric: minimum digits | 1, 12 |
* | | hh | Numeric: 2 digits + zero padded | 01, 12 |
* | Hour 0-23 | H | Numeric: minimum digits | 0, 23 |
* | | HH | Numeric: 2 digits + zero padded | 00, 23 |
* | Minute | m | Numeric: minimum digits | 8, 59 |
* | | mm | Numeric: 2 digits + zero padded | 08, 59 |
* | Second | s | Numeric: minimum digits | 0... 59 |
* | | ss | Numeric: 2 digits + zero padded | 00... 59 |
* | Fractional seconds | S | Numeric: 1 digit | 0... 9 |
* | | SS | Numeric: 2 digits + zero padded | 00... 99 |
* | | SSS | Numeric: 3 digits + zero padded (= milliseconds) | 000... 999 |
* | Zone | z, zz & zzz | Short specific non location format (fallback to O) | GMT-8 |
* | | zzzz | Long specific non location format (fallback to OOOO) | GMT-08:00 |
* | | Z, ZZ & ZZZ | ISO8601 basic format | -0800 |
* | | ZZZZ | Long localized GMT format | GMT-8:00 |
* | | ZZZZZ | ISO8601 extended format + Z indicator for offset 0 (= XXXXX) | -08:00 |
* | | O, OO & OOO | Short localized GMT format | GMT-8 |
* | | OOOO | Long localized GMT format | GMT-08:00 |
* | <t>Era</t><t></t> | G, GG & GGG | <t>Abbreviated</t><t></t>| AD |
* | | GGGG | <t>Wide</t><t></t>| Anno Domini |
* | | GGGGG | <t>Narrow</t><t></t>| A |
* | <t>Year</t><t></t> | y | <t>Numeric</t><t></t>: <t>minimum digits</t><t></t> | 2, 20, 201, 2017, 20173 |
* | | yy | <t>Numeric</t><t></t>: 2 <t>digits + zero padded</t><t> + 0 </t> | 02, 20, 01, 17, 73 |
* | | yyy | <t>Numeric</t><t></t>: 3 <t>digits + zero padded</t><t> + 0 </t> | 002, 020, 201, 2017, 20173 |
* | | yyyy | <t>Numeric</t><t></t>: 4 <t>digits or more + zero padded</t><t> + 0 </t> | 0002, 0020, 0201, 2017, 20173 |
* | <t>Month</t><t></t> | M | <t>Numeric</t><t></t>: <t>1 digit</t><t>1 </t> | 9, 12 |
* | | MM | <t>Numeric</t><t></t>: 2 <t>digits + zero padded</t><t> + 0 </t> | 09, 12 |
* | | MMM | <t>Abbreviated</t><t></t>| Sep |
* | | MMMM | <t>Wide</t><t></t>| September |
* | | MMMMM | <t>Narrow</t><t></t>| S |
* | <t>Month standalone</t><t></t> | L | <t>Numeric</t><t></t>: <t>1 digit</t><t>1 </t> | 9, 12 |
* | | LL | <t>Numeric</t><t></t>: 2 <t>digits + zero padded</t><t> + 0 </t> | 09, 12 |
* | | LLL | <t>Abbreviated</t><t></t>| Sep |
* | | LLLL | <t>Wide</t><t></t>| September |
* | | LLLLL | <t>Narrow</t><t></t>| S |
* | <t>Week of year</t><t></t> | w | <t>Numeric</t><t></t>: <t>minimum digits</t><t></t> | 1... 53 |
* | | ww | <t>Numeric</t><t></t>: 2 <t>digits + zero padded</t><t> + 0 </t> | 01... 53 |
* | <t>Week of month</t><t></t> | W | <t>Numeric</t><t></t>: <t>1 digit</t><t>1 </t> | 1... 5 |
* | <t>Day of month</t><t></t> | d | <t>Numeric</t><t></t>: <t>minimum digits</t><t></t> | 1 |
* | | dd | <t>Numeric</t><t></t>: 2 <t>digits + zero padded</t><t> + 0 </t> | 01 |
* | <t>Week day</t><t></t> | E, EE & EEE | <t>Abbreviated</t><t></t>| Tue |
* | | EEEE | <t>Wide</t><t></t>| Tuesday |
* | | EEEEE | <t>Narrow</t><t></t>| T |
* | | EEEEEE | <t>Short</t><t></t> | Tu |
* | <t>Period</t><t></t> | a, aa & aaa | <t>Abbreviated</t><t></t>| am/pm or AM/PM |
* | | aaaa | <t>Wide</t><t></t><t>(fallback to `a` when missing)</t><t>( `a`)</t>| ante meridiem/post meridiem |
* | | aaaaa | <t>Narrow</t><t></t>| a/p |
* | <t>Period*</t><t></t> | B, BB & BBB | <t>Abbreviated</t><t></t>| mid. |
* | | BBBB | <t>Wide</t><t></t>| am, pm, midnight, noon, morning, afternoon, evening, night |
* | | BBBBB | <t>Narrow</t><t></t>| md |
* | <t>Period standalone*</t><t></t> | b, bb & bbb | <t>Abbreviated</t><t></t>| mid. |
* | | bbbb | <t>Wide</t><t></t>| am, pm, midnight, noon, morning, afternoon, evening, night |
* | | bbbbb | <t>Narrow</t><t></t>| md |
* | <t>Hour 1-12</t><t>(1-12)</t> | h | <t>Numeric</t><t></t>: <t>minimum digits</t><t></t> | 1, 12 |
* | | hh | <t>Numeric</t><t></t>: 2 <t>digits + zero padded</t><t> + 0 </t> | 01, 12 |
* | <t>Hour 0-23</t><t>(0-23)</t> | H | <t>Numeric</t><t></t>: <t>minimum digits</t><t></t> | 0, 23 |
* | | HH | <t>Numeric</t><t></t>: 2 <t>digits + zero padded</t><t> + 0 </t> | 00, 23 |
* | <t>Minute</t><t></t> | m | <t>Numeric</t><t></t>: <t>minimum digits</t><t></t> | 8, 59 |
* | | mm | <t>Numeric</t><t></t>: 2 <t>digits + zero padded</t><t> + 0 </t> | 08, 59 |
* | <t>Second</t><t></t> | s | <t>Numeric</t><t></t>: <t>minimum digits</t><t></t> | 0... 59 |
* | | ss | <t>Numeric</t><t></t>: 2 <t>digits + zero padded</t><t> + 0 </t> | 00... 59 |
* | <t>Fractional seconds</t><t></t> | S | <t>Numeric</t><t></t>: <t>1 digit</t><t>1 </t> | 0... 9 |
* | | SS | <t>Numeric</t><t></t>: 2 <t>digits + zero padded</t><t> + 0 </t> | 00... 99 |
* | | SSS | <t>Numeric</t><t></t>: 3 <t>digits + zero padded</t><t> + 0 </t> (= <t>milliseconds</t><t></t>) | 000... 999 |
* | <t>Zone</t><t></t> | z, zz & zzz | <t>Short specific non location format (fallback to O)</t><t>0</t> | GMT-8 |
* | | zzzz | <t>Long specific non location format (fallback to OOOO)</t><t>0000</t> | GMT-08:00 |
* | | Z, ZZ & ZZZ | ISO8601 <t>basic format</t><t></t> | -0800 |
* | | ZZZZ | <t>Long localized GMT format</t><t> GMT </t> | GMT-8:00 |
* | | ZZZZZ | ISO8601 <t>extended format + Z indicator for offset 0</t><t> + 0 Z </t> (= XXXXX) | -08:00 |
* | | O, OO & OOO | <t>Short localized GMT format</t><t> GMT </t> | GMT-8 |
* | | OOOO | <t>Long localized GMT format</t><t> GMT </t> | GMT-08:00 |
*
* Note that timezone correction is not applied to an ISO string that has no time component, such as "2016-09-19"
*
* ISO字符串2016-09-19
*
* ### Format examples
*
* ###
*
* These examples transform a date into various formats,
* assuming that `dateObj` is a JavaScript `Date` object for
* year: 2015, month: 6, day: 15, hour: 21, minute: 43, second: 11,
* given in the local time for the `en-US` locale.
*
*
* `dateObj` JavaScript `Date` 2015 6 15 21 43 11
* 使 `en-US`
*
* ```
* {{ dateObj | date }} // output is 'Jun 15, 2015'
* {{ dateObj | date:'medium' }} // output is 'Jun 15, 2015, 9:43:11 PM'
@ -130,8 +192,12 @@ import {invalidPipeArgumentError} from './invalid_pipe_argument_error';
*
* ### Usage example
*
* ### 使
*
* The following component uses a date pipe to display the current date in different formats.
*
*
*
* ```
* @Component({
* selector: 'date-pipe',
@ -156,15 +222,31 @@ export class DatePipe implements PipeTransform {
/**
* @param value The date expression: a `Date` object, a number
* (milliseconds since UTC epoch), or an ISO string (https://www.w3.org/TR/NOTE-datetime).
*
* `Date` UTC ISO (https://www.w3.org/TR/NOTE-datetime)。
*
* @param format The date/time components to include, using predefined options or a
* custom format string.
*
* 使
*
* @param timezone A timezone offset (such as `'+0430'`), or a standard
* UTC/GMT or continental US timezone abbreviation. Default is
* the local system timezone of the end-user's machine.
*
* `'+0430'` UTC/GMT
*
* @param locale A locale code for the locale format rules to use.
* When not supplied, uses the value of `LOCALE_ID`, which is `en-US` by default.
* See [Setting your app locale](guide/i18n#setting-up-the-locale-of-your-app).
*
* 使
* 使 `LOCALE_ID` `en-US`
* [](guide/i18n#setting-up-the-locale-of-your-app)
*
* @returns A date string in the desired format.
*
*
*/
transform(value: any, format = 'mediumDate', timezone?: string, locale?: string): string|null {
if (value == null || value === '' || value !== value) return null;