Skip to content

Commit c1215d4

Browse files
committed
Update type definitions to match the code implementation
1 parent a2ea5b6 commit c1215d4

File tree

4 files changed

+52
-32
lines changed

4 files changed

+52
-32
lines changed

index.d.ts

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
1-
// Type definitions for moment-timezone.js 0.5
1+
// Type definitions for moment-timezone.js
22
// Project: http://momentjs.com/timezone/
33
// Definitions by: Michel Salib <https://github.com/michelsalib>
44
// Alan Brazil Lins <https://github.com/alanblins>
55
// Agustin Carrasco <https://github.com/asermax>
66
// Borys Kupar <https://github.com/borys-kupar>
77
// Anthony Rainer <https://github.com/pristinesource>
8-
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
9-
// Migrated here from DefinitelyTyped in release [email protected]
8+
// Original source: https://github.com/DefinitelyTyped/DefinitelyTyped
9+
// Migrated here from DefinitelyTyped in release [email protected],
10+
// then maintained by the Moment team
1011

1112
import moment = require('moment');
1213

1314
declare module 'moment' {
15+
/** Parsed / unpacked zone data. */
16+
interface UnpackedZone {
17+
name: string;
18+
abbrs: string[];
19+
untils: number[];
20+
offsets: number[];
21+
population?: number;
22+
}
23+
1424
interface MomentZone {
1525
name: string;
1626
abbrs: string[];
@@ -19,9 +29,13 @@ declare module 'moment' {
1929
population: number;
2030

2131
abbr(timestamp: number): string;
32+
/**
33+
* @deprecated use `.utcOffset()`
34+
*/
2235
offset(timestamp: number): number;
2336
utcOffset(timestamp: number): number;
2437
parse(timestamp: number): number;
38+
countries(): string[];
2539
}
2640

2741
interface MomentZoneOffset {
@@ -43,15 +57,21 @@ declare module 'moment' {
4357
(date: moment.Moment, timezone: string): moment.Moment;
4458
(date: any, timezone: string): moment.Moment;
4559

60+
version: string;
61+
dataVersion: string;
62+
moveInvalidForward: boolean;
63+
moveAmbiguousForward: boolean;
64+
4665
zone(timezone: string): MomentZone | null;
66+
Zone(packedZoneString?: string): MomentZone;
4767

4868
add(packedZoneString: string): void;
4969
add(packedZoneString: string[]): void;
5070

5171
link(packedLinkString: string): void;
5272
link(packedLinkString: string[]): void;
5373

54-
load(data: { version: string; links: string[]; zones: string[] }): void;
74+
load(data: { version: string; links: string[]; zones: string[]; countries?: string[] }): void;
5575

5676
names(): string[];
5777
zonesForCountry<T extends true>(country: string, with_offset: T): T extends true ? MomentZoneOffset[] : never;
@@ -60,8 +80,10 @@ declare module 'moment' {
6080
countries(): string[];
6181
guess(ignoreCache?: boolean): string;
6282

63-
setDefault(timezone?: string): Moment;
64-
dataVersion: string;
83+
setDefault(timezone?: string): typeof moment;
84+
85+
unpack(packedZoneString: string): UnpackedZone;
86+
unpackBase60(packedString: string): number;
6587
}
6688

6789
interface Moment {

moment-timezone-utils.d.ts

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,27 @@
1-
import moment = require('moment');
2-
import { MomentTimezone } from "./index";
1+
import moment = require('./index');
32

43
declare module 'moment' {
54

6-
/** Parsed / unpacked zone data. */
7-
interface UnpackedZone {
8-
/** The uniquely identifying name of the time zone. */
9-
name: string;
10-
/** zone abbreviations */
11-
abbrs: Array<string>;
12-
/** (measured in milliseconds) */
13-
untils: Array<number | null>;
14-
/** (measured in minutes) */
15-
offsets: Array<number>;
16-
}
17-
18-
/** Bundle of zone data and links for multiple timezones */
5+
/** Bundle of packed zone data and links for multiple timezones */
196
interface PackedZoneBundle {
207
version: string;
21-
zones: Array<string>;
22-
links: Array<string>;
8+
zones: string[];
9+
links: string[];
2310
}
2411

25-
/** Bundle of zone data and links for multiple timezones */
12+
/** Bundle of raw zone data and links for multiple timezones */
2613
interface UnpackedZoneBundle {
2714
version: string;
28-
zones: Array<UnpackedZone>;
29-
links: Array<string>;
15+
zones: UnpackedZone[];
16+
links: string[];
3017
}
31-
18+
19+
/** Bundle of timezones for a single country */
20+
interface UnpackedCountryData {
21+
name: string;
22+
zones: string[];
23+
}
24+
3225
/** extends MomentTimezone declared in index */
3326
interface MomentTimezone {
3427
/** Converts zone data in the unpacked format to the packed format. */
@@ -37,7 +30,11 @@ declare module 'moment' {
3730
/** Convert a base 10 number to a base 60 string. */
3831
packBase60(input: number, precision?: number): string;
3932

40-
/** Create links out of two zones that share data.
33+
/** Converts country data in the unpacked format to a packed format. */
34+
packCountry(unpacked: UnpackedCountryData): string;
35+
36+
/**
37+
* Create links out of two or more zones that share data.
4138
* @returns A new ZoneBundle with duplicate zone data replaced by links
4239
*/
4340
createLinks(unlinked: UnpackedZoneBundle): PackedZoneBundle;

typing-tests/moment-timezone-tests.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import moment = require('../index');
2-
import { UnpackedZone } from '../moment-timezone-utils';
32

43
const june = moment('2014-06-01T12:00:00Z');
54
june.tz('America/Los_Angeles').format('ha z');
@@ -87,7 +86,7 @@ moment.tz.load({
8786
version : '2014e'
8887
});
8988

90-
const unpacked: UnpackedZone = moment.tz.unpack('America/Los_Angeles|PST PDT|80 70|0101|1Lzm0 1zb0 Op0');
89+
const unpacked: moment.UnpackedZone = moment.tz.unpack('America/Los_Angeles|PST PDT|80 70|0101|1Lzm0 1zb0 Op0');
9190
const unpacked2: number = moment.tz.unpackBase60('1Lzm0');
9291

9392
const v1: string = moment.tz.version;

typing-tests/moment-timezone-utils-tests.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ const ZONE_A: moment.UnpackedZone = {
44
name : "Test/A",
55
abbrs : ["ABC", "DEF", "GHI"],
66
offsets : [10, 20, 30],
7-
untils : [-1000, 100, 200]
7+
untils : [-1000, 100, 200],
8+
population : 2000
89
};
910

1011
const ZONE_B = {
1112
name : "Test/B",
1213
abbrs : ["ABC", "DEF", "GHI"],
1314
offsets : [10, 20, 30],
14-
untils : [-1000, 100, 200]
15+
untils : [-1000, 100, 200],
16+
population : 0
1517
};
1618

1719
const ZONE_C = {

0 commit comments

Comments
 (0)