Skip to content

Commit 83784ed

Browse files
Merge pull request #1132 from moment/typescript-fixes
Fix and update all TypeScript definitions
2 parents fcec454 + f159a57 commit 83784ed

11 files changed

+120
-323
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import moment = require('../index');
2+
3+
export = moment;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import moment = require('../index');
2+
3+
export = moment;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import moment = require('../index');
2+
3+
export = moment;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import moment = require('../index');
2+
3+
export = moment;

index.d.ts

Lines changed: 29 additions & 12 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 moment-timezone@0.5.30
8+
// Original source: https://github.com/DefinitelyTyped/DefinitelyTyped
9+
// Migrated here from DefinitelyTyped in release moment-timezone@0.5.30,
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 {
@@ -32,26 +46,27 @@ declare module 'moment' {
3246
interface MomentTimezone {
3347
(): moment.Moment;
3448
(timezone: string): moment.Moment;
35-
(date: number, timezone: string): moment.Moment;
36-
(date: number[], timezone: string): moment.Moment;
37-
(date: string, timezone: string): moment.Moment;
49+
(date: moment.MomentInput, timezone: string): moment.Moment;
3850
(date: string, format: moment.MomentFormatSpecification, timezone: string): moment.Moment;
3951
(date: string, format: moment.MomentFormatSpecification, strict: boolean, timezone: string): moment.Moment;
4052
(date: string, format: moment.MomentFormatSpecification, language: string, timezone: string): moment.Moment;
4153
(date: string, format: moment.MomentFormatSpecification, language: string, strict: boolean, timezone: string): moment.Moment;
42-
(date: Date, timezone: string): moment.Moment;
43-
(date: moment.Moment, timezone: string): moment.Moment;
44-
(date: any, timezone: string): moment.Moment;
54+
55+
version: string;
56+
dataVersion: string;
57+
moveInvalidForward: boolean;
58+
moveAmbiguousForward: boolean;
4559

4660
zone(timezone: string): MomentZone | null;
61+
Zone(packedZoneString?: string): MomentZone;
4762

4863
add(packedZoneString: string): void;
4964
add(packedZoneString: string[]): void;
5065

5166
link(packedLinkString: string): void;
5267
link(packedLinkString: string[]): void;
5368

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

5671
names(): string[];
5772
zonesForCountry<T extends true>(country: string, with_offset: T): T extends true ? MomentZoneOffset[] : never;
@@ -60,8 +75,10 @@ declare module 'moment' {
6075
countries(): string[];
6176
guess(ignoreCache?: boolean): string;
6277

63-
setDefault(timezone?: string): Moment;
64-
dataVersion: string;
78+
setDefault(timezone?: string): typeof moment;
79+
80+
unpack(packedZoneString: string): UnpackedZone;
81+
unpackBase60(packedString: string): number;
6582
}
6683

6784
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;

moment-timezone.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import moment = require('./index');
2+
3+
export = moment;

tasks/builds.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ function staleDataWarning() {
1818

1919
module.exports = function (grunt) {
2020
grunt.registerMultiTask('build', 'Build minified versions with data included.', function () {
21-
var dest = 'builds/' + this.target + '.js',
22-
data = require('../data/unpacked/latest.json'),
23-
source = grunt.file.read('moment-timezone.js'),
24-
start = 0,
25-
end = 9999;
21+
var dest = 'builds/' + this.target + '.js',
22+
typesDest = 'builds/' + this.target + '.d.ts',
23+
data = require('../data/unpacked/latest.json'),
24+
source = grunt.file.read('moment-timezone.js'),
25+
typesSrc = grunt.file.read('moment-timezone.d.ts'),
26+
start = 0,
27+
end = 9999;
2628

2729
if (this.data && this.data[0]) {
2830
start = this.data[0];
@@ -45,5 +47,8 @@ module.exports = function (grunt) {
4547
source = source.replace('// INJECT DATA', data);
4648

4749
grunt.file.write(dest, source);
50+
51+
typesSrc = typesSrc.replace("'./index'", "'../index'");
52+
grunt.file.write(typesDest, typesSrc);
4853
});
4954
};

0 commit comments

Comments
 (0)