diff --git a/types/ultra-strftime/index.d.ts b/types/ultra-strftime/index.d.ts new file mode 100644 index 0000000000..f02d27d43f --- /dev/null +++ b/types/ultra-strftime/index.d.ts @@ -0,0 +1,59 @@ +// Type definitions for ultra-strftime 1.0 +// Project: https://github.com/xio4/ultra_strftime +// Definitions by: Piotr Roszatycki +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare function strftime(fmt: string, d?: Date, locale?: strftime.Locale, options?: strftime.Options): string; +declare function strftime(fmt: string, locale?: strftime.Locale, options?: strftime.Options): string; + +declare namespace strftime { + type StrftimeFunction = (fmt: string, d?: Date, options?: Options) => string; + + interface LocaleFormats { + /** equivalent to %m/%d/%y in en_US */ + D: string; + /** equivalent to %Y-%m-%d in en_US */ + F: string; + /** equivalent to %H:%M in en_US */ + R: string; + /** equivalent to %D in en_US */ + X: string; + /** equivalent to %a %b %d %X %Y %Z in en_US */ + c: string; + /** equivalent to %I:%M:%S %p in en_US */ + r: string; + /** equivalent to %H:%M:%S in en_US */ + T: string; + /** equivalent to %e-%b-%Y in en_US */ + v: string; + /** equivalent to %T in en_US */ + x: string; + } + + interface Locale { + days: string[]; + shortDays: string[]; + months: string[]; + shortMonths: string[]; + AM: string; + PM: string; + am: string; + pm: string; + formats: LocaleFormats; + } + + interface Options { + timezone?: string | number; + utc?: boolean; + } + + function strftimeUTC(fmt: string, d?: Date, locale?: Locale): string; + function strftimeTZ(fmt: string, d: Date, locale: Locale, timezone: number): string; + function strftimeTZ(fmt: string, d: Date, timezone: number): string; + function localizedStrftime(locale: Locale): StrftimeFunction; + + function strftime(fmt: string, d?: Date, locale?: Locale, options?: Options): string; + function strftime(fmt: string, locale?: Locale, options?: Options): string; +} + +export = strftime; diff --git a/types/ultra-strftime/tsconfig.json b/types/ultra-strftime/tsconfig.json new file mode 100644 index 0000000000..3b9461c0b6 --- /dev/null +++ b/types/ultra-strftime/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "ultra-strftime-tests.ts" + ] +} \ No newline at end of file diff --git a/types/ultra-strftime/tslint.json b/types/ultra-strftime/tslint.json new file mode 100644 index 0000000000..e60c15844f --- /dev/null +++ b/types/ultra-strftime/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +} \ No newline at end of file diff --git a/types/ultra-strftime/ultra-strftime-tests.ts b/types/ultra-strftime/ultra-strftime-tests.ts new file mode 100644 index 0000000000..4439425663 --- /dev/null +++ b/types/ultra-strftime/ultra-strftime-tests.ts @@ -0,0 +1,41 @@ +import * as strftime from "ultra-strftime"; + +const it_IT = { + days: ['domenica', 'lunedi', 'martedi', 'mercoledi', 'giovedi', 'venerdi', 'sabato'], + shortDays: ['dom', 'lun', 'mar', 'mer', 'gio', 'ven', 'sab'], + months: ['gennaio', 'febbraio', 'marzo', 'aprile', 'maggio', 'giugno', 'luglio', 'agosto', 'settembre', 'ottobre', 'novembre', 'dicembre'], + shortMonths: ['gen', 'feb', 'mar', 'apr', 'mag', 'giu', 'lug', 'ago', 'set', 'ott', 'nov', 'dic'], + AM: 'AM', + PM: 'PM', + am: 'am', + pm: 'pm', + formats: { + D: '%m/%d/%y', + F: '%Y-%m-%d', + R: '%H:%M', + X: '%T', + c: '%a %b %d %X %Y', + r: '%I:%M:%S %p', + T: '%H:%M:%S', + v: '%e-%b-%Y', + x: '%D' + } +}; + +strftime('%B %d, %Y %H:%M:%S'); +strftime('%B %d, %Y %H:%M:%S', new Date(1307472705067)); +strftime('%B %d, %Y %H:%M:%S', new Date(1307472705067), it_IT); +strftime('%B %d, %Y %H:%M:%S', new Date(1307472705067), it_IT, { timezone: -420 }); +strftime('%B %d, %Y %H:%M:%S', new Date(1307472705067), it_IT, { timezone: '-0700' }); +strftime('%B %d, %Y %H:%M:%S', new Date(1307472705067), it_IT, { utc: true }); + +const strftimeIT = strftime.localizedStrftime(it_IT); +strftimeIT('%B %d, %Y %H:%M:%S'); +strftimeIT('%B %d, %Y %H:%M:%S', new Date(1307472705067)); + +strftime.strftimeUTC('%B %d, %y %H:%M:%S', new Date(1307472705067), it_IT); +strftime.strftimeUTC('%B %d, %y %H:%M:%S', new Date(1307472705067)); +strftime.strftimeUTC('%B %d, %y %H:%M:%S'); + +strftime.strftimeTZ('%B %d, %y %H:%M:%S', new Date(1307472705067), it_IT, -420); +strftime.strftimeTZ('%B %d, %y %H:%M:%S', new Date(1307472705067), -420);