From 289e3578278791139800b4cd8945a6e9fe513fae Mon Sep 17 00:00:00 2001 From: Michel Salib Date: Mon, 1 Dec 2014 17:50:27 +0100 Subject: [PATCH 1/3] Add moment-timezone --- moment-timezone/moment-timezone-tests.ts | 42 ++++++++++++++++++ moment-timezone/moment-timezone.d.ts | 54 ++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 moment-timezone/moment-timezone-tests.ts create mode 100644 moment-timezone/moment-timezone.d.ts diff --git a/moment-timezone/moment-timezone-tests.ts b/moment-timezone/moment-timezone-tests.ts new file mode 100644 index 0000000000..6ee7a78dd7 --- /dev/null +++ b/moment-timezone/moment-timezone-tests.ts @@ -0,0 +1,42 @@ +/// + +var june = moment("2014-06-01T12:00:00Z"); +june.tz('America/Los_Angeles').format('ha z'); + +var a = moment.tz("2013-11-18 11:55", "America/Toronto"); +var b = moment.tz("May 12th 2014 8PM", "MMM Do YYYY hA", "America/Toronto"); +var c = moment.tz(1403454068850, "America/Toronto"); + +var arr = [2013, 5, 1], + str = "2013-12-01", + obj = { year : 2013, month : 5, day : 1 }; + +moment.tz(arr, "America/Los_Angeles"); +moment.tz(str, "America/Los_Angeles"); +moment.tz(obj, "America/Los_Angeles"); + +moment.tz.zone('America/Los_Angeles').abbr(1403465838805); +moment.tz.zone('America/Los_Angeles').offset(1403465838805); + +var zone = moment.tz.zone('America/New_York'); +zone.parse(Date.UTC(2012, 2, 19, 8, 30)); // 240 + +moment.tz.add('America/Los_Angeles|PST PDT|80 70|0101|1Lzm0 1zb0 Op0'); +moment.tz.add([ + 'America/Los_Angeles|PST PDT|80 70|0101|1Lzm0 1zb0 Op0', + 'America/New_York|EST EDT|50 40|0101|1Lz50 1zb0 Op0' +]); + +moment.tz.link('America/Los_Angeles|US/Pacific'); +moment.tz.link([ + 'America/Los_Angeles|US/Pacific', + 'America/New_York|US/Eastern' +]); + +moment.tz.load({ + zones : [], + links : [], + version : '2014e' +}); + +moment.tz.names(); diff --git a/moment-timezone/moment-timezone.d.ts b/moment-timezone/moment-timezone.d.ts new file mode 100644 index 0000000000..167df9a7cd --- /dev/null +++ b/moment-timezone/moment-timezone.d.ts @@ -0,0 +1,54 @@ +// Type definitions for moment-timezone.js 0.2.5 +// Project: http://momentjs.com/timezone/ +// Definitions by: Michel Salib +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +interface Moment { + tz(timezone: string): Moment; +} + +interface Zone { + name: string; + abbrs: string[]; + untils: number[]; + offsets: number[]; + + abbr(timestamp: number): string; + offset(timestamp: number): number; + parse(timestamp: number): number +} + +interface MomentTimezone { + (date: number, timezone: string): Moment; + (date: number[], timezone: string): Moment; + (date: string, format: string, timezone: string): Moment; + (date: Date, timezone: string): Moment; + (date: Moment, timezone: string): Moment; + (date: Object, timezone: string): Moment; + + zone(timezone: string): Zone; + + add(packedZoneString: string): void; + add(packedZoneString: string[]): void; + + link(packedLinkString: string): void; + link(packedLinkString: string[]): void; + + load(data: { + version: string; + links: string[]; + zones: string[]; + }): void; + + names(): string[]; +} + +interface MomentStatic { + tz: MomentTimezone; +} + +declare module 'moment-timezone' { + +} From be1c64f42405e24a822d6b07e2520ea670434625 Mon Sep 17 00:00:00 2001 From: Michel Salib Date: Mon, 1 Dec 2014 17:52:09 +0100 Subject: [PATCH 2/3] Rename class in order to avoid name collisions. --- moment-timezone/moment-timezone.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/moment-timezone/moment-timezone.d.ts b/moment-timezone/moment-timezone.d.ts index 167df9a7cd..785aeb047e 100644 --- a/moment-timezone/moment-timezone.d.ts +++ b/moment-timezone/moment-timezone.d.ts @@ -9,7 +9,7 @@ interface Moment { tz(timezone: string): Moment; } -interface Zone { +interface MomentZone { name: string; abbrs: string[]; untils: number[]; @@ -28,7 +28,7 @@ interface MomentTimezone { (date: Moment, timezone: string): Moment; (date: Object, timezone: string): Moment; - zone(timezone: string): Zone; + zone(timezone: string): MomentZone; add(packedZoneString: string): void; add(packedZoneString: string[]): void; From 3ce44dcc58e583980447f89ffb5b531973acf50f Mon Sep 17 00:00:00 2001 From: Michel Salib Date: Tue, 2 Dec 2014 14:04:06 +0100 Subject: [PATCH 3/3] Fix moment-timezone export/import --- moment-timezone/moment-timezone-tests.ts | 2 ++ moment-timezone/moment-timezone.d.ts | 2 ++ 2 files changed, 4 insertions(+) diff --git a/moment-timezone/moment-timezone-tests.ts b/moment-timezone/moment-timezone-tests.ts index 6ee7a78dd7..f6a754c6e7 100644 --- a/moment-timezone/moment-timezone-tests.ts +++ b/moment-timezone/moment-timezone-tests.ts @@ -1,5 +1,7 @@ /// +import moment = require('moment-timezone'); + var june = moment("2014-06-01T12:00:00Z"); june.tz('America/Los_Angeles').format('ha z'); diff --git a/moment-timezone/moment-timezone.d.ts b/moment-timezone/moment-timezone.d.ts index 785aeb047e..9553faa3ad 100644 --- a/moment-timezone/moment-timezone.d.ts +++ b/moment-timezone/moment-timezone.d.ts @@ -50,5 +50,7 @@ interface MomentStatic { } declare module 'moment-timezone' { + var _tmp: MomentStatic; + export = _tmp; }