-
Notifications
You must be signed in to change notification settings - Fork 835
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
240 additions
and
395 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,127 +1,67 @@ | ||
import * as moment from 'moment'; | ||
|
||
// require('moment-timezone') === require('moment') | ||
export = moment; | ||
import moment = require('moment'); | ||
|
||
declare module 'moment' { | ||
interface Moment { | ||
/** Set the timezone and update the offset */ | ||
tz(zone: string): Moment; | ||
/** Return the timezone name or undefined if a zone has not yet been set */ | ||
tz(): string | undefined; | ||
|
||
/** Get the zone abbreviation. This is what moment.js uses when formatting the z token. */ | ||
zoneAbbr(): string; | ||
|
||
/** Get the zone long form name. This is what moment.js uses when formatting the zz token. */ | ||
zoneName(): string; | ||
} | ||
|
||
// Match normal moment constructor but with an extra timezone argument | ||
// 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 | ||
// declare function moment(inp?: moment.MomentInput, format?: moment.MomentFormatSpecification, strict?: boolean): moment.Moment; | ||
// declare function moment(inp?: moment.MomentInput, format?: moment.MomentFormatSpecification, language?: string, strict?: boolean): moment.Moment; | ||
|
||
// Should be sorted from tightest to loosest. TypeScript picks the first signature that matches, going top to bottom. | ||
|
||
/** create a moment with a time zone */ | ||
function tz(inp: MomentInput, format: MomentFormatSpecification, language: string, strict: boolean, zone: string): Moment; | ||
/** create a moment with a time zone */ | ||
function tz(inp: MomentInput, format: MomentFormatSpecification, language: string, zone: string): Moment; | ||
/** create a moment with a time zone */ | ||
function tz(inp: MomentInput, format: MomentFormatSpecification, strict: boolean, zone: string): Moment; | ||
/** create a moment with a time zone */ | ||
function tz(inp: MomentInput, format: MomentFormatSpecification, zone: string): Moment; | ||
/** create a moment with a time zone */ | ||
function tz(inp: MomentInput, zone: string): Moment; | ||
/** create a moment with a time zone */ | ||
function tz(zone?: string): Moment; | ||
|
||
namespace tz { | ||
/** Version of moment-timezone */ | ||
const version: string; | ||
|
||
/** | ||
* Change the default timezone of newly created Moment instances. | ||
* By default new instances are created in the local timezone. | ||
*/ | ||
function setDefault(zone: string): typeof moment; | ||
|
||
/** Reset the default timezone to local. */ | ||
function setDefault(): typeof moment; | ||
|
||
/** | ||
* Retrieve or guess the user's timezone. Uses the browser's Internationalization API if available. | ||
* Otherwise, guesses by sampling offsets from different points in time and comparing them to available zone data. | ||
*/ | ||
function guess(): string; | ||
|
||
interface Zone extends UnpackedZone {} | ||
class Zone { | ||
/** Get the abbreviation for a given timestamp from a Zone. */ | ||
abbr(timestamp: number): string; | ||
|
||
/** Get the offset for a given timestamp from a Zone. */ | ||
offset(timestamp: number): number; | ||
|
||
/** Parse an offset for a timestamp constructed from Date.UTC in that zone. */ | ||
parse(timestamp: number): number; | ||
} | ||
|
||
/** Return a timezone by name or null if timezone by that name is not loaded. */ | ||
function zone(name: string): Zone | null; | ||
|
||
/** Add zone data for a timezone. */ | ||
function add(packedZone: string): void; | ||
/** Add zone data for multiple timezones. */ | ||
function add(packedZones: Array<string>): void; | ||
|
||
/** Link two zone names to the same data */ | ||
function link(packedLink: string): void; | ||
/** Add multiple links at once */ | ||
function link(packedLinks: Array<string>): void; | ||
|
||
/** load a bundle of zone data and links */ | ||
function load(bundle: PackedZoneBundle): void; | ||
|
||
/** get a list of all available time zone names */ | ||
function names(): Array<string>; | ||
|
||
/** Convert a packed string to an unpacked zone data object */ | ||
function unpack(packedZone: string): UnpackedZone; | ||
/** Convert a base 60 string to a base 10 number. */ | ||
function unpackBase60(base60String: string): number; | ||
interface MomentZone { | ||
name: string; | ||
abbrs: string[]; | ||
untils: number[]; | ||
offsets: number[]; | ||
population: number; | ||
|
||
abbr(timestamp: number): string; | ||
offset(timestamp: number): number; | ||
utcOffset(timestamp: number): number; | ||
parse(timestamp: number): number; | ||
} | ||
|
||
type Zone = tz.Zone; | ||
|
||
/** Parsed / unpacked zone data. */ | ||
interface UnpackedZone { | ||
/** The uniquely identifying name of the time zone. */ | ||
interface MomentZoneOffset { | ||
name: string; | ||
|
||
/** zone abbreviations */ | ||
abbrs: Array<string>; | ||
|
||
/** (measured in milliseconds) */ | ||
untils: Array<number | null>; | ||
|
||
/** (measured in minutes) */ | ||
offsets: Array<number>; | ||
offset: number; | ||
} | ||
|
||
/** Bundle of zone data and links for multiple timezones */ | ||
interface PackedZoneBundle { | ||
version: string; | ||
zones: Array<string>; | ||
links: Array<string>; | ||
interface MomentTimezone { | ||
(): moment.Moment; | ||
(timezone: string): moment.Moment; | ||
(date: number, timezone: string): moment.Moment; | ||
(date: number[], timezone: string): moment.Moment; | ||
(date: string, timezone: string): moment.Moment; | ||
(date: string, format: moment.MomentFormatSpecification, timezone: string): moment.Moment; | ||
(date: string, format: moment.MomentFormatSpecification, strict: boolean, timezone: string): moment.Moment; | ||
(date: string, format: moment.MomentFormatSpecification, language: string, timezone: string): moment.Moment; | ||
(date: string, format: moment.MomentFormatSpecification, language: string, strict: boolean, timezone: string): moment.Moment; | ||
(date: Date, timezone: string): moment.Moment; | ||
(date: moment.Moment, timezone: string): moment.Moment; | ||
(date: any, timezone: string): moment.Moment; | ||
|
||
zone(timezone: string): MomentZone | null; | ||
|
||
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[]; | ||
zonesForCountry<T extends true>(country: string, with_offset: T): T extends true ? MomentZoneOffset[] : never; | ||
zonesForCountry<T extends false>(country: string, with_offset?: T): T extends false ? string[] : never; | ||
zonesForCountry(country: string, with_offset?: boolean): MomentZoneOffset[] | string[]; | ||
countries(): string[]; | ||
guess(ignoreCache?: boolean): string; | ||
|
||
setDefault(timezone?: string): Moment; | ||
} | ||
|
||
/** Bundle of zone data and links for multiple timezones */ | ||
interface UnpackedZoneBundle { | ||
version: string; | ||
zones: Array<UnpackedZone>; | ||
links: Array<string>; | ||
interface Moment { | ||
tz(): string | undefined; | ||
tz(timezone: string, keepLocalTime?: boolean): moment.Moment; | ||
zoneAbbr(): string; | ||
zoneName(): string; | ||
} | ||
|
||
const tz: MomentTimezone; | ||
} | ||
|
||
// require("moment-timezone") === require("moment") | ||
export = moment; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,70 @@ | ||
import * as moment from 'moment'; | ||
|
||
// require('moment-timezone') === require('moment') | ||
export = moment; | ||
import moment = require('moment'); | ||
import { MomentTimezone } from "./index"; | ||
|
||
declare module 'moment' { | ||
namespace tz { | ||
|
||
/** Parsed / unpacked zone data. */ | ||
interface UnpackedZone { | ||
/** The uniquely identifying name of the time zone. */ | ||
name: string; | ||
/** zone abbreviations */ | ||
abbrs: Array<string>; | ||
/** (measured in milliseconds) */ | ||
untils: Array<number | null>; | ||
/** (measured in minutes) */ | ||
offsets: Array<number>; | ||
} | ||
|
||
/** Bundle of zone data and links for multiple timezones */ | ||
interface PackedZoneBundle { | ||
version: string; | ||
zones: Array<string>; | ||
links: Array<string>; | ||
} | ||
|
||
/** Bundle of zone data and links for multiple timezones */ | ||
interface UnpackedZoneBundle { | ||
version: string; | ||
zones: Array<UnpackedZone>; | ||
links: Array<string>; | ||
} | ||
|
||
/** extends MomentTimezone declared in index */ | ||
interface MomentTimezone { | ||
/** Converts zone data in the unpacked format to the packed format. */ | ||
function pack(unpackedObject: UnpackedZone): string; | ||
pack(unpackedObject: UnpackedZone): string; | ||
|
||
/** Convert a base 10 number to a base 60 string. */ | ||
function packBase60(input: number, precision?: number): string; | ||
packBase60(input: number, precision?: number): string; | ||
|
||
/** Create links out of two zones that share data. | ||
* @returns A new ZoneBundle with duplicate zone data replaced by links | ||
*/ | ||
function createLinks(unlinked: UnpackedZoneBundle): PackedZoneBundle; | ||
createLinks(unlinked: UnpackedZoneBundle): PackedZoneBundle; | ||
|
||
/** | ||
* Filter out data for years outside a certain range. | ||
* @return a new, filtered UnPackedZone object | ||
*/ | ||
function filterYears(unpackedZone: UnpackedZone, startYear: number, endYear: number): UnpackedZone; | ||
filterYears(unpackedZone: UnpackedZone, startYear: number, endYear: number): UnpackedZone; | ||
/** | ||
* Filter out data for years outside a certain range. | ||
* @return a new, filtered UnPackedZone object | ||
*/ | ||
function filterYears(unpackedZone: UnpackedZone, startAndEndYear: number): UnpackedZone; | ||
filterYears(unpackedZone: UnpackedZone, startAndEndYear: number): UnpackedZone; | ||
|
||
/** | ||
* Combines packing, link creation, and subsetting of years into one simple interface. | ||
* Pass in an unpacked bundle, start year, and end year and get a filtered, linked, packed bundle back. | ||
*/ | ||
function filterLinkPack(unpackedBundle: UnpackedZoneBundle, startYear: number, endYear: number): PackedZoneBundle; | ||
filterLinkPack(unpackedBundle: UnpackedZoneBundle, startYear: number, endYear: number): PackedZoneBundle; | ||
/** | ||
* Combines packing, link creation, and subsetting of years into one simple interface. | ||
* Pass in an unpacked bundle, start year, and end year and get a filtered, linked, packed bundle back. | ||
*/ | ||
function filterLinkPack(unpackedBundle: UnpackedZoneBundle, startAndEndYear: number): PackedZoneBundle; | ||
filterLinkPack(unpackedBundle: UnpackedZoneBundle, startAndEndYear: number): PackedZoneBundle; | ||
} | ||
} | ||
} | ||
|
||
// require("moment-timezone") === require("moment") | ||
export = moment; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.