@angelrove/forecast-utils 1.1.4 → 1.1.5

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 CHANGED
@@ -1,8 +1,6 @@
1
1
  ## Modules
2
2
 
3
3
  <dl>
4
- <dt><a href="#module_Astronomy">Astronomy</a></dt>
5
- <dd></dd>
6
4
  <dt><a href="#module_Astronomy/MoonCalc">Astronomy/MoonCalc</a></dt>
7
5
  <dd><p>MoonCalc for calculating moon times, positions, and phases.</p>
8
6
  <p> import { MoonCalc } from ...</p>
@@ -16,6 +14,8 @@
16
14
  ¡Solo proporcionar HORA LOCAL DEL SISTEMA!: &#39;new Date()&#39;
17
15
  Con excepción de &#39;getSolarTime()&#39;: recibe la hora local correspondiente a la localización dada.</p>
18
16
  </dd>
17
+ <dt><a href="#module_Astronomy/helpers">Astronomy/helpers</a></dt>
18
+ <dd></dd>
19
19
  <dt><a href="#module_Geolocation">Geolocation</a></dt>
20
20
  <dd></dd>
21
21
  <dt><a href="#module_OpenMeteo">OpenMeteo</a></dt>
@@ -24,137 +24,6 @@ Con excepción de &#39;getSolarTime()&#39;: recibe la hora local correspondiente
24
24
  <dd></dd>
25
25
  </dl>
26
26
 
