Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add typescript definitions #444

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions moment-timezone.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Type definitions for moment-timezone.js 0.2
// Project: http://momentjs.com/timezone/
// Definitions by: Michel Salib <https://github.com/michelsalib>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

/// <reference path="../moment/moment.d.ts" />

declare namespace moment {
interface MomentBuiltinFormat {
__momentBuiltinFormatBrand: any;
}

type MomentFormatSpecification = string | MomentBuiltinFormat | (string | MomentBuiltinFormat)[];
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the inconsistent indentation intentional? (This and above vs. the interfaces below.)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was not intentional. Haven't done much with JS. I used the initial from DefinitelyTyped and referenced other typescript files to get to this one. If there is a preferred format, I can make the updates.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the file is indented correctly--just be consistent.


interface Moment {
tz(): string;
tz(timezone: string): Moment;
zoneAbbr(): string;
zoneName(): string;
}

interface MomentZone {
name: string;
abbrs: string[];
untils: number[];
offsets: number[];

abbr(timestamp: number): string;
offset(timestamp: number): number;
parse(timestamp: number): number;
}

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;

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[];
guess(): string;

setDefault(timezone: string): void;
}

const tz: MomentTimezone;
}