-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from 9Y5/yisheng/add-typescript-declaration-file
Add typescript declaration file.
- Loading branch information
Showing
3 changed files
with
173 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import fecha = require('./fecha.js'); | ||
|
||
// 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: function(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 yet. | ||
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: function(D: number) { | ||
return D + "th"; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,5 +34,6 @@ | |
"files": [ | ||
"fecha.js", | ||
"fecha.min.js" | ||
] | ||
], | ||
"types": "./fecha.d.ts" | ||
} |