Skip to content

Commit

Permalink
Move exported types to top-level so that they can all be imported as …
Browse files Browse the repository at this point in the history
…named imports

- Zone class must exist at `tz.Zone` because that's where it's exposed at runtime, but the `Zone` interface is still re-exported as a named export
  • Loading branch information
cspotcode committed Jun 12, 2019
1 parent 10a4ceb commit 98e6199
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 36 deletions.
66 changes: 34 additions & 32 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,6 @@ declare module 'moment' {
*/
function guess(): string;

/** Return a timezone by name or null if timezone by that name is not loaded. */
function zone(name: string): Zone | null;

/** 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>;
}

interface Zone extends UnpackedZone {}
class Zone {
/** Get the abbreviation for a given timestamp from a Zone. */
Expand All @@ -86,6 +68,9 @@ declare module 'moment' {
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. */
Expand All @@ -99,20 +84,6 @@ declare module 'moment' {
/** load a bundle of zone data and links */
function load(bundle: PackedZoneBundle): void;

/** 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>;
}

/** get a list of all available time zone names */
function names(): Array<string>;

Expand All @@ -122,4 +93,35 @@ declare module 'moment' {
function unpackBase60(base60String: string): number;
}

type Zone = tz.Zone;

/** 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>;
}

}
8 changes: 4 additions & 4 deletions typing-tests/moment-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ moment.tz.setDefault();

moment.tz.guess(); // America/Chicago

const unpackedZone: moment.tz.UnpackedZone = {
const unpackedZone: moment.UnpackedZone = {
name : 'America/Los_Angeles', // the unique identifier
abbrs : ['PDT', 'PST'], // the abbreviations
untils : [1414918800000, 1425808800000], // the timestamps in milliseconds
Expand All @@ -126,7 +126,7 @@ var zone = moment.tz.zone('America/New_York');
zone.parse(Date.UTC(2012, 2, 11, 1, 59)); // 300
zone.parse(Date.UTC(2012, 2, 11, 2, 0)); // 240

const unpackedZone2: moment.tz.UnpackedZone = {
const unpackedZone2: moment.UnpackedZone = {
name : 'America/Los_Angeles',
abbrs : ['PST', 'PDT','PST', 'PDT', 'PST', 'PDT', 'PST', 'PDT', 'PST', 'PDT', 'PST'],
untils : [1394359200000, 1414918800000, 1425808800000, 1446368400000, 1457863200000, 1478422800000, 1489312800000, 1509872400000, 1520762400000, 1541322000000, null],
Expand Down Expand Up @@ -154,7 +154,7 @@ moment.tz.link([
'America/New_York|US/Eastern'
]);

const packedZoneBundle: moment.tz.PackedZoneBundle = {
const packedZoneBundle: moment.PackedZoneBundle = {
version : '2014e',
zones : [
'America/Los_Angeles|PST PDT|80 70|0101|1Lzm0 1zb0 Op0',
Expand Down Expand Up @@ -229,7 +229,7 @@ moment.tz.unpackBase60('mh'); // 1337
moment.tz.unpackBase60('1.9'); // 1.15
moment.tz.unpackBase60('k.7op'); // 20.123449074074074

var unlinked: moment.tz.UnpackedZoneBundle = {
var unlinked: moment.UnpackedZoneBundle = {
zones : [
{name:"Zone/One",abbrs:["OST","ODT"],offsets:[60,120],untils:[403041600000,417034800000]},
{name:"Zone/Two",abbrs:["OST","ODT"],offsets:[60,120],untils:[403041600000,417034800000]}
Expand Down

0 comments on commit 98e6199

Please sign in to comment.