my-timezone 1.4.0 → 1.4.2
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.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
/* eslint-disable no-magic-numbers */
|
|
11
|
+
import { expect, describe, test, vi } from 'vitest';
|
|
12
|
+
import nock from 'nock';
|
|
13
|
+
import { MyTimezone } from './MyTimezone.js';
|
|
14
|
+
vi.setConfig({
|
|
15
|
+
testTimeout: 10 * 1000, // 10 seconds
|
|
16
|
+
});
|
|
17
|
+
const nominatimAPI = 'https://nominatim.openstreetmap.org';
|
|
18
|
+
describe('MyTimezone', () => {
|
|
19
|
+
const tz = new MyTimezone({
|
|
20
|
+
offline: true,
|
|
21
|
+
});
|
|
22
|
+
let formatted_address;
|
|
23
|
+
nock(nominatimAPI)
|
|
24
|
+
.get('/search')
|
|
25
|
+
.query(queryObject => {
|
|
26
|
+
formatted_address = queryObject.q;
|
|
27
|
+
return true;
|
|
28
|
+
})
|
|
29
|
+
.reply(() => [
|
|
30
|
+
200,
|
|
31
|
+
[
|
|
32
|
+
{
|
|
33
|
+
boundingbox: ['52.3570365', '52.6770365', '13.2288599', '13.5488599'],
|
|
34
|
+
class: 'place',
|
|
35
|
+
display_name: formatted_address,
|
|
36
|
+
icon: 'https://nominatim.openstreetmap.org/images/mapicons/poi_place_city.p.20.png',
|
|
37
|
+
importance: 1.007539028249136,
|
|
38
|
+
lat: '52.5170365',
|
|
39
|
+
licence: 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright',
|
|
40
|
+
lon: '13.3888599',
|
|
41
|
+
osm_id: 240109189,
|
|
42
|
+
osm_type: 'node',
|
|
43
|
+
place_id: 595794,
|
|
44
|
+
type: 'city',
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
])
|
|
48
|
+
.persist();
|
|
49
|
+
test('returns an address from Nominatim', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
50
|
+
const location = 'Berlin, Germany';
|
|
51
|
+
const { formattedAddress } = yield tz.getLocationByName(location);
|
|
52
|
+
expect(formattedAddress).toBe(location);
|
|
53
|
+
}));
|
|
54
|
+
test('returns the correct time for a location', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
|
+
const berlinTime = yield tz.getDateByLongitude(13.40803);
|
|
56
|
+
//console.log('Timezone at 52.51848, 13.40803:', berlinTime.toString());
|
|
57
|
+
const frankfurtTime = yield tz.getDateByLongitude(8.67931);
|
|
58
|
+
//console.log('Timezone at 50.11796, 8.67931:', frankfurtTime.toString());
|
|
59
|
+
expect(frankfurtTime.getTime() < berlinTime.getTime()).toBe(true);
|
|
60
|
+
}));
|
|
61
|
+
test('returns the time for an address', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
62
|
+
const dataBerlin = yield tz.getDateByAddress('Berlin, Germany');
|
|
63
|
+
expect(dataBerlin).toBeDefined();
|
|
64
|
+
//console.log('Timezone Berlin:', dataBerlin.toString());
|
|
65
|
+
const dataMinsk = yield tz.getDateByAddress('Minsk, Belarus');
|
|
66
|
+
expect(dataMinsk).toBeDefined();
|
|
67
|
+
//console.log('Timezone Minsk:', dataMinsk.toString());
|
|
68
|
+
}));
|
|
69
|
+
});
|
|
70
|
+
//# sourceMappingURL=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4
|
+
import { MyTimezone } from './MyTimezone.js';
|
|
5
|
+
vi.setConfig({
|
|
6
|
+
testTimeout: 10 * 1000, // 10 seconds
|
|
7
|
+
});
|
|
8
|
+
const nominatimAPI = 'https://nominatim.openstreetmap.org';
|
|
9
|
+
describe('MyTimezone', () => {
|
|
10
|
+
const tz = new MyTimezone({
|
|
11
|
+
offline: true,
|
|
12
|
+
});
|
|
13
|
+
let formatted_address;
|
|
14
|
+
nock(nominatimAPI)
|
|
15
|
+
.get('/search')
|
|
16
|
+
.query(queryObject => {
|
|
17
|
+
formatted_address = queryObject.q;
|
|
18
|
+
return true;
|
|
19
|
+
})
|
|
20
|
+
.reply(() => [
|
|
21
|
+
200,
|
|
22
|
+
[
|
|
23
|
+
{
|
|
24
|
+
boundingbox: ['52.3570365', '52.6770365', '13.2288599', '13.5488599'],
|
|
25
|
+
class: 'place',
|
|
26
|
+
display_name: formatted_address,
|
|
27
|
+
icon: 'https://nominatim.openstreetmap.org/images/mapicons/poi_place_city.p.20.png',
|
|
28
|
+
importance: 1.007539028249136,
|
|
29
|
+
lat: '52.5170365',
|
|
30
|
+
licence: 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright',
|
|
31
|
+
lon: '13.3888599',
|
|
32
|
+
osm_id: 240109189,
|
|
33
|
+
osm_type: 'node',
|
|
34
|
+
place_id: 595794,
|
|
35
|
+
type: 'city',
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
])
|
|
39
|
+
.persist();
|
|
40
|
+
test('returns an address from Nominatim', async () => {
|
|
41
|
+
const location = 'Berlin, Germany';
|
|
42
|
+
const { formattedAddress } = await tz.getLocationByName(location);
|
|
43
|
+
expect(formattedAddress).toBe(location);
|
|
44
|
+
});
|
|
45
|
+
test('returns the correct time for a location', async () => {
|
|
46
|
+
const berlinTime = await tz.getDateByLongitude(13.40803);
|
|
47
|
+
//console.log('Timezone at 52.51848, 13.40803:', berlinTime.toString());
|
|
48
|
+
const frankfurtTime = await tz.getDateByLongitude(8.67931);
|
|
49
|
+
//console.log('Timezone at 50.11796, 8.67931:', frankfurtTime.toString());
|
|
50
|
+
expect(frankfurtTime.getTime() < berlinTime.getTime()).toBe(true);
|
|
51
|
+
});
|
|
52
|
+
test('returns the time for an address', async () => {
|
|
53
|
+
const dataBerlin = await tz.getDateByAddress('Berlin, Germany');
|
|
54
|
+
expect(dataBerlin).toBeDefined();
|
|
55
|
+
//console.log('Timezone Berlin:', dataBerlin.toString());
|
|
56
|
+
const dataMinsk = await tz.getDateByAddress('Minsk, Belarus');
|
|
57
|
+
expect(dataMinsk).toBeDefined();
|
|
58
|
+
//console.log('Timezone Minsk:', dataMinsk.toString());
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
//# sourceMappingURL=MyTimezone.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MyTimezone.test.js","sourceRoot":"","sources":["../../src/MyTimezone.test.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,OAAO,EAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,EAAC,MAAM,QAAQ,CAAC;AAClD,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAC,UAAU,EAAC,MAAM,iBAAiB,CAAC;AAE3C,EAAE,CAAC,SAAS,CAAC;IACX,WAAW,EAAE,EAAE,GAAG,IAAI,EAAE,aAAa;CACtC,CAAC,CAAC;AACH,MAAM,YAAY,GAAG,qCAAqC,CAAC;AAE3D,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;IAC1B,MAAM,EAAE,GAAG,IAAI,UAAU,CAAC;QACxB,OAAO,EAAE,IAAI;KACd,CAAC,CAAC;IACH,IAAI,iBAAyB,CAAC;IAE9B,IAAI,CAAC,YAAY,CAAC;SACf,GAAG,CAAC,SAAS,CAAC;SACd,KAAK,CAAC,WAAW,CAAC,EAAE;QACnB,iBAAiB,GAAG,WAAW,CAAC,CAAW,CAAC;QAC5C,OAAO,IAAI,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B,CAAC,iBAAiB,CAAC,CAAC;QAChE,MAAM,CAAC,UAAU,CAAC,CAAC,WAAW,EAAE,CAAC;QACjC,yDAAyD;QAEzD,MAAM,SAAS,GAAG,MAAM,EAAE,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;QAC9D,MAAM,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,CAAC;QAChC,uDAAuD;IACzD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "Florian Imdahl <git@ffflorian.de>",
|
|
3
|
-
"bin":
|
|
4
|
-
"my-timezone": "dist/cjs/cli.js"
|
|
5
|
-
},
|
|
3
|
+
"bin": "dist/cjs/cli.js",
|
|
6
4
|
"dependencies": {
|
|
7
5
|
"commander": "11.1.0",
|
|
8
|
-
"ntpclient": "1.5.
|
|
6
|
+
"ntpclient": "1.5.2"
|
|
9
7
|
},
|
|
10
8
|
"description": "Get the exact time based on your location.",
|
|
11
9
|
"devDependencies": {
|
|
12
|
-
"axios": "1.6.
|
|
13
|
-
"nock": "13.3.
|
|
10
|
+
"axios": "1.6.2",
|
|
11
|
+
"nock": "13.3.8",
|
|
14
12
|
"rimraf": "5.0.5",
|
|
15
13
|
"typescript": "5.2.2"
|
|
16
14
|
},
|
|
@@ -39,9 +37,9 @@
|
|
|
39
37
|
"dist": "yarn clean && yarn build",
|
|
40
38
|
"generate:packagejson": "../../bin/generate-hybrid-package-json.sh",
|
|
41
39
|
"start": "ts-node-esm src/cli.ts",
|
|
42
|
-
"test": "
|
|
40
|
+
"test": "vitest run"
|
|
43
41
|
},
|
|
44
42
|
"type": "module",
|
|
45
|
-
"version": "1.4.
|
|
46
|
-
"gitHead": "
|
|
43
|
+
"version": "1.4.2",
|
|
44
|
+
"gitHead": "f5134e8663185ed1ff19e0291a7a2da86c0aa39e"
|
|
47
45
|
}
|