27
- <a name="module_Astronomy"></a>
28
-
29
- ## Astronomy
30
-
31
- * [Astronomy](#module_Astronomy)
32
- * [.exports.timeString([date], [sec])](#module_Astronomy.exports.timeString) ⇒ <code>string</code>
33
- * [.exports.nowString(sec)](#module_Astronomy.exports.nowString) ⇒ <code>String</code>
34
- * [.exports.dateFormat([date])](#module_Astronomy.exports.dateFormat) ⇒ <code>string</code>
35
- * [.exports.getLocalTimeFromTz(timeZone, [date])](#module_Astronomy.exports.getLocalTimeFromTz) ⇒ <code>string</code>
36
- * [.exports.getLocalTimeInfo(apiKey, lat, lng)](#module_Astronomy.exports.getLocalTimeInfo) ⇒ <code>Promise.&lt;(any\|LocalTimeData)&gt;</code>
37
- * [.AstroPosition](#module_Astronomy.AstroPosition) : <code>Object</code>
38
- * [.LocalTimeData](#module_Astronomy.LocalTimeData) : <code>Object</code>
39
-
40
-
41
- * * *
42
-
43
- <a name="module_Astronomy.exports.timeString"></a>
44
-
45
- ### Astronomy.exports.timeString([date], [sec]) ⇒ <code>string</code>
46
- Formatea una fecha a un string legible.
47
-
48
- **Kind**: static method of [<code>Astronomy</code>](#module_Astronomy)
49
- **Returns**: <code>string</code> - La fecha formateada.
50
-
51
- | Param | Type | Default |
52
- | --- | --- | --- |
53
- | [date] | <code>Date</code> | |
54
- | [sec] | <code>boolean</code> | <code>false</code> |
55
-
56
-
57
- * * *
58
-
59
- <a name="module_Astronomy.exports.nowString"></a>
60
-
61
- ### Astronomy.exports.nowString(sec) ⇒ <code>String</code>
62
- **Kind**: static method of [<code>Astronomy</code>](#module_Astronomy)
63
-
64
- | Param | Type |
65
- | --- | --- |
66
- | sec | <code>boolean</code> |
67
-
68
-
69
- * * *
70
-
71
- <a name="module_Astronomy.exports.dateFormat"></a>
72
-
73
- ### Astronomy.exports.dateFormat([date]) ⇒ <code>string</code>
74
- Formatea una fecha a un string legible.
75
-
76
- **Kind**: static method of [<code>Astronomy</code>](#module_Astronomy)
77
- **Returns**: <code>string</code> - La fecha formateada.
78
-
79
- | Param | Type | Default | Description |
80
- | --- | --- | --- | --- |
81
- | [date] | <code>Date</code> | <code>new Date()</code> | La fecha a formatear. |
82
-
83
-
84
- * * *
85
-
86
- <a name="module_Astronomy.exports.getLocalTimeFromTz"></a>
87
-
88
- ### Astronomy.exports.getLocalTimeFromTz(timeZone, [date]) ⇒ <code>string</code>
89
- Get local time from timezone
90
-
91
- **Kind**: static method of [<code>Astronomy</code>](#module_Astronomy)
92
- **Returns**: <code>string</code> - - The formatted local time string.
93
-
94
- | Param | Type | Default | Description |
95
- | --- | --- | --- | --- |
96
- | timeZone | <code>string</code> | | The timezone string (e.g., 'America/New_York'). |
97
- | [date] | <code>Date</code> \| <code>number</code> | <code>new Date()</code> | The date object to format. Defaults to the current date. |
98
-
99
-
100
- * * *
101
-
102
- <a name="module_Astronomy.exports.getLocalTimeInfo"></a>
103
-
104
- ### Astronomy.exports.getLocalTimeInfo(apiKey, lat, lng) ⇒ <code>Promise.&lt;(any\|LocalTimeData)&gt;</code>
105
- Get local time from any location using Google Maps TimeZone API.
106
-
107
- **Kind**: static method of [<code>Astronomy</code>](#module_Astronomy)
108
- **Returns**: <code>Promise.&lt;(any\|LocalTimeData)&gt;</code> - - An object containing the local time and timezone information:
109
- **Throws**:
110
-
111
- - <code>Error</code> - If the API request fails or returns an error status.
112
-
113
-
114
- | Param | Type | Description |
115
- | --- | --- | --- |
116
- | apiKey | <code>string</code> | GoogleMaps API key. |
117
- | lat | <code>number</code> | |
118
- | lng | <code>number</code> | |
119
-
120
-
121
- * * *
122
-
123
- <a name="module_Astronomy.AstroPosition"></a>
124
-
125
- ### Astronomy.AstroPosition : <code>Object</code>
126
- **Kind**: static typedef of [<code>Astronomy</code>](#module_Astronomy)
127
- **Properties**
128
-
129
- | Name | Type |
130
- | --- | --- |
131
- | altitude | <code>number</code> |
132
- | azimuth | <code>number</code> |
133
- | direction | <code>string</code> |
134
- | direction_full | <code>string</code> |
135
-
136
-
137
- * * *
138
-
139
- <a name="module_Astronomy.LocalTimeData"></a>
140
-
141
- ### Astronomy.LocalTimeData : <code>Object</code>
142
- **Kind**: static typedef of [<code>Astronomy</code>](#module_Astronomy)
143
- **Properties**
144
-
145
- | Name | Type | Description |
146
- | --- | --- | --- |
147
- | time | <code>Date</code> | The local time. |
148
- | timeStr | <code>string</code> | The formatted local time string. |
149
- | timezone | <code>string</code> | The timezone name. |
150
- | timezoneId | <code>string</code> | The timezone ID. |
151
- | offset | <code>number</code> | The UTC offset in hours. |
152
- | offsetSign | <code>string</code> | The sign of the offset ('+' or '-'). |
153
- | dstOffset | <code>number</code> | The DST offset in hours. |
154
-
155
-
156
- * * *
157
-
158
27
  <a name="module_Astronomy/MoonCalc"></a>
159
28
 
160
29
  ## Astronomy/MoonCalc
@@ -392,6 +261,100 @@ Con excepción de 'getSolarTime()': recibe la hora local correspondiente a la lo
392
261
  | noon | <code>string</code> |
393
262
 
394
263
 
264
+ * * *
265
+
266
+ <a name="module_Astronomy/helpers"></a>
267
+
268
+ ## Astronomy/helpers
269
+
270
+ * [Astronomy/helpers](#module_Astronomy/helpers)
271
+ * [.exports.timeString([date], [sec])](#module_Astronomy/helpers.exports.timeString) ⇒ <code>string</code>
272
+ * [.exports.nowString(sec)](#module_Astronomy/helpers.exports.nowString) ⇒ <code>String</code>
273
+ * [.exports.dateFormat([date])](#module_Astronomy/helpers.exports.dateFormat) ⇒ <code>string</code>
274
+ * [.exports.getLocalTimeFromTz(timeZone, [date])](#module_Astronomy/helpers.exports.getLocalTimeFromTz) ⇒ <code>string</code>
275
+ * [.exports.getLocalTimeInfo(apiKey, lat, lng)](#module_Astronomy/helpers.exports.getLocalTimeInfo) ⇒ <code>Promise.&lt;(any\|LocalTimeData)&gt;</code>
276
+
277
+
278
+ * * *
279
+
280
+ <a name="module_Astronomy/helpers.exports.timeString"></a>
281
+
282
+ ### Astronomy/helpers.exports.timeString([date], [sec]) ⇒ <code>string</code>
283
+ Formatea una fecha a un string legible.
284
+
285
+ **Kind**: static method of [<code>Astronomy/helpers</code>](#module_Astronomy/helpers)
286
+ **Returns**: <code>string</code> - La fecha formateada.
287
+
288
+ | Param | Type | Default |
289
+ | --- | --- | --- |
290
+ | [date] | <code>Date</code> | |
291
+ | [sec] | <code>boolean</code> | <code>false</code> |
292
+
293
+
294
+ * * *
295
+
296
+ <a name="module_Astronomy/helpers.exports.nowString"></a>
297
+
298
+ ### Astronomy/helpers.exports.nowString(sec) ⇒ <code>String</code>
299
+ **Kind**: static method of [<code>Astronomy/helpers</code>](#module_Astronomy/helpers)
300
+
301
+ | Param | Type |
302
+ | --- | --- |
303
+ | sec | <code>boolean</code> |
304
+
305
+
306
+ * * *
307
+
308
+ <a name="module_Astronomy/helpers.exports.dateFormat"></a>
309
+
310
+ ### Astronomy/helpers.exports.dateFormat([date]) ⇒ <code>string</code>
311
+ Formatea una fecha a un string legible.
312
+
313
+ **Kind**: static method of [<code>Astronomy/helpers</code>](#module_Astronomy/helpers)
314
+ **Returns**: <code>string</code> - La fecha formateada.
315
+
316
+ | Param | Type | Default | Description |
317
+ | --- | --- | --- | --- |
318
+ | [date] | <code>Date</code> | <code>new Date()</code> | La fecha a formatear. |
319
+
320
+
321
+ * * *
322
+
323
+ <a name="module_Astronomy/helpers.exports.getLocalTimeFromTz"></a>
324
+
325
+ ### Astronomy/helpers.exports.getLocalTimeFromTz(timeZone, [date]) ⇒ <code>string</code>
326
+ Get local time from timezone
327
+
328
+ **Kind**: static method of [<code>Astronomy/helpers</code>](#module_Astronomy/helpers)
329
+ **Returns**: <code>string</code> - - The formatted local time string.
330
+
331
+ | Param | Type | Default | Description |
332
+ | --- | --- | --- | --- |
333
+ | timeZone | <code>string</code> | | The timezone string (e.g., 'America/New_York'). |
334
+ | [date] | <code>Date</code> \| <code>number</code> | <code>new Date()</code> | The date object to format. Defaults to the current date. |
335
+
336
+
337
+ * * *
338
+
339
+ <a name="module_Astronomy/helpers.exports.getLocalTimeInfo"></a>
340
+
341
+ ### Astronomy/helpers.exports.getLocalTimeInfo(apiKey, lat, lng) ⇒ <code>Promise.&lt;(any\|LocalTimeData)&gt;</code>
342
+ Get local time from any location using Google Maps TimeZone API.
343
+
344
+ **Kind**: static method of [<code>Astronomy/helpers</code>](#module_Astronomy/helpers)
345
+ **Returns**: <code>Promise.&lt;(any\|LocalTimeData)&gt;</code> - - An object containing the local time and timezone information:
346
+ **Throws**:
347
+
348
+ - <code>Error</code> - If the API request fails or returns an error status.
349
+
350
+
351
+ | Param | Type | Description |
352
+ | --- | --- | --- |
353
+ | apiKey | <code>string</code> | GoogleMaps API key. |
354
+ | lat | <code>number</code> | |
355
+ | lng | <code>number</code> | |
356
+
357
+
395
358
  * * *
396
359
 
397
360
  <a name="module_Geolocation"></a>
@@ -1,4 +1,2 @@
1
1
  export { default as MoonCalc } from "./moon/MoonCalc.js";
2
2
  export { default as SunCalc } from "./sun/SunCalc.js";
3
- export { getLocalTimeInfo as getLocalTime } from "./timeZoneInfo.js";
4
- export { dateFormat, getLocalTimeFromTz, nowString, timeString } from "./timehelpers.js";
@@ -1 +1,2 @@
1
1
  export { getGeolocation } from "./getGeolocation.js";
2
+ export { timeFromLocation } from "./timeFromLocation.js";
@@ -1,11 +1,11 @@
1
1
  /**
2
- * Get local time from any location using Google Maps TimeZone API.
2
+ * Get local time from a given location (lat, lng) using 'GoogleMaps TimeZone' API.
3
3
  *
4
4
  * @param {string} apiKey - GoogleMaps API key.
5
5
  * @param {number} lat
6
6
  * @param {number} lng
7
7
  * @returns {Promise<any | LocalTimeData>} - An object containing the local time and timezone information:
8
8
  * @throws {Error} - If the API request fails or returns an error status.
9
- * @memberof module:Astronomy
9
+ * @memberof module:Geolocation
10
10
  */
11
- export function getLocalTimeInfo(apiKey: string, lat: number, lng: number): Promise<any | LocalTimeData>;
11
+ export function timeFromLocation(apiKey: string, lat: number, lng: number): Promise<any | LocalTimeData>;
@@ -1,6 +1,7 @@
1
1
  export { default as MoonCalc } from "./astronomy/moon/MoonCalc.js";
2
2
  export { default as SunCalc } from "./astronomy/sun/SunCalc.js";
3
- export { getLocalTimeInfo as getLocalTime } from "./astronomy/timeZoneInfo.js";
3
+ export { timeFromLocation } from "./geolocation/timeFromLocation.js";
4
+ export { default as TimeDateStr } from "./utils/timehelpers.js";
4
5
  export { getGeolocation } from "./geolocation/getGeolocation.js";
5
6
  export { useForecastCurrent } from "./OpenMeteo/current/useForecastCurrent.js";
6
7
  export { useForecastDaily } from "./OpenMeteo/daily/useForecastDaily.js";
@@ -10,5 +11,4 @@ export { degreesToCompass } from "./utils/degreesToCompass.js";
10
11
  export { WindArrow } from "./utils/wind/WindArrow.jsx";
11
12
  export { windArrowTx } from "./utils/wind/windArrowTx.js";
12
13
  export { getWindLevel } from "./utils/wind/windLevel.js";
13
- export { dateFormat, getLocalTimeFromTz, nowString, timeString } from "./astronomy/timehelpers.js";
14
14
  export { getWarning, getWarningByDays } from "./utils/warning.js";
@@ -1,4 +1,5 @@
1
1
  export { degreesToCompass } from "./degreesToCompass.js";
2
+ export { default as TimeDateStr } from "./timehelpers.js";
2
3
  export { WindArrow } from "./wind/WindArrow.jsx";
3
4
  export { windArrowTx } from "./wind/windArrowTx.js";
4
5
  export { getWindLevel } from "./wind/windLevel.js";
@@ -0,0 +1,41 @@
1
+ export default TimeDateStr;
2
+ declare namespace TimeDateStr {
3
+ export { dateFormat };
4
+ export { nowString };
5
+ export { timeString };
6
+ export { getLocalTimeFromTz };
7
+ }
8
+ /**
9
+ * Returns a date as a formated string.
10
+ *
11
+ * @param {Date} [date=new Date()] La fecha a formatear.
12
+ * @returns {string} La fecha formateada.
13
+ * @memberof module:Utils
14
+ */
15
+ declare function dateFormat(date?: Date | undefined): string;
16
+ /**
17
+ * Returns a now time as a formated string.
18
+ *
19
+ * @param {boolean} sec
20
+ * @returns {String}
21
+ * @memberof module:Utils
22
+ */
23
+ declare function nowString(sec?: boolean): string;
24
+ /**
25
+ * Returns a time as a formated string.
26
+ *
27
+ * @param {Date} [date]
28
+ * @param {boolean} [sec=false]
29
+ * @returns {string} La fecha formateada.
30
+ * @memberof module:Utils
31
+ */
32
+ declare function timeString(date?: Date | undefined, sec?: boolean | undefined): string;
33
+ /**
34
+ * Return the local time string from a given timezone.
35
+ *
36
+ * @param {string} timeZone - The timezone string (e.g., 'America/New_York').
37
+ * @param {Date | number} [date=new Date()] - The date object to format. Defaults to the current date.
38
+ * @returns {string} - The formatted local time string.
39
+ * @memberof module:Utils
40
+ */
41
+ declare function getLocalTimeFromTz(timeZone: string, date?: number | Date | undefined): string;
package/package.json CHANGED
@@ -1,9 +1,12 @@
1
1
  {
2
- "name": "@angelrove/forecast-utils",
3
- "version": "1.1.4",
4
2
  "author": "Jose Angel Romero Vegas",
5
- "license": "MIT",
3
+ "name": "@angelrove/forecast-utils",
4
+ "version": "1.1.5",
6
5
  "description": "Utilities for obtaining weather and astronomy forecast data.",
6
+ "license": "MIT",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
7
10
  "homepage": "https://github.com/angelrove/forecast-utils",
8
11
  "type": "module",
9
12
  "scripts": {
@@ -12,8 +15,7 @@
12
15
  "types": "dist/types/index.d.ts",
13
16
  "exports": {
14
17
  ".": {
15
- "import": "./src/index.js",
16
- "require": "./src/index.js"
18
+ "import": "./src/index.js"
17
19
  }
18
20
  },
19
21
  "files": [
@@ -1,13 +1,2 @@
1
- /**
2
- * @module Astronomy
3
- */
4
-
5
1
  export { default as MoonCalc } from "./moon/MoonCalc.js";
6
2
  export { default as SunCalc } from "./sun/SunCalc.js";
7
- export {
8
- dateFormat,
9
- getLocalTimeFromTz,
10
- nowString,
11
- timeString,
12
- } from "./timehelpers.js";
13
- export { getLocalTimeInfo as getLocalTime } from "./timeZoneInfo.js";
@@ -12,7 +12,7 @@
12
12
 
13
13
  // @ts-ignore
14
14
  import SunCalc from "suncalc3";
15
- import { dateFormat, getLocalTimeFromTz, timeString } from "../timehelpers.js";
15
+ import TimeDateStr from "../../utils/timehelpers.js";
16
16
  import { parseBasicData } from "./parseBasicData.js";
17
17
 
18
18
  /**
@@ -105,8 +105,8 @@ function dataExt(latitude, longitude, date = new Date(), language = "es-ES") {
105
105
 
106
106
  // Return ---
107
107
  return {
108
- date: dateFormat(date),
109
- time: timeString(date),
108
+ date: TimeDateStr.dateFormat(date),
109
+ time: TimeDateStr.timeString(date),
110
110
  illumination: illumination,
111
111
  phase: phase,
112
112
  phaseId: phaseId,
@@ -160,9 +160,9 @@ function times(latitude, longitude, timezoneId, date = new Date()) {
160
160
  return ret;
161
161
  }
162
162
 
163
- ret.rise = getLocalTimeFromTz(timezoneId, times.rise);
164
- ret.set = getLocalTimeFromTz(timezoneId, times.set);
165
- ret.highest = getLocalTimeFromTz(timezoneId, times.highest);
163
+ ret.rise = TimeDateStr.getLocalTimeFromTz(timezoneId, times.rise);
164
+ ret.set = TimeDateStr.getLocalTimeFromTz(timezoneId, times.set);
165
+ ret.highest = TimeDateStr.getLocalTimeFromTz(timezoneId, times.highest);
166
166
  return ret;
167
167
  }
168
168
  //--------------------------------------------------------------------
@@ -1,6 +1,6 @@
1
1
  // @ts-nocheck
2
2
  import { degreesToCompass } from "../../utils/degreesToCompass.js";
3
- import { dateFormat } from "../timehelpers.js";
3
+ import TimeDateStr from "../../utils/timehelpers.js";
4
4
 
5
5
  /**
6
6
  * Parse basic data from SunCalc
@@ -17,10 +17,10 @@ export function parseBasicData(data, language) {
17
17
  const direction = degreesToCompass(data.azimuthDegrees, language);
18
18
 
19
19
  // Next moon ---
20
- const nextNewMoon = dateFormat(
20
+ const nextNewMoon = TimeDateStr.dateFormat(
21
21
  new Date(data.illumination.next.newMoon.value),
22
22
  );
23
- const nextFullMoon = dateFormat(
23
+ const nextFullMoon = TimeDateStr.dateFormat(
24
24
  new Date(data.illumination.next.fullMoon.value),
25
25
  );
26
26
 
@@ -13,12 +13,7 @@
13
13
  // @ts-ignore
14
14
  import { default as SunCalc3 } from "suncalc3";
15
15
  import { degreesToCompass } from "../../utils/degreesToCompass.js";
16
- import {
17
- dateFormat,
18
- getLocalTimeFromTz,
19
- nowString,
20
- timeString,
21
- } from "../timehelpers.js";
16
+ import TimeDateStr from "../../utils/timehelpers.js";
22
17
 
23
18
  /**
24
19
  * SunCalc.
@@ -69,11 +64,14 @@ function times(date, latitude, longitude, timezoneId) {
69
64
 
70
65
  const sunTimes = {
71
66
  date: date,
72
- sunrise: getLocalTimeFromTz(timezoneId, times.sunriseStart.value),
73
- sunset: getLocalTimeFromTz(timezoneId, times.sunsetStart.value),
74
- noon: getLocalTimeFromTz(timezoneId, times.solarNoon.value),
75
- dawn: getLocalTimeFromTz(timezoneId, times.civilDawn.value),
76
- dusk: getLocalTimeFromTz(timezoneId, times.civilDusk.value),
67
+ sunrise: TimeDateStr.getLocalTimeFromTz(
68
+ timezoneId,
69
+ times.sunriseStart.value,
70
+ ),
71
+ sunset: TimeDateStr.getLocalTimeFromTz(timezoneId, times.sunsetStart.value),
72
+ noon: TimeDateStr.getLocalTimeFromTz(timezoneId, times.solarNoon.value),
73
+ dawn: TimeDateStr.getLocalTimeFromTz(timezoneId, times.civilDawn.value),
74
+ dusk: TimeDateStr.getLocalTimeFromTz(timezoneId, times.civilDusk.value),
77
75
  };
78
76
 
79
77
  // console.log(sunTimes);
@@ -92,7 +90,7 @@ function getSolarTime(date, lng, offsetSign, offset) {
92
90
  // Convert offsetSign and offset to a numeric UTC offset (e.g., -3, +2)
93
91
  const utcOffset = (offsetSign === "-" ? -1 : 1) * Math.abs(Number(offset));
94
92
  const solarTime = SunCalc3.getSolarTime(date, lng, utcOffset);
95
- return timeString(solarTime);
93
+ return TimeDateStr.timeString(solarTime);
96
94
  }
97
95
  //-------------------------------------------------------
98
96
  /**
@@ -108,7 +106,7 @@ function position(latitude, longitude, date = new Date(), language = "es-ES") {
108
106
  const direction = degreesToCompass(position.azimuthDegrees, language);
109
107
 
110
108
  return {
111
- date: dateFormat(date),
109
+ date: TimeDateStr.dateFormat(date),
112
110
  azimuth: position.azimuthDegrees,
113
111
  direction: direction.short,
114
112
  direction_full: direction.full,
@@ -134,8 +132,11 @@ function getIsNight(lat, lon, timezoneId, date, dateStr) {
134
132
 
135
133
  // se pueden comparar horas(hh:mm) estando en formato texto
136
134
  // y así no tenemos que tener en cuenta el día, mes.
137
- const timeUp = getLocalTimeFromTz(timezoneId, times.sunriseEnd.value);
138
- const timeDown = getLocalTimeFromTz(
135
+ const timeUp = TimeDateStr.getLocalTimeFromTz(
136
+ timezoneId,
137
+ times.sunriseEnd.value,
138
+ );
139
+ const timeDown = TimeDateStr.getLocalTimeFromTz(
139
140
  timezoneId,
140
141
  times.goldenHourDuskStart.value,
141
142
  );
@@ -150,7 +151,7 @@ function getIsNight(lat, lon, timezoneId, date, dateStr) {
150
151
  * @memberof module:Astronomy/SunCalc
151
152
  */
152
153
  function getPhase(altitude, noon) {
153
- const nowTime = nowString();
154
+ const nowTime = TimeDateStr.nowString();
154
155
 
155
156
  let phase = "day";
156
157
  if (altitude < 4) {
@@ -1,7 +1,3 @@
1
- /**
2
- * Get the current geolocation of the device and reverse geocode it to get the address.
3
- */
4
-
5
1
  import geolocationCapacitor from "./lib/geolocation.js";
6
2
  import reverseGeocoding from "./lib/reversegeocoding.js";
7
3
 
@@ -3,3 +3,4 @@
3
3
  */
4
4
 
5
5
  export { getGeolocation } from "./getGeolocation.js";
6
+ export { timeFromLocation } from "./timeFromLocation.js";
@@ -30,12 +30,16 @@ export default async function geolocation() {
30
30
  };
31
31
  } catch (error) {
32
32
  console.error(error);
33
+
34
+ // @ts-ignore
33
35
  if (error.code === error.PERMISSION_DENIED) {
34
36
  throw new Error("Geolocation: permission denied");
35
37
  }
38
+ // @ts-ignore
36
39
  if (error.code === error.POSITION_UNAVAILABLE) {
37
40
  throw new Error("Geolocation: position unavailable");
38
41
  }
42
+ // @ts-ignore
39
43
  if (error.code === error.TIMEOUT) {
40
44
  throw new Error("Geolocation: timeout");
41
45
  }
@@ -1,24 +1,18 @@
1
1
  // @ts-nocheck
2
- /**
3
- * Get local time from any location using Google Maps TimeZone API.
4
- * - import { getLocalTimeInfo } from '@angelrov/forecast';
5
- *
6
- */
7
-
8
- import { timeString } from "./timehelpers.js";
2
+ import TimeDateStr from "../utils/timehelpers.js";
9
3
 
10
4
  //------------------------------------------------------
11
5
  /**
12
- * Get local time from any location using Google Maps TimeZone API.
6
+ * Get local time from a given location (lat, lng) using 'GoogleMaps TimeZone' API.
13
7
  *
14
8
  * @param {string} apiKey - GoogleMaps API key.
15
9
  * @param {number} lat
16
10
  * @param {number} lng
17
11
  * @returns {Promise<any | LocalTimeData>} - An object containing the local time and timezone information:
18
12
  * @throws {Error} - If the API request fails or returns an error status.
19
- * @memberof module:Astronomy
13
+ * @memberof module:Geolocation
20
14
  */
21
- export async function getLocalTimeInfo(apiKey, lat, lng) {
15
+ export async function timeFromLocation(apiKey, lat, lng) {
22
16
  const timestamp = Math.floor(Date.now() / 1000);
23
17
  const url =
24
18
  "https://maps.googleapis.com/maps/api/timezone/json?" +
@@ -45,6 +39,8 @@ export async function getLocalTimeInfo(apiKey, lat, lng) {
45
39
  });
46
40
  }
47
41
  //------------------------------------------------------
42
+ // Private
43
+ //------------------------------------------------------
48
44
  /**
49
45
  * @private
50
46
  * @param {Object} timezoneInfo - The timezone Google API information.
@@ -64,7 +60,7 @@ function getLocalTimeData(timezoneInfo) {
64
60
 
65
61
  return {
66
62
  time: time,
67
- timeStr: timeString(time),
63
+ timeStr: TimeDateStr.timeString(time),
68
64
  timezone: timezoneInfo.timeZoneName,
69
65
  timezoneId: timezoneInfo.timeZoneId,
70
66
  offset: timezoneInfo.rawOffset / 3600,
@@ -81,7 +77,7 @@ function getLocalTimeDataErr() {
81
77
  const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
82
78
  return {
83
79
  time: new Date(),
84
- timeStr: timeString(new Date()),
80
+ timeStr: TimeDateStr.timeString(new Date()),
85
81
  timezone: timezone,
86
82
  timezoneId: timezone,
87
83
  offset: 0,
package/src/index.js CHANGED
@@ -12,13 +12,8 @@
12
12
  // Astronomy
13
13
  export { default as MoonCalc } from "./astronomy/moon/MoonCalc.js";
14
14
  export { default as SunCalc } from "./astronomy/sun/SunCalc.js";
15
- export {
16
- dateFormat,
17
- getLocalTimeFromTz,
18
- nowString,
19
- timeString,
20
- } from "./astronomy/timehelpers.js";
21
- export { getLocalTimeInfo as getLocalTime } from "./astronomy/timeZoneInfo.js";
15
+ export { timeFromLocation } from "./geolocation/timeFromLocation.js";
16
+ export { default as TimeDateStr } from "./utils/timehelpers.js";
22
17
 
23
18
  // Geolocation
24
19
  export { getGeolocation } from "./geolocation/getGeolocation.js";
@@ -3,6 +3,7 @@
3
3
  */
4
4
 
5
5
  export { degreesToCompass } from "./degreesToCompass.js";
6
+ export { default as TimeDateStr } from "./timehelpers.js";
6
7
  export { getWarning, getWarningByDays } from "./warning.js";
7
8
  export { WindArrow } from "./wind/WindArrow.jsx";
8
9
  export { windArrowTx } from "./wind/windArrowTx.js";
@@ -1,13 +1,47 @@
1
+ /**
2
+ * Helpers for get date and time formeted strings
3
+ *
4
+ */
5
+
6
+ /**
7
+ * TimeDateStr.
8
+ * @ignore
9
+ */
10
+ const TimeDateStr = {
11
+ dateFormat,
12
+ nowString,
13
+ timeString,
14
+ getLocalTimeFromTz,
15
+ };
16
+ export default TimeDateStr;
17
+
1
18
  //------------------------------------------------------
2
19
  /**
3
- * Formatea una fecha a un string legible.
20
+ * Returns a date as a formated string.
21
+ *
22
+ * @param {Date} [date=new Date()] La fecha a formatear.
23
+ * @returns {string} La fecha formateada.
24
+ * @memberof module:Utils
25
+ */
26
+ function dateFormat(date = new Date()) {
27
+ const options = {
28
+ weekday: "long",
29
+ day: "numeric",
30
+ month: "short",
31
+ };
32
+ // @ts-ignore
33
+ return date.toLocaleDateString([], options);
34
+ }
35
+ //------------------------------------------------------
36
+ /**
37
+ * Returns a time as a formated string.
4
38
  *
5
39
  * @param {Date} [date]
6
40
  * @param {boolean} [sec=false]
7
41
  * @returns {string} La fecha formateada.
8
- * @memberof module:Astronomy
42
+ * @memberof module:Utils
9
43
  */
10
- export function timeString(date = new Date(), sec = false) {
44
+ function timeString(date = new Date(), sec = false) {
11
45
  if (sec) {
12
46
  return date.toLocaleTimeString([], {
13
47
  hour: "2-digit",
@@ -25,41 +59,25 @@ export function timeString(date = new Date(), sec = false) {
25
59
  }
26
60
  //------------------------------------------------------
27
61
  /**
62
+ * Returns a now time as a formated string.
28
63
  *
29
64
  * @param {boolean} sec
30
65
  * @returns {String}
31
- * @memberof module:Astronomy
66
+ * @memberof module:Utils
32
67
  */
33
- export function nowString(sec = false) {
68
+ function nowString(sec = false) {
34
69
  return timeString(new Date(), sec);
35
70
  }
36
71
  //------------------------------------------------------
37
72
  /**
38
- * Formatea una fecha a un string legible.
39
- *
40
- * @param {Date} [date=new Date()] La fecha a formatear.
41
- * @returns {string} La fecha formateada.
42
- * @memberof module:Astronomy
43
- */
44
- export function dateFormat(date = new Date()) {
45
- const options = {
46
- weekday: "long",
47
- day: "numeric",
48
- month: "short",
49
- };
50
- // @ts-ignore
51
- return date.toLocaleDateString([], options);
52
- }
53
- //------------------------------------------------------
54
- /**
55
- * Get local time from timezone
73
+ * Return the local time string from a given timezone.
56
74
  *
57
75
  * @param {string} timeZone - The timezone string (e.g., 'America/New_York').
58
76
  * @param {Date | number} [date=new Date()] - The date object to format. Defaults to the current date.
59
77
  * @returns {string} - The formatted local time string.
60
- * @memberof module:Astronomy
78
+ * @memberof module:Utils
61
79
  */
62
- export function getLocalTimeFromTz(timeZone, date = new Date()) {
80
+ function getLocalTimeFromTz(timeZone, date = new Date()) {
63
81
  // Timezone example
64
82
  // timeZone = 'America/New_York';
65
83
 
@@ -1,33 +0,0 @@
1
- /**
2
- * Formatea una fecha a un string legible.
3
- *
4
- * @param {Date} [date]
5
- * @param {boolean} [sec=false]
6
- * @returns {string} La fecha formateada.
7
- * @memberof module:Astronomy
8
- */
9
- export function timeString(date?: Date | undefined, sec?: boolean | undefined): string;
10
- /**
11
- *
12
- * @param {boolean} sec
13
- * @returns {String}
14
- * @memberof module:Astronomy
15
- */
16
- export function nowString(sec?: boolean): string;
17
- /**
18
- * Formatea una fecha a un string legible.
19
- *
20
- * @param {Date} [date=new Date()] La fecha a formatear.
21
- * @returns {string} La fecha formateada.
22
- * @memberof module:Astronomy
23
- */
24
- export function dateFormat(date?: Date | undefined): string;
25
- /**
26
- * Get local time from timezone
27
- *
28
- * @param {string} timeZone - The timezone string (e.g., 'America/New_York').
29
- * @param {Date | number} [date=new Date()] - The date object to format. Defaults to the current date.
30
- * @returns {string} - The formatted local time string.
31
- * @memberof module:Astronomy
32
- */
33
- export function getLocalTimeFromTz(timeZone: string, date?: number | Date | undefined): string;