my-timezone 1.14.1 → 1.14.3
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/dist/MyTimezone.d.ts +14 -14
- package/dist/MyTimezone.js +14 -14
- package/dist/cli.js +1 -1
- package/package.json +5 -5
package/dist/MyTimezone.d.ts
CHANGED
|
@@ -2,6 +2,9 @@ export declare enum DIRECTION {
|
|
|
2
2
|
EAST = "E",
|
|
3
3
|
WEST = "W"
|
|
4
4
|
}
|
|
5
|
+
export interface Coordinates {
|
|
6
|
+
longitude: number;
|
|
7
|
+
}
|
|
5
8
|
export interface CustomDate {
|
|
6
9
|
day: string;
|
|
7
10
|
hours: string;
|
|
@@ -10,11 +13,18 @@ export interface CustomDate {
|
|
|
10
13
|
seconds: string;
|
|
11
14
|
year: string;
|
|
12
15
|
}
|
|
16
|
+
export interface Location extends Coordinates {
|
|
17
|
+
formattedAddress?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface MyTimezoneConfig {
|
|
20
|
+
ntpServer?: string;
|
|
21
|
+
offline?: boolean;
|
|
22
|
+
}
|
|
13
23
|
export interface OSMResult {
|
|
14
|
-
boundingbox?: string[]
|
|
24
|
+
boundingbox?: null | string[];
|
|
15
25
|
class: string;
|
|
16
26
|
display_name: string;
|
|
17
|
-
icon?:
|
|
27
|
+
icon?: null | string;
|
|
18
28
|
importance: number;
|
|
19
29
|
lat: string;
|
|
20
30
|
licence: string;
|
|
@@ -24,24 +34,14 @@ export interface OSMResult {
|
|
|
24
34
|
place_id: number;
|
|
25
35
|
type: string;
|
|
26
36
|
}
|
|
27
|
-
export interface MyTimezoneConfig {
|
|
28
|
-
ntpServer?: string;
|
|
29
|
-
offline?: boolean;
|
|
30
|
-
}
|
|
31
|
-
export interface Coordinates {
|
|
32
|
-
longitude: number;
|
|
33
|
-
}
|
|
34
|
-
export interface Location extends Coordinates {
|
|
35
|
-
formattedAddress?: string;
|
|
36
|
-
}
|
|
37
37
|
export declare class MyTimezone {
|
|
38
38
|
private readonly config;
|
|
39
39
|
private readonly ntpClient;
|
|
40
40
|
constructor(config?: MyTimezoneConfig);
|
|
41
|
-
getLocation(location: string): Promise<Location>;
|
|
42
|
-
getLocationByName(address: string, radius?: string): Promise<Location>;
|
|
43
41
|
getDateByAddress(address: string): Promise<Date>;
|
|
44
42
|
getDateByLongitude(longitude: number): Promise<Date>;
|
|
43
|
+
getLocation(location: string): Promise<Location>;
|
|
44
|
+
getLocationByName(address: string, radius?: string): Promise<Location>;
|
|
45
45
|
parseCoordinates(coordinates: string): Coordinates;
|
|
46
46
|
parseDate(date: Date): CustomDate;
|
|
47
47
|
private getOffsetMillis;
|
package/dist/MyTimezone.js
CHANGED
|
@@ -17,6 +17,19 @@ export class MyTimezone {
|
|
|
17
17
|
};
|
|
18
18
|
this.ntpClient = new NTPClient(this.config.ntpServer);
|
|
19
19
|
}
|
|
20
|
+
async getDateByAddress(address) {
|
|
21
|
+
const { longitude } = await this.getLocationByName(address);
|
|
22
|
+
return this.getDateByLongitude(longitude);
|
|
23
|
+
}
|
|
24
|
+
async getDateByLongitude(longitude) {
|
|
25
|
+
const direction = longitude < 0 ? DIRECTION.WEST : DIRECTION.EAST;
|
|
26
|
+
const utcDate = await this.getUTCDate();
|
|
27
|
+
const offsetMillis = this.getOffsetMillis(longitude, direction);
|
|
28
|
+
const calculatedDate = direction === DIRECTION.EAST
|
|
29
|
+
? new Date(utcDate.getTime() + offsetMillis)
|
|
30
|
+
: new Date(utcDate.getTime() - offsetMillis);
|
|
31
|
+
return calculatedDate;
|
|
32
|
+
}
|
|
20
33
|
async getLocation(location) {
|
|
21
34
|
try {
|
|
22
35
|
const coordinates = this.parseCoordinates(location);
|
|
@@ -62,19 +75,6 @@ export class MyTimezone {
|
|
|
62
75
|
longitude: parsedLongitude,
|
|
63
76
|
};
|
|
64
77
|
}
|
|
65
|
-
async getDateByAddress(address) {
|
|
66
|
-
const { longitude } = await this.getLocationByName(address);
|
|
67
|
-
return this.getDateByLongitude(longitude);
|
|
68
|
-
}
|
|
69
|
-
async getDateByLongitude(longitude) {
|
|
70
|
-
const direction = longitude < 0 ? DIRECTION.WEST : DIRECTION.EAST;
|
|
71
|
-
const utcDate = await this.getUTCDate();
|
|
72
|
-
const offsetMillis = this.getOffsetMillis(longitude, direction);
|
|
73
|
-
const calculatedDate = direction === DIRECTION.EAST
|
|
74
|
-
? new Date(utcDate.getTime() + offsetMillis)
|
|
75
|
-
: new Date(utcDate.getTime() - offsetMillis);
|
|
76
|
-
return calculatedDate;
|
|
77
|
-
}
|
|
78
78
|
parseCoordinates(coordinates) {
|
|
79
79
|
var _a;
|
|
80
80
|
const longitudeRegex = new RegExp('[-?\\W\\d\\.]+,(?<longitude>[-?\\W\\d\\.]+)');
|
|
@@ -97,7 +97,7 @@ export class MyTimezone {
|
|
|
97
97
|
if (!(parsedString === null || parsedString === void 0 ? void 0 : parsedString.groups)) {
|
|
98
98
|
throw new Error('Could not parse date');
|
|
99
99
|
}
|
|
100
|
-
const {
|
|
100
|
+
const { day, hours, minutes, month, seconds, year } = parsedString.groups;
|
|
101
101
|
return { day, hours, minutes, month, seconds, year };
|
|
102
102
|
}
|
|
103
103
|
getOffsetMillis(longitudeDegrees, direction) {
|
package/dist/cli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { program as commander } from 'commander';
|
|
2
3
|
import fs from 'node:fs/promises';
|
|
3
4
|
import path from 'node:path';
|
|
4
|
-
import { program as commander } from 'commander';
|
|
5
5
|
import { MyTimezone } from './MyTimezone.js';
|
|
6
6
|
const __dirname = import.meta.dirname;
|
|
7
7
|
const packageJsonPath = path.join(__dirname, '../package.json');
|
package/package.json
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
"author": "Florian Imdahl <git@ffflorian.de>",
|
|
3
3
|
"bin": "dist/cli.js",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"commander": "14.0.
|
|
6
|
-
"ntpclient": "1.15.
|
|
5
|
+
"commander": "14.0.3",
|
|
6
|
+
"ntpclient": "1.15.3"
|
|
7
7
|
},
|
|
8
8
|
"description": "Get the exact time based on your location.",
|
|
9
9
|
"devDependencies": {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"rimraf": "6.1.2",
|
|
12
12
|
"tsx": "4.21.0",
|
|
13
13
|
"typescript": "5.9.3",
|
|
14
|
-
"vitest": "4.0.
|
|
14
|
+
"vitest": "4.0.18"
|
|
15
15
|
},
|
|
16
16
|
"engines": {
|
|
17
17
|
"node": ">= 21"
|
|
@@ -33,6 +33,6 @@
|
|
|
33
33
|
"test": "vitest run"
|
|
34
34
|
},
|
|
35
35
|
"type": "module",
|
|
36
|
-
"version": "1.14.
|
|
37
|
-
"gitHead": "
|
|
36
|
+
"version": "1.14.3",
|
|
37
|
+
"gitHead": "7a18174f4c706e506e8b3aed50a49d54b795206b"
|
|
38
38
|
}
|