|
| 1 | +import * as moment from 'moment'; |
| 2 | + |
| 3 | +// require('moment-timezone') === require('moment') |
| 4 | +export = moment; |
| 5 | + |
| 6 | +declare module 'moment' { |
| 7 | + interface Moment { |
| 8 | + /** Set the timezone and update the offset */ |
| 9 | + tz(zone: string): Moment; |
| 10 | + /** Return the timezone name or undefined if a zone has not yet been set */ |
| 11 | + tz(): string | undefined; |
| 12 | + |
| 13 | + /** Get the zone abbreviation. This is what moment.js uses when formatting the z token. */ |
| 14 | + zoneAbbr(): string; |
| 15 | + |
| 16 | + /** Get the zone long form name. This is what moment.js uses when formatting the zz token. */ |
| 17 | + zoneName(): string; |
| 18 | + } |
| 19 | + |
| 20 | + // Match normal moment constructor but with an extra timezone argument |
| 21 | + // Here's a copy-paste of the normal moment constructor's signature, from https://github.com/moment/moment/blob/develop/moment.d.ts#L1-L2 |
| 22 | + // declare function moment(inp?: moment.MomentInput, format?: moment.MomentFormatSpecification, strict?: boolean): moment.Moment; |
| 23 | + // declare function moment(inp?: moment.MomentInput, format?: moment.MomentFormatSpecification, language?: string, strict?: boolean): moment.Moment; |
| 24 | + |
| 25 | + // Should be sorted from tightest to loosest. TypeScript picks the first signature that matches, going top to bottom. |
| 26 | + |
| 27 | + /** create a moment with a time zone */ |
| 28 | + function tz(inp: MomentInput, format: MomentFormatSpecification, language: string, strict: boolean, zone: string): Moment; |
| 29 | + /** create a moment with a time zone */ |
| 30 | + function tz(inp: MomentInput, format: MomentFormatSpecification, language: string, zone: string): Moment; |
| 31 | + /** create a moment with a time zone */ |
| 32 | + function tz(inp: MomentInput, format: MomentFormatSpecification, strict: boolean, zone: string): Moment; |
| 33 | + /** create a moment with a time zone */ |
| 34 | + function tz(inp: MomentInput, format: MomentFormatSpecification, zone: string): Moment; |
| 35 | + /** create a moment with a time zone */ |
| 36 | + function tz(inp: MomentInput, zone: string): Moment; |
| 37 | + /** create a moment with a time zone */ |
| 38 | + function tz(zone?: string): Moment; |
| 39 | + |
| 40 | + namespace tz { |
| 41 | + /** Version of moment-timezone */ |
| 42 | + const version: string; |
| 43 | + |
| 44 | + /** |
| 45 | + * Change the default timezone of newly created Moment instances. |
| 46 | + * By default new instances are created in the local timezone. |
| 47 | + */ |
| 48 | + function setDefault(zone: string): typeof moment; |
| 49 | + |
| 50 | + /** Reset the default timezone to local. */ |
| 51 | + function setDefault(): typeof moment; |
| 52 | + |
| 53 | + /** |
| 54 | + * Retrieve or guess the user's timezone. Uses the browser's Internationalization API if available. |
| 55 | + * Otherwise, guesses by sampling offsets from different points in time and comparing them to available zone data. |
| 56 | + */ |
| 57 | + function guess(): string; |
| 58 | + |
| 59 | + interface Zone extends UnpackedZone {} |
| 60 | + class Zone { |
| 61 | + /** Get the abbreviation for a given timestamp from a Zone. */ |
| 62 | + abbr(timestamp: number): string; |
| 63 | + |
| 64 | + /** Get the offset for a given timestamp from a Zone. */ |
| 65 | + offset(timestamp: number): number; |
| 66 | + |
| 67 | + /** Parse an offset for a timestamp constructed from Date.UTC in that zone. */ |
| 68 | + parse(timestamp: number): number; |
| 69 | + } |
| 70 | + |
| 71 | + /** Return a timezone by name or null if timezone by that name is not loaded. */ |
| 72 | + function zone(name: string): Zone | null; |
| 73 | + |
| 74 | + /** Add zone data for a timezone. */ |
| 75 | + function add(packedZone: string): void; |
| 76 | + /** Add zone data for multiple timezones. */ |
| 77 | + function add(packedZones: Array<string>): void; |
| 78 | + |
| 79 | + /** Link two zone names to the same data */ |
| 80 | + function link(packedLink: string): void; |
| 81 | + /** Add multiple links at once */ |
| 82 | + function link(packedLinks: Array<string>): void; |
| 83 | + |
| 84 | + /** load a bundle of zone data and links */ |
| 85 | + function load(bundle: PackedZoneBundle): void; |
| 86 | + |
| 87 | + /** get a list of all available time zone names */ |
| 88 | + function names(): Array<string>; |
| 89 | + |
| 90 | + /** Convert a packed string to an unpacked zone data object */ |
| 91 | + function unpack(packedZone: string): UnpackedZone; |
| 92 | + /** Convert a base 60 string to a base 10 number. */ |
| 93 | + function unpackBase60(base60String: string): number; |
| 94 | + } |
| 95 | + |
| 96 | + type Zone = tz.Zone; |
| 97 | + |
| 98 | + /** Parsed / unpacked zone data. */ |
| 99 | + interface UnpackedZone { |
| 100 | + /** The uniquely identifying name of the time zone. */ |
| 101 | + name: string; |
| 102 | + |
| 103 | + /** zone abbreviations */ |
| 104 | + abbrs: Array<string>; |
| 105 | + |
| 106 | + /** (measured in milliseconds) */ |
| 107 | + untils: Array<number | null>; |
| 108 | + |
| 109 | + /** (measured in minutes) */ |
| 110 | + offsets: Array<number>; |
| 111 | + } |
| 112 | + |
| 113 | + /** Bundle of zone data and links for multiple timezones */ |
| 114 | + interface PackedZoneBundle { |
| 115 | + version: string; |
| 116 | + zones: Array<string>; |
| 117 | + links: Array<string>; |
| 118 | + } |
| 119 | + |
| 120 | + /** Bundle of zone data and links for multiple timezones */ |
| 121 | + interface UnpackedZoneBundle { |
| 122 | + version: string; |
| 123 | + zones: Array<UnpackedZone>; |
| 124 | + links: Array<string>; |
| 125 | + } |
| 126 | + |
| 127 | +} |
0 commit comments