@angelrove/forecast-utils 1.1.4 → 1.1.6

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>
@@ -22,139 +20,11 @@ Con excepción de &#39;getSolarTime()&#39;: recibe la hora local correspondiente
22
20
  <dd></dd>
23
21
  <dt><a href="#module_Utils">Utils</a></dt>
24
22
  <dd></dd>
23
+ <dt><a href="#module_Utils/TimeDateStr">Utils/TimeDateStr</a></dt>
24
+ <dd><p>Helpers for get date and time formeted strings</p>
25
+ </dd>
25
26
  </dl>
26
27
 
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
28
  <a name="module_Astronomy/MoonCalc"></a>
159
29
 
160
30
  ## Astronomy/MoonCalc
@@ -398,6 +268,11 @@ Con excepción de 'getSolarTime()': recibe la hora local correspondiente a la lo
398
268
 
399
269
  ## Geolocation
400
270
 
271
+ * [Geolocation](#module_Geolocation)
272
+ * [.exports.getGeolocation()](#module_Geolocation.exports.getGeolocation) ⇒ <code>Promise.&lt;{latitude: number, longitude: number, formatted\_address: string}&gt;</code>
273
+ * [.exports.timeFromLocation(apiKey, lat, lng)](#module_Geolocation.exports.timeFromLocation) ⇒ <code>Promise.&lt;(any\|LocalTimeData)&gt;</code>
274
+
275
+
401
276
  * * *
402
277
 
403
278
  <a name="module_Geolocation.exports.getGeolocation"></a>
@@ -411,6 +286,27 @@ Get the current geolocation of the device and reverse geocode it to get the addr
411
286
  - <code>Error</code> If geolocation is not supported or permission is denied.
412
287
 
413
288
 
289
+ * * *
290
+
291
+ <a name="module_Geolocation.exports.timeFromLocation"></a>
292
+
293
+ ### Geolocation.exports.timeFromLocation(apiKey, lat, lng) ⇒ <code>Promise.&lt;(any\|LocalTimeData)&gt;</code>
294
+ Get local time from a given location (lat, lng) using 'GoogleMaps TimeZone' API.
295
+
296
+ **Kind**: static method of [<code>Geolocation</code>](#module_Geolocation)
297
+ **Returns**: <code>Promise.&lt;(any\|LocalTimeData)&gt;</code> - - An object containing the local time and timezone information:
298
+ **Throws**:
299
+
300
+ - <code>Error</code> - If the API request fails or returns an error status.
301
+
302
+
303
+ | Param | Type | Description |
304
+ | --- | --- | --- |
305
+ | apiKey | <code>string</code> | GoogleMaps API key. |
306
+ | lat | <code>number</code> | |
307
+ | lng | <code>number</code> | |
308
+
309
+
414
310
  * * *
415
311
 
416
312
  <a name="module_OpenMeteo"></a>
@@ -503,6 +399,7 @@ Get weather symbol and description based on the weather code.
503
399
  * [.exports.degreesToCompass(degrees, language)](#module_Utils.exports.degreesToCompass) ⇒ <code>Object</code>
504
400
  * [.exports.getWarningByDays(precipitationSumToday, precipitationSumTomorrow, showersSumToday, showersSumTomorrow)](#module_Utils.exports.getWarningByDays) ⇒ <code>Object</code> \| <code>null</code>
505
401
  * [.exports.getWarning(precipitation, showers)](#module_Utils.exports.getWarning) ⇒ <code>Object</code> \| <code>null</code>
402
+ * [.exports.WindArrow(props)](#module_Utils.exports.WindArrow)
506
403
  * [.exports.windArrowTx(deg)](#module_Utils.exports.windArrowTx)
507
404
  * [.exports.getWindLevel(speed)](#module_Utils.exports.getWindLevel) ⇒ <code>WindLevel</code> \| <code>null</code>
508
405
  * [.Compass](#module_Utils.Compass) : <code>Object</code>
@@ -607,6 +504,30 @@ Get warning by precipitation and showers
607
504
  | showers | <code>number</code> |
608
505
 
609
506
 
507
+ * * *
508
+
509
+ <a name="module_Utils.exports.WindArrow"></a>
510
+
511
+ ### Utils.exports.WindArrow(props)
512
+ SVG arrow indicating wind direction.
513
+
514
+ **Kind**: static method of [<code>Utils</code>](#module_Utils)
515
+ **Component**: JSX
516
+
517
+ | Param | Type | Description |
518
+ | --- | --- | --- |
519
+ | props | <code>Object</code> | Component props. |
520
+
521
+ **Properties**
522
+
523
+ | Name | Type | Description |
524
+ | --- | --- | --- |
525
+ | props.deg | <code>number</code> | Wind direction in degrees (0 = North, 90 = East, etc.). |
526
+ | [props.size] | <code>string</code> | Tailwind CSS size class (e.g., 'size-10') |
527
+ | [props.strokeWidth] | <code>number</code> | Stroke width of the arrow (range: 1–6). |
528
+ | [props.className] | <code>string</code> | Additional CSS classes. |
529
+
530
+
610
531
  * * *
611
532
 
612
533
  <a name="module_Utils.exports.windArrowTx"></a>
@@ -685,3 +606,79 @@ Return the wind level based on the speed.
685
606
 
686
607
  * * *
687
608
 
609
+ <a name="module_Utils/TimeDateStr"></a>
610
+
611
+ ## Utils/TimeDateStr
612
+ Helpers for get date and time formeted strings
613
+
614
+
615
+ * [Utils/TimeDateStr](#module_Utils/TimeDateStr)
616
+ * [.dateFormat([date])](#module_Utils/TimeDateStr.dateFormat) ⇒ <code>string</code>
617
+ * [.timeString([date], [sec])](#module_Utils/TimeDateStr.timeString) ⇒ <code>string</code>
618
+ * [.nowString(sec)](#module_Utils/TimeDateStr.nowString) ⇒ <code>String</code>
619
+ * [.getLocalTimeFromTz(timeZone, [date])](#module_Utils/TimeDateStr.getLocalTimeFromTz) ⇒ <code>string</code>
620
+
621
+
622
+ * * *
623
+
624
+ <a name="module_Utils/TimeDateStr.dateFormat"></a>
625
+
626
+ ### Utils/TimeDateStr.dateFormat([date]) ⇒ <code>string</code>
627
+ Returns a date as a formated string.
628
+
629
+ **Kind**: static method of [<code>Utils/TimeDateStr</code>](#module_Utils/TimeDateStr)
630
+ **Returns**: <code>string</code> - La fecha formateada.
631
+
632
+ | Param | Type | Default | Description |
633
+ | --- | --- | --- | --- |
634
+ | [date] | <code>Date</code> | <code>new Date()</code> | La fecha a formatear. |
635
+
636
+
637
+ * * *
638
+
639
+ <a name="module_Utils/TimeDateStr.timeString"></a>
640
+
641
+ ### Utils/TimeDateStr.timeString([date], [sec]) ⇒ <code>string</code>
642
+ Returns a time as a formated string.
643
+
644
+ **Kind**: static method of [<code>Utils/TimeDateStr</code>](#module_Utils/TimeDateStr)
645
+ **Returns**: <code>string</code> - La fecha formateada.
646
+
647
+ | Param | Type | Default |
648
+ | --- | --- | --- |
649
+ | [date] | <code>Date</code> | |
650
+ | [sec] | <code>boolean</code> | <code>false</code> |
651
+
652
+
653
+ * * *
654
+
655
+ <a name="module_Utils/TimeDateStr.nowString"></a>
656
+
657
+ ### Utils/TimeDateStr.nowString(sec) ⇒ <code>String</code>
658
+ Returns a now time as a formated string.
659
+
660
+ **Kind**: static method of [<code>Utils/TimeDateStr</code>](#module_Utils/TimeDateStr)
661
+
662
+ | Param | Type | Default |
663
+ | --- | --- | --- |
664
+ | sec | <code>boolean</code> | <code>false</code> |
665
+
666
+
667
+ * * *
668
+
669
+ <a name="module_Utils/TimeDateStr.getLocalTimeFromTz"></a>
670
+
671
+ ### Utils/TimeDateStr.getLocalTimeFromTz(timeZone, [date]) ⇒ <code>string</code>
672
+ Return the local time string from a given timezone.
673
+
674
+ **Kind**: static method of [<code>Utils/TimeDateStr</code>](#module_Utils/TimeDateStr)
675
+ **Returns**: <code>string</code> - - The formatted local time string.
676
+
677
+ | Param | Type | Default | Description |
678
+ | --- | --- | --- | --- |
679
+ | timeZone | <code>string</code> | | The timezone string (e.g., 'America/New_York'). |
680
+ | [date] | <code>Date</code> \| <code>number</code> | <code>new Date()</code> | The date object to format. Defaults to the current date. |
681
+
682
+
683
+ * * *
684
+
@@ -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/TimeDateStr
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/TimeDateStr
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/TimeDateStr
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/TimeDateStr
40
+ */
41
+ declare function getLocalTimeFromTz(timeZone: string, date?: number | Date | undefined): string;
@@ -2,32 +2,14 @@
2
2
  * Wind direction arrow component (svg image).
3
3
  */
4
4
  /**
5
- * @typedef {Object} WindArrowProps
6
- * @property {number} props.deg - Wind direction in degrees
7
- * @property {string} [props.size] - Size of the arrow (Tailwind CSS size: 'size-10')
8
- * @property {number} [props.strokeWidth] - Stroke width of the arrow (1 to 6)
9
- * @property {string} [props.className]
10
- */
11
- /**
12
- * Wind direction arrow component (svg image).
5
+ * SVG arrow indicating wind direction.
13
6
  *
14
- * @component
15
- * @param {WindArrowProps} props
7
+ * @component JSX
8
+ * @param {Object} props - Component props.
9
+ * @prop {number} props.deg - Wind direction in degrees (0 = North, 90 = East, etc.).
10
+ * @prop {string} [props.size] - Tailwind CSS size class (e.g., 'size-10')
11
+ * @prop {number} [props.strokeWidth] - Stroke width of the arrow (range: 1–6).
12
+ * @prop {string} [props.className] - Additional CSS classes.
16
13
  * @memberof module:Utils
17
14
  */
18
- export function WindArrow({ deg, size, strokeWidth, className, }: WindArrowProps): any;
19
- export type WindArrowProps = {
20
- /**
21
- * - Wind direction in degrees
22
- */
23
- deg: number;
24
- /**
25
- * - Size of the arrow (Tailwind CSS size: 'size-10')
26
- */
27
- size?: string;
28
- /**
29
- * - Stroke width of the arrow (1 to 6)
30
- */
31
- strokeWidth?: number;
32
- className?: string;
33
- };
15
+ export function WindArrow({ deg, size, strokeWidth, className, }: Object): any;
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.6",
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,48 @@
1
+ /**
2
+ * Helpers for get date and time formeted strings
3
+ *
4
+ * @module Utils/TimeDateStr
5
+ */
6
+
7
+ /**
8
+ * TimeDateStr.
9
+ * @ignore
10
+ */
11
+ const TimeDateStr = {
12
+ dateFormat,
13
+ nowString,
14
+ timeString,
15
+ getLocalTimeFromTz,
16
+ };
17
+ export default TimeDateStr;
18
+
1
19
  //------------------------------------------------------
2
20
  /**
3
- * Formatea una fecha a un string legible.
21
+ * Returns a date as a formated string.
22
+ *
23
+ * @param {Date} [date=new Date()] La fecha a formatear.
24
+ * @returns {string} La fecha formateada.
25
+ * @memberof module:Utils/TimeDateStr
26
+ */
27
+ function dateFormat(date = new Date()) {
28
+ const options = {
29
+ weekday: "long",
30
+ day: "numeric",
31
+ month: "short",
32
+ };
33
+ // @ts-ignore
34
+ return date.toLocaleDateString([], options);
35
+ }
36
+ //------------------------------------------------------
37
+ /**
38
+ * Returns a time as a formated string.
4
39
  *
5
40
  * @param {Date} [date]
6
41
  * @param {boolean} [sec=false]
7
42
  * @returns {string} La fecha formateada.
8
- * @memberof module:Astronomy
43
+ * @memberof module:Utils/TimeDateStr
9
44
  */
10
- export function timeString(date = new Date(), sec = false) {
45
+ function timeString(date = new Date(), sec = false) {
11
46
  if (sec) {
12
47
  return date.toLocaleTimeString([], {
13
48
  hour: "2-digit",
@@ -25,41 +60,25 @@ export function timeString(date = new Date(), sec = false) {
25
60
  }
26
61
  //------------------------------------------------------
27
62
  /**
63
+ * Returns a now time as a formated string.
28
64
  *
29
65
  * @param {boolean} sec
30
66
  * @returns {String}
31
- * @memberof module:Astronomy
67
+ * @memberof module:Utils/TimeDateStr
32
68
  */
33
- export function nowString(sec = false) {
69
+ function nowString(sec = false) {
34
70
  return timeString(new Date(), sec);
35
71
  }
36
72
  //------------------------------------------------------
37
73
  /**
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
74
+ * Return the local time string from a given timezone.
56
75
  *
57
76
  * @param {string} timeZone - The timezone string (e.g., 'America/New_York').
58
77
  * @param {Date | number} [date=new Date()] - The date object to format. Defaults to the current date.
59
78
  * @returns {string} - The formatted local time string.
60
- * @memberof module:Astronomy
79
+ * @memberof module:Utils/TimeDateStr
61
80
  */
62
- export function getLocalTimeFromTz(timeZone, date = new Date()) {
81
+ function getLocalTimeFromTz(timeZone, date = new Date()) {
63
82
  // Timezone example
64
83
  // timeZone = 'America/New_York';
65
84
 
@@ -1,20 +1,26 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Wind direction arrow component (svg image).
3
4
  */
4
5
 
5
- /**
6
- * @typedef {Object} WindArrowProps
7
- * @property {number} props.deg - Wind direction in degrees
8
- * @property {string} [props.size] - Size of the arrow (Tailwind CSS size: 'size-10')
9
- * @property {number} [props.strokeWidth] - Stroke width of the arrow (1 to 6)
10
- * @property {string} [props.className]
11
- */
6
+ // /**
7
+ // * @typedef {Object} WindArrowProps
8
+ // * @property {number} props.deg - Wind direction in degrees
9
+ // * @property {string} [props.size] - Size of the arrow (Tailwind CSS size: 'size-10')
10
+ // * @property {number} [props.strokeWidth] - Stroke width of the arrow (1 to 6)
11
+ // * @property {string} [props.className]
12
+ // * @memberof module:Utils
13
+ // */
12
14
 
13
15
  /**
14
- * Wind direction arrow component (svg image).
16
+ * SVG arrow indicating wind direction.
15
17
  *
16
- * @component
17
- * @param {WindArrowProps} props
18
+ * @component JSX
19
+ * @param {Object} props - Component props.
20
+ * @prop {number} props.deg - Wind direction in degrees (0 = North, 90 = East, etc.).
21
+ * @prop {string} [props.size] - Tailwind CSS size class (e.g., 'size-10')
22
+ * @prop {number} [props.strokeWidth] - Stroke width of the arrow (range: 1–6).
23
+ * @prop {string} [props.className] - Additional CSS classes.
18
24
  * @memberof module:Utils
19
25
  */
20
26
  export function WindArrow({
@@ -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;