From e16f61614562b34291d2490aab04a06aba233b73 Mon Sep 17 00:00:00 2001 From: balrob Date: Mon, 16 Jun 2014 18:02:05 +1200 Subject: [PATCH 1/2] Add test files & correct header Add test files & correct header for date.format.d.ts --- date.format.js/date.format-tests.ts | 8 ++++ date.format.js/date.format.d.ts | 59 ++++++++++++++++++++++++----- 2 files changed, 58 insertions(+), 9 deletions(-) create mode 100644 date.format.js/date.format-tests.ts diff --git a/date.format.js/date.format-tests.ts b/date.format.js/date.format-tests.ts new file mode 100644 index 0000000000..b14e7efe0b --- /dev/null +++ b/date.format.js/date.format-tests.ts @@ -0,0 +1,8 @@ +/// + +var now : string = dateFormat(); +var nowFullDate : string = dateFormat( dateFormat.masks.fullDate ); + +var then : Date = new Date( 2014, 1, 1 ); +var thenDefaultFormat : string = then.format(); +var thenCustomFormat : string = then.format('yyyy/m/d HH:MM'); diff --git a/date.format.js/date.format.d.ts b/date.format.js/date.format.d.ts index 249926eae6..d40917644a 100644 --- a/date.format.js/date.format.d.ts +++ b/date.format.js/date.format.d.ts @@ -1,6 +1,10 @@ -/****************************************************************************** - Portions Copyright (c) Microsoft Corporation. All rights reserved. +// Type definitions for Date Format 1.2.3 +// Project: http://blog.stevenlevithan.com/archives/date-time-format +// Definitions by: Rob Stutton +// Definitions: https://github.com/borisyankov/DefinitelyTyped +/* **************************************************************************** + Portions Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 @@ -14,9 +18,6 @@ and limitations under the License. ***************************************************************************** */ -// Typing for the date.format.js from Steven Levithan -// reproduces "Date" and adds format() - seemed to be the only way ... - /** Enables basic storage and retrieval of dates and times. */ interface Date { /** Returns a string representation of a date. The format of the string depends on the locale. */ @@ -169,11 +170,16 @@ interface Date { toISOString(): string; /** Used by the JSON.stringify method to enable the transformation of an object's data for JavaScript Object Notation (JSON) serialization. */ toJSON(key?: any): string; - - format(mask: string, utc?: boolean) : string; + /** + * This is a convenience addition to the Date prototype + * Returns a formatted version of the date. + * The mask defaults to dateFormat.masks.default. + * @param {string=} mask + * @param {boolean=} utc + */ + format(mask?: string, utc?: boolean) : string; } - declare var Date: { new (): Date; new (value: number): Date; @@ -200,4 +206,39 @@ declare var Date: { now(): number; }; -declare function dateFormat(date?: any, mask?: string, utc?: boolean ) : string; +// Some common format strings +interface DateFormatMasks { + "default": string; + shortDate: string; + mediumDate: string; + longDate: string; + fullDate: string; + shortTime: string; + mediumTime: string; + longTime: string; + isoDate: string; + isoTime: string; + isoDateTime: string; + isoUtcDateTime: string; +} + +// Internationalization strings +interface DateFormatI18n { + dayNames: string[]; + monthNames: string[]; +} + +/** + * Accepts a date, a mask, or a date and a mask. + * Returns a formatted version of the given date. + * The date defaults to the current date/time. + * The mask defaults to dateFormat.masks.default. + * @param {Date=} date + * @param {string=} mask + * @param {boolean=} utc + */ +declare var dateFormat: { + (date?: any, mask?: string, utc?: boolean ): string; + masks : DateFormatMasks; + i18n : DateFormatI18n; +}; From 8a699244b3fe4f693065b62649366aa6af833b31 Mon Sep 17 00:00:00 2001 From: balrob Date: Tue, 17 Jun 2014 11:12:07 +1200 Subject: [PATCH 2/2] Minor update to comment - to allow a new commit --- date.format.js/date.format-tests.ts | 2 ++ date.format.js/date.format.d.ts | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/date.format.js/date.format-tests.ts b/date.format.js/date.format-tests.ts index b14e7efe0b..d06e78cb7a 100644 --- a/date.format.js/date.format-tests.ts +++ b/date.format.js/date.format-tests.ts @@ -1,8 +1,10 @@ /// +// test dateFormat var now : string = dateFormat(); var nowFullDate : string = dateFormat( dateFormat.masks.fullDate ); +// test format() (on the prototype of Date) var then : Date = new Date( 2014, 1, 1 ); var thenDefaultFormat : string = then.format(); var thenCustomFormat : string = then.format('yyyy/m/d HH:MM'); diff --git a/date.format.js/date.format.d.ts b/date.format.js/date.format.d.ts index d40917644a..6e4ef4ea68 100644 --- a/date.format.js/date.format.d.ts +++ b/date.format.js/date.format.d.ts @@ -3,7 +3,7 @@ // Definitions by: Rob Stutton // Definitions: https://github.com/borisyankov/DefinitelyTyped -/* **************************************************************************** +/***************************************************************************** Portions Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the