Skip to content

Commit a2ea5b6

Browse files
committed
Update typing tests to include missing use cases
`moment-tests.ts` wasn't being included in the `typing-tests` project, so it wasn't being tested at all. Any unique tests it contained have been migrated to the other files.
1 parent fcec454 commit a2ea5b6

3 files changed

Lines changed: 44 additions & 282 deletions

File tree

typing-tests/moment-tests.ts

Lines changed: 0 additions & 260 deletions
This file was deleted.

typing-tests/moment-timezone-tests.ts

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

34
const june = moment('2014-06-01T12:00:00Z');
45
june.tz('America/Los_Angeles').format('ha z');
@@ -10,6 +11,10 @@ const d = moment.tz('May 12th 2014 8PM', 'MMM Do YYYY hA', true, 'America/Toront
1011

1112
a.tz();
1213

14+
const name: string = moment().tz();
15+
const converted: moment.Moment = moment().tz('America/Los_Angeles');
16+
moment().tz('America/Los_Angeles', true);
17+
1318
const num = 1367337600000;
1419
const arr = [2013, 5, 1];
1520
const str = '2013-12-01';
@@ -51,15 +56,19 @@ moment.tz(obj, 'America/Los_Angeles');
5156

5257
const zone1: moment.MomentZone | null = moment.tz.zone('America/Los_Angeles');
5358
if (zone1 != null) {
54-
zone1.abbr(1403465838805);
55-
zone1.utcOffset(1403465838805);
59+
zone1.abbr(1403465838805) === 'PDT';
60+
zone1.offset(1403465838805) === 420; // deprecated
61+
zone1.utcOffset(1403465838805) === 420;
5662
}
57-
5863
const zone2: moment.MomentZone | null = moment.tz.zone('America/New_York');
5964
if (zone2 != null) {
60-
zone2.parse(Date.UTC(2012, 2, 19, 8, 30)); // 240
65+
zone2.parse(Date.UTC(2012, 2, 19, 8, 30)) === 240;
66+
const zoneCountries: string[] = zone2.countries();
6167
}
6268

69+
moment.tz.Zone();
70+
const zone3: moment.MomentZone = moment.tz.Zone('America/Los_Angeles|PST PDT|80 70|0101|1Lzm0 1zb0 Op0');
71+
6372
moment.tz.add('America/Los_Angeles|PST PDT|80 70|0101|1Lzm0 1zb0 Op0');
6473
moment.tz.add([
6574
'America/Los_Angeles|PST PDT|80 70|0101|1Lzm0 1zb0 Op0',
@@ -78,26 +87,26 @@ moment.tz.load({
7887
version : '2014e'
7988
});
8089

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

83-
moment.tz.setDefault('America/Los_Angeles');
93+
const v1: string = moment.tz.version;
94+
const v2: string = moment.tz.dataVersion;
8495

85-
moment.tz.setDefault();
96+
const names: string[] = moment.tz.names();
8697

87-
moment.tz.guess();
98+
const def1: typeof moment = moment.tz.setDefault('America/Los_Angeles');
99+
const def2: typeof moment = moment.tz.setDefault();
88100

89-
moment.tz.guess(true);
101+
const guess1: string = moment.tz.guess();
102+
const guess2: string = moment.tz.guess(true);
90103

91104
const zoneAbbr: string = moment.tz('America/Los_Angeles').zoneAbbr();
92-
93105
const zoneName: string = moment.tz('America/Los_Angeles').zoneName();
94-
95-
const zoneType: string | undefined = moment.tz('2013-11-18 11:55').tz();
106+
const zoneId: string | undefined = moment.tz('2013-11-18 11:55').tz();
96107

97108
const zones1: string[] = moment.tz.zonesForCountry('US');
98-
99109
const zones2: moment.MomentZoneOffset[] = moment.tz.zonesForCountry('CN', true);
100-
101110
const zones3: string[] = moment.tz.zonesForCountry('GB', false);
102111

103112
const countries: string[] = moment.tz.countries();
Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,43 @@
11
import moment = require('../moment-timezone-utils');
22

3-
var ZONE_A = {
4-
name : "Zone/A",
3+
const ZONE_A: moment.UnpackedZone = {
4+
name : "Test/A",
55
abbrs : ["ABC", "DEF", "GHI"],
66
offsets : [10, 20, 30],
77
untils : [-1000, 100, 200]
88
};
99

10-
var ZONE_B = {
11-
name : "Zone/B",
10+
const ZONE_B = {
11+
name : "Test/B",
1212
abbrs : ["ABC", "DEF", "GHI"],
1313
offsets : [10, 20, 30],
1414
untils : [-1000, 100, 200]
1515
};
1616

17-
var ZONE_C = {
18-
name : "Zone/C",
17+
const ZONE_C = {
18+
name : "Test/C",
1919
abbrs : ["ZYX", "WVU"],
2020
offsets : [20, 30],
2121
untils : [-3000, 900]
2222
};
2323

24-
moment.tz.createLinks({
24+
const unpackedBundle: moment.UnpackedZoneBundle = {
2525
zones : [ZONE_A, ZONE_B, ZONE_C],
2626
links : ["Test/A|Test/B", "Test/A|Test/C"],
27-
version : '2014abcretain'
27+
version : '2025test'
28+
}
29+
30+
const packedZone: string = moment.tz.pack(ZONE_A);
31+
const packedNum: string = moment.tz.packBase60(12345678);
32+
33+
const packedBundle: moment.PackedZoneBundle = moment.tz.createLinks(unpackedBundle);
34+
const packedCountry: string = moment.tz.packCountry({
35+
name: 'PG',
36+
zones: ['Pacific/Port_Moresby', 'Pacific/Bougainville']
2837
});
2938

39+
const filtered1: moment.UnpackedZone = moment.tz.filterYears(ZONE_A, 2025);
40+
const filtered2: moment.UnpackedZone = moment.tz.filterYears(ZONE_A, 1970, 2038);
3041

42+
const all1: moment.PackedZoneBundle = moment.tz.filterLinkPack(unpackedBundle, 2025);
43+
const all2: moment.PackedZoneBundle = moment.tz.filterLinkPack(unpackedBundle, 1970, 2038);

0 commit comments

Comments
 (0)