Type definitions for ultra-strftime 1.0 (#20869)

This commit is contained in:
Piotr Roszatycki
2017-10-23 11:41:03 -07:00
committed by Sheetal Nandi
parent 9fe8f1b8a4
commit 8abe0458f0
4 changed files with 126 additions and 0 deletions
+59
View File
@@ -0,0 +1,59 @@
// Type definitions for ultra-strftime 1.0
// Project: https://github.com/xio4/ultra_strftime
// Definitions by: Piotr Roszatycki <https://github.com/dex4er>
// 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;
+23
View File
@@ -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"
]
}
+3
View File
@@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}
@@ -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);