docs(API): 翻译完了 formatDate

This commit is contained in:
Zhicheng Wang 2018-09-04 15:48:34 +08:00
parent 284e6a7319
commit 8dbe7ff025
2 changed files with 51 additions and 2 deletions

View File

@ -73,8 +73,8 @@
[x] | router/ActivatedRouteSnapshot | 0.22 [x] | router/ActivatedRouteSnapshot | 0.22
[x] | common/http | 0.21 [x] | common/http | 0.21
[x] | core/ChangeDetectorRef | 0.21 [x] | core/ChangeDetectorRef | 0.21
[ ] | router/NavigationStart | 0.21 [x] | router/NavigationStart | 0.21
[ ] | common/formatDate | 0.21 [x] | common/formatDate | 0.21
[ ] | core/ComponentFactoryResolver | 0.20 [ ] | core/ComponentFactoryResolver | 0.20
[ ] | forms/Form | 0.20 [ ] | forms/Form | 0.20
[ ] | common/http/HttpErrorResponse | 0.20 [ ] | common/http/HttpErrorResponse | 0.20

View File

@ -46,17 +46,36 @@ enum TranslationType {
* *
* Formats a date according to locale rules. * Formats a date according to locale rules.
* *
*
*
* Where: * Where:
*
*
*
* - `value` is a Date, a number (milliseconds since UTC epoch) or an ISO string * - `value` is a Date, a number (milliseconds since UTC epoch) or an ISO string
* (https://www.w3.org/TR/NOTE-datetime). * (https://www.w3.org/TR/NOTE-datetime).
*
* `value` UTC ISO (https://www.w3.org/TR/NOTE-datetime)。
*
* - `format` indicates which date/time components to include. See {@link DatePipe} for more * - `format` indicates which date/time components to include. See {@link DatePipe} for more
* details. * details.
*
* `format` / {@link DatePipe}
*
* - `locale` is a `string` defining the locale to use. * - `locale` is a `string` defining the locale to use.
*
* `locale` `string`使
*
* - `timezone` to be used for formatting. It understands UTC/GMT and the continental US time zone * - `timezone` to be used for formatting. It understands UTC/GMT and the continental US time zone
* abbreviations, but for general use, use a time zone offset (e.g. `'+0430'`). * abbreviations, but for general use, use a time zone offset (e.g. `'+0430'`).
* If not specified, host system settings are used. * If not specified, host system settings are used.
* *
* `timezone` UTC/GMT 使 `'+0430'`
* 使宿
*
* See {@link DatePipe} for more details. * See {@link DatePipe} for more details.
*
* {@link DatePipe}
*/ */
export function formatDate( export function formatDate(
value: string | number | Date, format: string, locale: string, timezone?: string): string { value: string | number | Date, format: string, locale: string, timezone?: string): string {
@ -200,6 +219,9 @@ function formatFractionalSeconds(milliseconds: number, digits: number): string {
/** /**
* Returns a date formatter that transforms a date into its locale digit representation * Returns a date formatter that transforms a date into its locale digit representation
*
*
*
*/ */
function dateGetter( function dateGetter(
name: DateType, size: number, offset: number = 0, trim = false, name: DateType, size: number, offset: number = 0, trim = false,
@ -248,6 +270,9 @@ function getDatePart(part: DateType, date: Date): number {
/** /**
* Returns a date formatter that transforms a date into its locale string representation * Returns a date formatter that transforms a date into its locale string representation
*
*
*
*/ */
function dateStrGetter( function dateStrGetter(
name: TranslationType, width: TranslationWidth, form: FormStyle = FormStyle.Format, name: TranslationType, width: TranslationWidth, form: FormStyle = FormStyle.Format,
@ -259,6 +284,8 @@ function dateStrGetter(
/** /**
* Returns the locale translation of a date for a given form, type and width * Returns the locale translation of a date for a given form, type and width
*
*
*/ */
function getDateTranslation( function getDateTranslation(
date: Date, locale: string, name: TranslationType, width: TranslationWidth, form: FormStyle, date: Date, locale: string, name: TranslationType, width: TranslationWidth, form: FormStyle,
@ -314,6 +341,10 @@ function getDateTranslation(
* Returns a date formatter that transforms a date and an offset into a timezone with ISO8601 or * Returns a date formatter that transforms a date and an offset into a timezone with ISO8601 or
* GMT format depending on the width (eg: short = +0430, short:GMT = GMT+4, long = GMT+04:30, * GMT format depending on the width (eg: short = +0430, short:GMT = GMT+4, long = GMT+04:30,
* extended = +04:30) * extended = +04:30)
*
* ISO8601 GMT
* short = +0430, short:GMT = GMT+4, long = GMT+04:30,
* extended = +04:30
*/ */
function timeZoneGetter(width: ZoneWidth): DateFormatter { function timeZoneGetter(width: ZoneWidth): DateFormatter {
return function(date: Date, locale: string, offset: number) { return function(date: Date, locale: string, offset: number) {
@ -640,14 +671,29 @@ function convertTimezoneToLocal(date: Date, timezone: string, reverse: boolean):
/** /**
* Converts a value to date. * Converts a value to date.
* *
*
*
* Supported input formats: * Supported input formats:
*
*
*
* - `Date` * - `Date`
* - number: timestamp * - number: timestamp
*
*
*
* - string: numeric (e.g. "1234"), ISO and date strings in a format supported by * - string: numeric (e.g. "1234"), ISO and date strings in a format supported by
* [Date.parse()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse). * [Date.parse()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse).
* Note: ISO strings without time return a date without timeoffset. * Note: ISO strings without time return a date without timeoffset.
* *
* "1234"ISO [Date.parse()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse)
*
* ISO
*
* Throws if unable to convert to a date. * Throws if unable to convert to a date.
*
*
*
*/ */
export function toDate(value: string | number | Date): Date { export function toDate(value: string | number | Date): Date {
if (isDate(value)) { if (isDate(value)) {
@ -696,6 +742,9 @@ export function toDate(value: string | number | Date): Date {
/** /**
* Converts a date in ISO8601 to a Date. * Converts a date in ISO8601 to a Date.
* Used instead of `Date.parse` because of browser discrepancies. * Used instead of `Date.parse` because of browser discrepancies.
*
* ISO8601 `Date`
* 使 `Date.parse`
*/ */
export function isoStringToDate(match: RegExpMatchArray): Date { export function isoStringToDate(match: RegExpMatchArray): Date {
const date = new Date(0); const date = new Date(0);