-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.d.ts
170 lines (136 loc) · 4.27 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/**
* @see https://github.com/kawanet/cdate
*/
export const cdate: cdate.cdate;
export const strftime: cdate.strftime;
export declare namespace cdate {
type cdate = (dt?: string | number | Date) => CDate;
type strftime = (fmt: string, dt?: Date) => string;
/**
* Unit
*/
type UnitLong = "second" | "minute" | "hour" | "day" | "month" | "year";
type UnitLongS = "seconds" | "minutes" | "hours" | "days" | "months" | "years";
type UnitShort = "s" | "m" | "h" | "d" | "M" | "y";
type UnitForNext = UnitLong | UnitShort | "week" | "w" | "millisecond" | "ms";
type UnitForAdd = UnitForNext | UnitLongS | "weeks" | "milliseconds";
type UnitForStart = UnitLong | UnitShort | "week" | "w" | "date" | "D";
type UnitForGet = UnitLong | UnitShort | "date" | "D" | "millisecond" | "ms";
/**
* Public Interface for consumers
*/
type CDate = CDateCore & CDateFormat & CDateCalc & CDateTZ;
interface CDateCore {
/**
* returns a bare Date object
*/
toDate(): Date;
/**
* returns a JSON representation of Date
*/
toJSON(): string;
/**
* returns an instance including the plugin
*/
plugin<T>(fn: Plugin<T>): this & T;
/**
* cdate function factory
*/
cdateFn(): cdate;
}
interface CDateFormat {
/**
* format("YYYY/MM/DD HH:mm:ss.SSSZ")
*/
format(format?: string): string;
/**
* text("%Y-%m-%dT%H:%M:%S.%LZ")
*/
text(format?: string): string;
handler(handlers: Handlers): this;
locale(lang: string): this;
}
interface CDateCalc {
/**
* get("date"), get("hour"),...
*/
get(unit: UnitForGet): number;
/**
* set("date", 31), set("day", 0),...
*/
set(unit: UnitForGet, value: number): this;
/**
* add(1, "day"), add(2, "hours"),...
*/
add(diff: number, unit?: UnitForAdd): this;
/**
* startOf("day"), startOf("month"),...
*/
startOf(unit: UnitForStart): this;
/**
* endOf("day") == startOf("day").next("day").add(-1, "ms")
*/
endOf(unit: UnitForStart): this;
/**
* next("day") == add(1, "day")
*/
next(unit: UnitForNext): this;
/**
* prev("day") == add(-1, "day")
*/
prev(unit: UnitForNext): this;
}
interface CDateTZ {
/**
* UTC
*/
utc(keepLocalTime?: boolean): this;
/**
* "+0900", "+09:00", "GMT+09:00", 540,...
*/
utcOffset(offset: string | number, keepLocalTime?: boolean): this;
/**
* returns 540 for "GMT+09:00"
*/
utcOffset(): number;
/**
* "Asia/Tokyo", "America/New_York",...
*/
tz(timeZoneName: string, keepLocalTime?: boolean): this;
}
type Handler = (dt: DateLike) => (string | number);
type Handlers = { [specifier: string]: string | Handler };
/**
* Internal interface for plugin developers
*/
interface Internal<T = {}, X = {}> extends CDate {
readonly t: number | DateLike;
readonly x: Options & X;
create(dt: number | DateLike): this;
inherit(): this & T;
rw(): DateLike;
ro(): DateLike;
}
interface Class<T = {}, X = {}> {
new(t: number | DateLike, x: X): Internal<T, X>;
}
interface Options {
rw?: (t: number) => DateLike;
}
interface Plugin<T = {}, X = {}, P = {}> {
(Parent: Class<P, X>): Class<T, X>;
}
interface DateLike {
getMilliseconds: typeof Date.prototype.getMilliseconds,
getSeconds: typeof Date.prototype.getSeconds,
getMinutes: typeof Date.prototype.getMinutes,
getHours: typeof Date.prototype.getHours,
getDay: typeof Date.prototype.getDay,
getDate: typeof Date.prototype.getDate,
getMonth: typeof Date.prototype.getMonth,
getFullYear: typeof Date.prototype.getFullYear,
getTimezoneOffset: typeof Date.prototype.getTimezoneOffset,
getTime: typeof Date.prototype.getTime,
setTime: typeof Date.prototype.setTime,
}
}