@tmlmobilidade/utils 20250328.1807.3 → 20250331.1622.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.
@@ -12,5 +12,30 @@ export declare function getUnixTimestampFromSeconds(seconds: number): UnixTimest
12
12
  * Returns a JS Date object from a Unix Timestamp.
13
13
  * @param unixTimestamp - The Unix Timestamp to convert. in UTC.
14
14
  * @returns The JS Date object in local timezone.
15
+ * @deprecated Use `getDateStringFromUnixTimestamp` instead.
15
16
  */
16
17
  export declare function getJSDateFromUnixTimestamp(unixTimestamp: UnixTimestamp): Date;
18
+ /**
19
+ * Returns a formatted date string from a UnixTimestamp.
20
+ * @param timestamp - The Unix Timestamp to convert. UnixTimestamps are always in UTC.
21
+ * @param options - Optional formatting options.
22
+ * @param options.format - The format to use. Defaults to 'yyyy-MM-dd'.
23
+ * @param options.timezone - The timezone to use. Defaults to 'local'.
24
+ * @returns The formatted date string.
25
+ */
26
+ export declare function getDateStringFromUnixTimestamp(timestamp: UnixTimestamp, options?: {
27
+ format?: string;
28
+ timezone?: string;
29
+ }): string;
30
+ /**
31
+ * Returns a formatted date string from Unix seconds.
32
+ * @param timestamp - The Unix seconds to convert in UTC.
33
+ * @param options - Optional formatting options.
34
+ * @param options.format - The format to use. Defaults to 'yyyy-MM-dd'.
35
+ * @param options.timezone - The timezone to use. Defaults to 'local'.
36
+ * @returns The formatted date string.
37
+ */
38
+ export declare function getDateStringFromUnixSeconds(timestamp: number, options?: {
39
+ format?: string;
40
+ timezone?: string;
41
+ }): string;
@@ -36,7 +36,32 @@ export function getUnixTimestampFromSeconds(seconds) {
36
36
  * Returns a JS Date object from a Unix Timestamp.
37
37
  * @param unixTimestamp - The Unix Timestamp to convert. in UTC.
38
38
  * @returns The JS Date object in local timezone.
39
+ * @deprecated Use `getDateStringFromUnixTimestamp` instead.
39
40
  */
40
41
  export function getJSDateFromUnixTimestamp(unixTimestamp) {
41
42
  return DateTime.fromMillis(unixTimestamp, { zone: 'utc' }).toLocal().toJSDate();
42
43
  }
44
+ /**
45
+ * Returns a formatted date string from a UnixTimestamp.
46
+ * @param timestamp - The Unix Timestamp to convert. UnixTimestamps are always in UTC.
47
+ * @param options - Optional formatting options.
48
+ * @param options.format - The format to use. Defaults to 'yyyy-MM-dd'.
49
+ * @param options.timezone - The timezone to use. Defaults to 'local'.
50
+ * @returns The formatted date string.
51
+ */
52
+ export function getDateStringFromUnixTimestamp(timestamp, options) {
53
+ const date = DateTime.fromMillis(timestamp, { zone: 'utc' }).setZone(options?.timezone || 'local');
54
+ return date.toFormat(options?.format || 'yyyy-MM-dd');
55
+ }
56
+ /**
57
+ * Returns a formatted date string from Unix seconds.
58
+ * @param timestamp - The Unix seconds to convert in UTC.
59
+ * @param options - Optional formatting options.
60
+ * @param options.format - The format to use. Defaults to 'yyyy-MM-dd'.
61
+ * @param options.timezone - The timezone to use. Defaults to 'local'.
62
+ * @returns The formatted date string.
63
+ */
64
+ export function getDateStringFromUnixSeconds(timestamp, options) {
65
+ const convertedUnixTimestamp = getUnixTimestampFromSeconds(timestamp);
66
+ return getDateStringFromUnixTimestamp(convertedUnixTimestamp, options);
67
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmlmobilidade/utils",
3
- "version": "20250328.1807.03",
3
+ "version": "20250331.1622.05",
4
4
  "author": "João de Vasconcelos & Jusi Monteiro",
5
5
  "license": "AGPL-3.0-or-later",
6
6
  "homepage": "https://github.com/tmlmobilidade/services#readme",
@@ -53,7 +53,7 @@
53
53
  "@tmlmobilidade/tsconfig": "*",
54
54
  "@tmlmobilidade/types": "*",
55
55
  "@types/luxon": "3.4.2",
56
- "@types/node": "22.13.13",
56
+ "@types/node": "22.13.14",
57
57
  "resolve-tspaths": "0.8.23",
58
58
  "rimraf": "6.0.1",
59
59
  "turbo": "2.4.4",