-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
44 lines (38 loc) · 1.39 KB
/
index.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
/**
* @author <a href="mailto:[email protected]">Open Software Development Team - Pattarapong.Dev</a>
* @license Pattarapong.Dev Open Software License Agreement (https://open.pattarapong.dev/licenses)
* @copyright Pattarapong.Dev (https://pattarapong.dev)
* @version alpha-0.1.0
* @since 2024-07-16
* @description This module provides various date and time manipulation functions.
* @see https://docs.pattarapong.dev/th/date-time-manipulation-module
* @link https://open.pattarapong.dev/
* @link https://docs.pattarapong.dev/
* @link https://github.com/Pattarapong-Dev
*/
export function addSeconds(date: Date, seconds: number) {
return new Date(date.getTime() + seconds*1000);
}
export function addMinutes(date: Date, minutes: number): Date {
return new Date(date.getTime() + minutes*60000);
}
export function addHours(date: Date, hours: number): Date {
return new Date(date.getTime() + hours*3600000);
}
export function addDays(date: Date, days: number): Date {
return new Date(date.getTime() + days*86400000);
}
export function addWeeks(date: Date, weeks: number): Date {
return new Date(date.getTime() + weeks*604800000);
}
export default {
currentTime: new Date,
addSeconds,
addMinutes,
addHours,
addDays,
addWeeks,
formatDate: (date: Date, format: string = 'YYYY-MM-DD HH:mm:ss') => {
return date.toISOString().slice(0, format.length);
}
}