mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-12-04 12:11:47 +00:00
Add types for fecha. (#16284)
This commit is contained in:
committed by
Mohamed Hegazy
parent
8f7ff04d07
commit
da8970e975
@@ -0,0 +1,124 @@
|
||||
import fecha = require('fecha');
|
||||
|
||||
// test fecha.parse
|
||||
fecha.parse("February 3rd, 2014", "MMMM Do, YYYY");
|
||||
fecha.parse("5/3/98", "shortDate");
|
||||
|
||||
// test override fecha.i18n
|
||||
fecha.i18n = {
|
||||
dayNamesShort: ["Sun", "Mon", "Tue", "Wed", "Thur", "Fri", "Sat"],
|
||||
dayNames: [
|
||||
"Sunday",
|
||||
"Monday",
|
||||
"Tuesday",
|
||||
"Wednesday",
|
||||
"Thursday",
|
||||
"Friday",
|
||||
"Saturday"
|
||||
],
|
||||
monthNamesShort: [
|
||||
"Jan",
|
||||
"Feb",
|
||||
"Mar",
|
||||
"Apr",
|
||||
"May",
|
||||
"Jun",
|
||||
"Jul",
|
||||
"Aug",
|
||||
"Sep",
|
||||
"Oct",
|
||||
"Nov",
|
||||
"Dec"
|
||||
],
|
||||
monthNames: [
|
||||
"January",
|
||||
"February",
|
||||
"March",
|
||||
"April",
|
||||
"May",
|
||||
"June",
|
||||
"July",
|
||||
"August",
|
||||
"September",
|
||||
"October",
|
||||
"November",
|
||||
"December"
|
||||
],
|
||||
amPm: ["am", "pm"],
|
||||
DoFn(D: number) {
|
||||
return D + "th";
|
||||
}
|
||||
};
|
||||
|
||||
// just change one default mask
|
||||
fecha.masks.shortDate = "M/D/YY";
|
||||
|
||||
// test override fecha.masks with an object. Must implement all keys.
|
||||
// if you want to implement partially, use
|
||||
// fecha.masks = Object.assign(fecha.masks, {shortDate: 'M/D/YY'}) for example.
|
||||
fecha.masks = {
|
||||
default: "ddd MMM DD YYYY HH:mm:ss",
|
||||
shortDate: "M/D/YY",
|
||||
mediumDate: "MMM D, YYYY",
|
||||
longDate: "MMMM D, YYYY",
|
||||
fullDate: "dddd, MMMM D, YYYY",
|
||||
shortTime: "HH:mm",
|
||||
mediumTime: "HH:mm:ss",
|
||||
longTime: "HH:mm:ss.SSS"
|
||||
};
|
||||
|
||||
// test add custom named mask.
|
||||
// fecha.masks.myMask = "HH:mm:ss YY/MM/DD"; does not work for now.
|
||||
fecha.masks['myMask'] = "HH:mm:ss YY/MM/DD";
|
||||
|
||||
// test fecha.format without i18nSettings, with Date object.
|
||||
fecha.format(new Date(2014, 5, 6, 14, 10, 45), "myMask");
|
||||
|
||||
// test fecha.format without i18nSettings with number.
|
||||
fecha.format(Date.now(), "myMask");
|
||||
|
||||
// test override i18nSettings with fecha.format
|
||||
fecha.format(new Date(2014, 5, 6, 14, 10, 45), "myMask", {
|
||||
dayNamesShort: ["Sun", "Mon", "Tue", "Wed", "Thur", "Fri", "Sat"],
|
||||
dayNames: [
|
||||
"Sunday",
|
||||
"Monday",
|
||||
"Tuesday",
|
||||
"Wednesday",
|
||||
"Thursday",
|
||||
"Friday",
|
||||
"Saturday"
|
||||
],
|
||||
monthNamesShort: [
|
||||
"Jan",
|
||||
"Feb",
|
||||
"Mar",
|
||||
"Apr",
|
||||
"May",
|
||||
"Jun",
|
||||
"Jul",
|
||||
"Aug",
|
||||
"Sep",
|
||||
"Oct",
|
||||
"Nov",
|
||||
"Dec"
|
||||
],
|
||||
monthNames: [
|
||||
"January",
|
||||
"February",
|
||||
"March",
|
||||
"April",
|
||||
"May",
|
||||
"June",
|
||||
"July",
|
||||
"August",
|
||||
"September",
|
||||
"October",
|
||||
"November",
|
||||
"December"
|
||||
],
|
||||
amPm: ["am", "pm"],
|
||||
DoFn(D: number) {
|
||||
return D + "th";
|
||||
}
|
||||
});
|
||||
Vendored
+52
@@ -0,0 +1,52 @@
|
||||
// Type definitions for fecha 2.3
|
||||
// Project: https://github.com/taylorhakes/fecha
|
||||
// Definitions by: Goh Yisheng <https://github.com/9y5>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
export type Days = [string, string, string, string, string, string, string];
|
||||
|
||||
export type Months = [
|
||||
string,
|
||||
string,
|
||||
string,
|
||||
string,
|
||||
string,
|
||||
string,
|
||||
string,
|
||||
string,
|
||||
string,
|
||||
string,
|
||||
string,
|
||||
string
|
||||
];
|
||||
|
||||
export interface i18nSettings {
|
||||
amPm: [string, string];
|
||||
dayNames: Days;
|
||||
dayNamesShort: Days;
|
||||
monthNames: Months;
|
||||
monthNamesShort: Months;
|
||||
DoFn(D: number): string;
|
||||
}
|
||||
|
||||
export interface Masks {
|
||||
default: string;
|
||||
fullDate: string;
|
||||
longDate: string;
|
||||
longTime: string;
|
||||
mediumDate: string;
|
||||
mediumTime: string;
|
||||
shortDate: string;
|
||||
shortTime: string;
|
||||
[myMask: string]: string;
|
||||
}
|
||||
|
||||
export let masks: Masks;
|
||||
|
||||
export let i18n: i18nSettings;
|
||||
|
||||
export function format(dateObj: Date | number, mask: string, i18nSettings?: i18nSettings): string;
|
||||
|
||||
export function parse(dateStr: string, format: string, i18nSettings?: i18nSettings): Date;
|
||||
|
||||
export as namespace Fecha;
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"fecha-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user