clockey 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/package.json +39 -0
- package/src/core/date.ts +40 -0
- package/src/core/time.ts +28 -0
- package/src/index.ts +2 -0
- package/src/response/dateResponse.ts +13 -0
- package/src/response/timeResponse.ts +13 -0
- package/src/types/date.d.ts +15 -0
- package/src/types/time.d.ts +16 -0
- package/tsconfig.json +17 -0
- package/tsup.config.ts +10 -0
package/README.md
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "clockey",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "API-first time utilities for backend developers",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsup"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/yasasbanukaofficial/clockey.git"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"clockey",
|
|
17
|
+
"api",
|
|
18
|
+
"time",
|
|
19
|
+
"timestamp",
|
|
20
|
+
"backend",
|
|
21
|
+
"server",
|
|
22
|
+
"clock",
|
|
23
|
+
"utc",
|
|
24
|
+
"helper",
|
|
25
|
+
"response",
|
|
26
|
+
"clock",
|
|
27
|
+
"date"
|
|
28
|
+
],
|
|
29
|
+
"author": "Yasas Banu",
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"bugs": {
|
|
32
|
+
"url": "https://github.com/yasasbanukaofficial/clockey/issues"
|
|
33
|
+
},
|
|
34
|
+
"homepage": "https://github.com/yasasbanukaofficial/clockey#readme",
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"tsup": "^8.5.1",
|
|
37
|
+
"typescript": "^5.9.3"
|
|
38
|
+
}
|
|
39
|
+
}
|
package/src/core/date.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export function formatCurrentDate() {
|
|
2
|
+
const currentDate = new Date();
|
|
3
|
+
const dayAsString = [
|
|
4
|
+
"Sunday",
|
|
5
|
+
"Monday",
|
|
6
|
+
"Tuesday",
|
|
7
|
+
"Wednesday",
|
|
8
|
+
"Thursday",
|
|
9
|
+
"Friday",
|
|
10
|
+
"Saturday",
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
const monthAsString = [
|
|
14
|
+
"January",
|
|
15
|
+
"February",
|
|
16
|
+
"March",
|
|
17
|
+
"April",
|
|
18
|
+
"May",
|
|
19
|
+
"June",
|
|
20
|
+
"July",
|
|
21
|
+
"August",
|
|
22
|
+
"September",
|
|
23
|
+
"October",
|
|
24
|
+
"November",
|
|
25
|
+
"December",
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
const yr = currentDate.getFullYear();
|
|
29
|
+
const month = monthAsString[currentDate.getMonth()];
|
|
30
|
+
const day = dayAsString[currentDate.getDay()];
|
|
31
|
+
const date = currentDate.getDate();
|
|
32
|
+
const ordinal =
|
|
33
|
+
date === 1 ? "st" : date === 2 ? "nd" : date === 3 ? "rd" : "th";
|
|
34
|
+
|
|
35
|
+
const fullDate = `${month} ${date}${ordinal}, ${day}, ${yr}`;
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
date: { yr, month, day, date, ordinal, fullDate },
|
|
39
|
+
};
|
|
40
|
+
}
|
package/src/core/time.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export function formatCurrentTime() {
|
|
2
|
+
const currentTime = new Date();
|
|
3
|
+
|
|
4
|
+
let hrs24 = currentTime.getHours();
|
|
5
|
+
const min = currentTime.getMinutes();
|
|
6
|
+
const sec = currentTime.getSeconds();
|
|
7
|
+
|
|
8
|
+
const period = hrs24 >= 12 ? "PM" : "AM";
|
|
9
|
+
let hrs12 = hrs24 % 12;
|
|
10
|
+
if (hrs12 === 0) hrs12 = 12;
|
|
11
|
+
|
|
12
|
+
const pad = (n: number) => n.toString().padStart(2, "0");
|
|
13
|
+
|
|
14
|
+
const timeAsString24 = `${pad(hrs24)}:${pad(min)}:${pad(sec)}`;
|
|
15
|
+
const timeAsString12 = `${pad(hrs12)}:${pad(min)}:${pad(sec)} ${period}`;
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
time: {
|
|
19
|
+
hrs24,
|
|
20
|
+
hrs12,
|
|
21
|
+
min,
|
|
22
|
+
sec,
|
|
23
|
+
period,
|
|
24
|
+
timeAsString24,
|
|
25
|
+
timeAsString12,
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { formatCurrentDate } from "../core/date";
|
|
2
|
+
import { ClockeyDateResponse } from "../types/date";
|
|
3
|
+
|
|
4
|
+
export function getCurrentDate() {
|
|
5
|
+
const { date } = formatCurrentDate();
|
|
6
|
+
const response: ClockeyDateResponse = {
|
|
7
|
+
success: true,
|
|
8
|
+
code: 200,
|
|
9
|
+
msg: "Current date fetched successfully",
|
|
10
|
+
data: date,
|
|
11
|
+
};
|
|
12
|
+
return response;
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { formatCurrentTime } from "../core/time";
|
|
2
|
+
import { ClockeyTimeResponse } from "../types/time";
|
|
3
|
+
|
|
4
|
+
export function getCurrentTime() {
|
|
5
|
+
const { time } = formatCurrentTime();
|
|
6
|
+
const response: ClockeyTimeResponse = {
|
|
7
|
+
success: true,
|
|
8
|
+
code: 200,
|
|
9
|
+
msg: "Current time fetched successfully",
|
|
10
|
+
data: time,
|
|
11
|
+
};
|
|
12
|
+
return response;
|
|
13
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface DateData {
|
|
2
|
+
yr: number;
|
|
3
|
+
month: string;
|
|
4
|
+
day: string;
|
|
5
|
+
date: number;
|
|
6
|
+
ordinal: string;
|
|
7
|
+
fullDate: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface ClockeyDateResponse {
|
|
11
|
+
success: boolean;
|
|
12
|
+
code: number;
|
|
13
|
+
msg: string;
|
|
14
|
+
data: DateData;
|
|
15
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface TimeData {
|
|
2
|
+
hrs24: number;
|
|
3
|
+
hrs12: number;
|
|
4
|
+
min: number;
|
|
5
|
+
sec: number;
|
|
6
|
+
period: "AM" | "PM" | string;
|
|
7
|
+
timeAsString24: string;
|
|
8
|
+
timeAsString12: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface ClockeyTimeResponse {
|
|
12
|
+
success: boolean;
|
|
13
|
+
code: number;
|
|
14
|
+
msg: string;
|
|
15
|
+
data: TimeData;
|
|
16
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"strict": true,
|
|
4
|
+
"noImplicitAny": true,
|
|
5
|
+
"esModuleInterop": true,
|
|
6
|
+
"strictNullChecks": true,
|
|
7
|
+
"target": "es2022",
|
|
8
|
+
"moduleResolution": "Node10",
|
|
9
|
+
"module": "es2022",
|
|
10
|
+
"declaration": true,
|
|
11
|
+
"isolatedModules": true,
|
|
12
|
+
"noEmit": true,
|
|
13
|
+
"outDir": "dist"
|
|
14
|
+
},
|
|
15
|
+
"include": ["src"],
|
|
16
|
+
"exclude": ["node_modules"]
|
|
17
|
+
}
|