wedance-shared 1.0.19 → 1.0.21
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/Timestamp.d.ts +78 -0
- package/dist/Timestamp.js +2 -0
- package/dist/Timestamp.js.map +1 -0
- package/dist/index.d.ts +2 -9
- package/dist/index.js +2 -9
- package/dist/index.js.map +1 -1
- package/dist/{analytics.d.ts → types/analytics.d.ts} +1 -1
- package/dist/{analytics.js.map → types/analytics.js.map} +1 -1
- package/dist/types/city.js.map +1 -0
- package/dist/{event.d.ts → types/event.d.ts} +2 -1
- package/dist/types/event.js.map +1 -0
- package/dist/{festivals → types/festivals}/festival.d.ts +10 -10
- package/dist/types/festivals/festival.js.map +1 -0
- package/dist/types/festivals/index.d.ts +2 -0
- package/dist/types/festivals/index.js +3 -0
- package/dist/types/festivals/index.js.map +1 -0
- package/dist/{festivals → types/festivals}/user.d.ts +1 -1
- package/dist/types/festivals/user.js.map +1 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/index.js +11 -0
- package/dist/types/index.js.map +1 -0
- package/dist/{organizer.js.map → types/organizer.js.map} +1 -1
- package/dist/types/other.js.map +1 -0
- package/dist/{ticket.d.ts → types/ticket.d.ts} +1 -1
- package/dist/types/ticket.js.map +1 -0
- package/dist/{festivals → types}/user.js.map +1 -1
- package/dist/utils/date.d.ts +42 -0
- package/dist/utils/date.js +93 -0
- package/dist/utils/date.js.map +1 -0
- package/package.json +6 -3
- package/script/incrementVersion.sh +73 -0
- package/src/Timestamp.ts +85 -0
- package/src/index.ts +2 -9
- package/src/{analytics.ts → types/analytics.ts} +1 -1
- package/src/{event.ts → types/event.ts} +2 -1
- package/src/{festivals → types/festivals}/festival.ts +10 -12
- package/src/types/festivals/index.ts +2 -0
- package/src/{festivals → types/festivals}/user.ts +1 -1
- package/src/types/index.ts +11 -0
- package/src/{ticket.ts → types/ticket.ts} +1 -1
- package/src/utils/date.ts +116 -0
- package/dist/city.js.map +0 -1
- package/dist/event.js.map +0 -1
- package/dist/festivals/festival.js.map +0 -1
- package/dist/other.js.map +0 -1
- package/dist/ticket.js.map +0 -1
- package/dist/user.js.map +0 -1
- /package/dist/{analytics.js → types/analytics.js} +0 -0
- /package/dist/{city.d.ts → types/city.d.ts} +0 -0
- /package/dist/{city.js → types/city.js} +0 -0
- /package/dist/{event.js → types/event.js} +0 -0
- /package/dist/{festivals → types/festivals}/festival.js +0 -0
- /package/dist/{festivals → types/festivals}/user.js +0 -0
- /package/dist/{organizer.d.ts → types/organizer.d.ts} +0 -0
- /package/dist/{organizer.js → types/organizer.js} +0 -0
- /package/dist/{other.d.ts → types/other.d.ts} +0 -0
- /package/dist/{other.js → types/other.js} +0 -0
- /package/dist/{ticket.js → types/ticket.js} +0 -0
- /package/dist/{user.d.ts → types/user.d.ts} +0 -0
- /package/dist/{user.js → types/user.js} +0 -0
- /package/src/{city.ts → types/city.ts} +0 -0
- /package/src/{organizer.ts → types/organizer.ts} +0 -0
- /package/src/{other.ts → types/other.ts} +0 -0
- /package/src/{user.ts → types/user.ts} +0 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A `Timestamp` represents a point in time independent of any time zone or
|
|
3
|
+
* calendar, represented as seconds and fractions of seconds at nanosecond
|
|
4
|
+
* resolution in UTC Epoch time.
|
|
5
|
+
*
|
|
6
|
+
* It is encoded using the Proleptic Gregorian Calendar which extends the
|
|
7
|
+
* Gregorian calendar backwards to year one. It is encoded assuming all minutes
|
|
8
|
+
* are 60 seconds long, i.e. leap seconds are "smeared" so that no leap second
|
|
9
|
+
* table is needed for interpretation. Range is from 0001-01-01T00:00:00Z to
|
|
10
|
+
* 9999-12-31T23:59:59.999999999Z.
|
|
11
|
+
*
|
|
12
|
+
* For examples and further specifications, refer to the
|
|
13
|
+
* {@link https://github.com/google/protobuf/blob/master/src/google/protobuf/timestamp.proto | Timestamp definition}.
|
|
14
|
+
*/
|
|
15
|
+
export declare class Timestamp {
|
|
16
|
+
readonly seconds: number;
|
|
17
|
+
readonly nanoseconds: number;
|
|
18
|
+
constructor(seconds: number, nanoseconds: number);
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new timestamp with the current date, with millisecond precision.
|
|
21
|
+
*
|
|
22
|
+
* @returns a new timestamp representing the current date.
|
|
23
|
+
*/
|
|
24
|
+
static now(): Timestamp;
|
|
25
|
+
/**
|
|
26
|
+
* Creates a new timestamp from the given date.
|
|
27
|
+
*
|
|
28
|
+
* @param date - The date to initialize the `Timestamp` from.
|
|
29
|
+
* @returns A new `Timestamp` representing the same point in time as the given
|
|
30
|
+
* date.
|
|
31
|
+
*/
|
|
32
|
+
static fromDate(date: Date): Timestamp;
|
|
33
|
+
/**
|
|
34
|
+
* Creates a new timestamp from the given number of milliseconds.
|
|
35
|
+
*
|
|
36
|
+
* @param milliseconds - Number of milliseconds since Unix epoch
|
|
37
|
+
* 1970-01-01T00:00:00Z.
|
|
38
|
+
* @returns A new `Timestamp` representing the same point in time as the given
|
|
39
|
+
* number of milliseconds.
|
|
40
|
+
*/
|
|
41
|
+
static fromMillis(milliseconds: number): Timestamp;
|
|
42
|
+
/**
|
|
43
|
+
* Converts a `Timestamp` to a JavaScript `Date` object. This conversion
|
|
44
|
+
* causes a loss of precision since `Date` objects only support millisecond
|
|
45
|
+
* precision.
|
|
46
|
+
*
|
|
47
|
+
* @returns JavaScript `Date` object representing the same point in time as
|
|
48
|
+
* this `Timestamp`, with millisecond precision.
|
|
49
|
+
*/
|
|
50
|
+
toDate(): Date;
|
|
51
|
+
/**
|
|
52
|
+
* Converts a `Timestamp` to a numeric timestamp (in milliseconds since
|
|
53
|
+
* epoch). This operation causes a loss of precision.
|
|
54
|
+
*
|
|
55
|
+
* @returns The point in time corresponding to this timestamp, represented as
|
|
56
|
+
* the number of milliseconds since Unix epoch 1970-01-01T00:00:00Z.
|
|
57
|
+
*/
|
|
58
|
+
toMillis(): number;
|
|
59
|
+
/**
|
|
60
|
+
* Returns true if this `Timestamp` is equal to the provided one.
|
|
61
|
+
*
|
|
62
|
+
* @param other - The `Timestamp` to compare against.
|
|
63
|
+
* @returns true if this `Timestamp` is equal to the provided one.
|
|
64
|
+
*/
|
|
65
|
+
isEqual(other: Timestamp): boolean;
|
|
66
|
+
/** Returns a JSON-serializable representation of this `Timestamp`. */
|
|
67
|
+
toJSON(): {
|
|
68
|
+
seconds: number;
|
|
69
|
+
nanoseconds: number;
|
|
70
|
+
};
|
|
71
|
+
/** Returns a textual representation of this `Timestamp`. */
|
|
72
|
+
toString(): string;
|
|
73
|
+
/**
|
|
74
|
+
* Converts this object to a primitive string, which allows `Timestamp` objects
|
|
75
|
+
* to be compared using the `>`, `<=`, `>=` and `>` operators.
|
|
76
|
+
*/
|
|
77
|
+
valueOf(): string;
|
|
78
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Timestamp.js","sourceRoot":"","sources":["../src/Timestamp.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,2 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./ticket";
|
|
4
|
-
export * from "./user";
|
|
5
|
-
export * from "./city";
|
|
6
|
-
export * from "./other";
|
|
7
|
-
export * from "./analytics";
|
|
8
|
-
export * from "./festivals/festival";
|
|
9
|
-
export * from "./festivals/user";
|
|
1
|
+
export * from "./types";
|
|
2
|
+
export * from "./utils/date";
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./ticket";
|
|
4
|
-
export * from "./user";
|
|
5
|
-
export * from "./city";
|
|
6
|
-
export * from "./other";
|
|
7
|
-
export * from "./analytics";
|
|
8
|
-
export * from "./festivals/festival";
|
|
9
|
-
export * from "./festivals/user";
|
|
1
|
+
export * from "./types";
|
|
2
|
+
export * from "./utils/date";
|
|
10
3
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analytics.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"analytics.js","sourceRoot":"","sources":["../../src/types/analytics.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"city.js","sourceRoot":"","sources":["../../src/types/city.ts"],"names":[],"mappings":"AAgCA,MAAM,CAAC,MAAM,WAAW,GAAe;IACrC;QACE,IAAI,EAAE,UAAU;QAChB,OAAO,EAAE,IAAI;QACb,WAAW,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC;KAChC;IACD;QACE,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,IAAI;QACb,WAAW,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC;KAC/B;IACD;QACE,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,IAAI;QACb,WAAW,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC;KAChC;IACD,IAAI;IACJ,uBAAuB;IACvB,mBAAmB;IACnB,KAAK;IACL;QACE,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,IAAI;QACb,WAAW,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC;KAC/B;IACD;QACE,IAAI,EAAE,YAAY;QAClB,OAAO,EAAE,IAAI;QACb,WAAW,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC;KAChC;IACD;QACE,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,IAAI;QACb,WAAW,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC;KAC9B;CACF,CAAC;AAMF,MAAM,CAAN,IAAY,QAKX;AALD,WAAY,QAAQ;IAClB,uCAA2B,CAAA;IAC3B,yCAA6B,CAAA;IAC7B,uCAA2B,CAAA;IAC3B,kCAAsB,CAAA;AACxB,CAAC,EALW,QAAQ,KAAR,QAAQ,QAKnB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Timestamp } from "
|
|
1
|
+
import { Timestamp } from "../Timestamp";
|
|
2
2
|
import { City } from "./city";
|
|
3
3
|
import { OrganizerName } from "./organizer";
|
|
4
4
|
import { EventTicket } from "./ticket";
|
|
@@ -9,6 +9,7 @@ export type Organizer = {
|
|
|
9
9
|
email?: string;
|
|
10
10
|
};
|
|
11
11
|
export type Links = {
|
|
12
|
+
paymentLink?: string;
|
|
12
13
|
instagram?: string;
|
|
13
14
|
facebook?: string;
|
|
14
15
|
website?: string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event.js","sourceRoot":"","sources":["../../src/types/event.ts"],"names":[],"mappings":""}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Timestamp } from "
|
|
1
|
+
import { Timestamp } from "../../Timestamp";
|
|
2
2
|
import { Links } from "../event";
|
|
3
|
+
import { EventTicket } from "wedance-shared";
|
|
3
4
|
/**
|
|
4
5
|
* This is the type of the data we get from the server
|
|
5
6
|
* */
|
|
@@ -8,14 +9,12 @@ export type FestivalData = {
|
|
|
8
9
|
title: string;
|
|
9
10
|
from: Timestamp;
|
|
10
11
|
until: Timestamp;
|
|
11
|
-
organizerId: string;
|
|
12
|
+
organizerId: string[];
|
|
12
13
|
description: string;
|
|
13
14
|
location: FestivalLocation[];
|
|
14
15
|
genre?: FestivalGenre[];
|
|
15
16
|
tags?: string[];
|
|
16
17
|
imageData: FestivalImageData[];
|
|
17
|
-
countryCode: string;
|
|
18
|
-
region: Region[];
|
|
19
18
|
priceRange?: {
|
|
20
19
|
min: number;
|
|
21
20
|
max: number;
|
|
@@ -28,6 +27,7 @@ export type FestivalData = {
|
|
|
28
27
|
links: Links;
|
|
29
28
|
isFree: boolean;
|
|
30
29
|
artists: FestivalArtist[];
|
|
30
|
+
tickets?: EventTicket[];
|
|
31
31
|
};
|
|
32
32
|
type FestivalGenre = "salsa" | "bachata" | "kizomba" | "zouk";
|
|
33
33
|
type FestivalImageData = {
|
|
@@ -35,10 +35,10 @@ type FestivalImageData = {
|
|
|
35
35
|
alt?: string;
|
|
36
36
|
blurhash?: string;
|
|
37
37
|
};
|
|
38
|
-
type FestivalLocation = {
|
|
39
|
-
id?: string;
|
|
38
|
+
export type FestivalLocation = {
|
|
40
39
|
city: string;
|
|
41
40
|
countryCode: string;
|
|
41
|
+
country: string;
|
|
42
42
|
address?: string;
|
|
43
43
|
venue?: string;
|
|
44
44
|
geoLocation?: {
|
|
@@ -46,15 +46,15 @@ type FestivalLocation = {
|
|
|
46
46
|
lng: number;
|
|
47
47
|
};
|
|
48
48
|
timeZone: string;
|
|
49
|
-
region
|
|
49
|
+
region: Region[];
|
|
50
50
|
};
|
|
51
|
-
type FestivalArtist = {
|
|
51
|
+
export type FestivalArtist = {
|
|
52
52
|
id: string;
|
|
53
53
|
name: string;
|
|
54
54
|
image: string;
|
|
55
55
|
imageUrl: string;
|
|
56
56
|
role: FestivalArtistRole;
|
|
57
57
|
};
|
|
58
|
-
type FestivalArtistRole = "dj" | "dancer" | "mc" | "guest-dancer" | "organizer" | "media";
|
|
59
|
-
type Region = "Nordics" | "Baltics" | "Western Europe" | "Eastern Europe" | "Southern Europe" | "Central Europe" | "Asia" | "Africa";
|
|
58
|
+
export type FestivalArtistRole = "dj" | "dancer" | "mc" | "guest-dancer" | "organizer" | "media";
|
|
59
|
+
export type Region = "Nordics" | "Baltics" | "Western Europe" | "Eastern Europe" | "Southern Europe" | "Central Europe" | "Asia" | "Africa";
|
|
60
60
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"festival.js","sourceRoot":"","sources":["../../../src/types/festivals/festival.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/festivals/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user.js","sourceRoot":"","sources":["../../../src/types/festivals/user.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Re-export all types from individual files
|
|
2
|
+
export * from "./event";
|
|
3
|
+
export * from "./ticket";
|
|
4
|
+
export * from "./city";
|
|
5
|
+
export * from "./organizer";
|
|
6
|
+
export * from "./user";
|
|
7
|
+
export * from "./other";
|
|
8
|
+
export * from "./analytics";
|
|
9
|
+
// Re-export from subdirectories
|
|
10
|
+
export * from "./festivals";
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAE5B,gCAAgC;AAChC,cAAc,aAAa,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"organizer.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"organizer.js","sourceRoot":"","sources":["../../src/types/organizer.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"other.js","sourceRoot":"","sources":["../../src/types/other.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ticket.js","sourceRoot":"","sources":["../../src/types/ticket.ts"],"names":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user.js","sourceRoot":"","sources":["../../src/
|
|
1
|
+
{"version":3,"file":"user.js","sourceRoot":"","sources":["../../src/types/user.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Timestamp } from "../Timestamp";
|
|
2
|
+
/**
|
|
3
|
+
* Converts a Firestore Timestamp to a JavaScript Date object
|
|
4
|
+
* @param timestamp Firestore Timestamp or null/undefined
|
|
5
|
+
* @returns JavaScript Date object or null if input is null/undefined
|
|
6
|
+
*/
|
|
7
|
+
export declare const timestampToDate: (timestamp: Timestamp | null | undefined) => Date | null;
|
|
8
|
+
/**
|
|
9
|
+
* Converts a JavaScript Date to a Firestore Timestamp
|
|
10
|
+
* @param date JavaScript Date object or null/undefined
|
|
11
|
+
* @returns Firestore Timestamp or null if input is null/undefined
|
|
12
|
+
*/
|
|
13
|
+
export declare const dateToTimestamp: (date: Date | null | undefined) => Timestamp | null;
|
|
14
|
+
/**
|
|
15
|
+
* Formats a Firestore Timestamp to a string using the provided format
|
|
16
|
+
* Uses day.js library - install with: npm install dayjs
|
|
17
|
+
* @param timestamp Firestore Timestamp or null/undefined
|
|
18
|
+
* @param formatStr Format string compatible with day.js format function
|
|
19
|
+
* (see https://day.js.org/docs/en/display/format for format options)
|
|
20
|
+
* @param defaultValue Value to return if timestamp is null/undefined
|
|
21
|
+
* @returns Formatted date string or defaultValue if timestamp is null/undefined
|
|
22
|
+
*/
|
|
23
|
+
export declare const formatTimestamp: (timestamp: Timestamp | null | undefined, formatStr?: string, defaultValue?: string) => string;
|
|
24
|
+
/**
|
|
25
|
+
* Checks if a Firestore Timestamp is before current time
|
|
26
|
+
* @param timestamp Firestore Timestamp to check
|
|
27
|
+
* @returns boolean indicating if timestamp is in the past
|
|
28
|
+
*/
|
|
29
|
+
export declare const isTimestampInPast: (timestamp: Timestamp | null | undefined) => boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Checks if a Firestore Timestamp is after current time
|
|
32
|
+
* @param timestamp Firestore Timestamp to check
|
|
33
|
+
* @returns boolean indicating if timestamp is in the future
|
|
34
|
+
*/
|
|
35
|
+
export declare const isTimestampInFuture: (timestamp: Timestamp | null | undefined) => boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Gets the relative time between now and a Firestore Timestamp (e.g. "2 hours ago", "in 3 days")
|
|
38
|
+
* Uses day.js with relativeTime plugin for localized relative time formatting
|
|
39
|
+
* @param timestamp Firestore Timestamp
|
|
40
|
+
* @returns String representation of relative time
|
|
41
|
+
*/
|
|
42
|
+
export declare const getRelativeTime: (timestamp: Timestamp | null | undefined) => string;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import dayjs from "dayjs";
|
|
2
|
+
import relativeTime from "dayjs/plugin/relativeTime";
|
|
3
|
+
import { Timestamp } from "../Timestamp";
|
|
4
|
+
// Register the relativeTime plugin
|
|
5
|
+
dayjs.extend(relativeTime);
|
|
6
|
+
/**
|
|
7
|
+
* Converts a Firestore Timestamp to a JavaScript Date object
|
|
8
|
+
* @param timestamp Firestore Timestamp or null/undefined
|
|
9
|
+
* @returns JavaScript Date object or null if input is null/undefined
|
|
10
|
+
*/
|
|
11
|
+
export const timestampToDate = (timestamp) => {
|
|
12
|
+
if (!timestamp)
|
|
13
|
+
return null;
|
|
14
|
+
return new Date(timestamp.seconds * 1000 + timestamp.nanoseconds / 1000000);
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Converts a JavaScript Date to a Firestore Timestamp
|
|
18
|
+
* @param date JavaScript Date object or null/undefined
|
|
19
|
+
* @returns Firestore Timestamp or null if input is null/undefined
|
|
20
|
+
*/
|
|
21
|
+
export const dateToTimestamp = (date) => {
|
|
22
|
+
if (!date)
|
|
23
|
+
return null;
|
|
24
|
+
return Timestamp.fromDate(date);
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Formats a Firestore Timestamp to a string using the provided format
|
|
28
|
+
* Uses day.js library - install with: npm install dayjs
|
|
29
|
+
* @param timestamp Firestore Timestamp or null/undefined
|
|
30
|
+
* @param formatStr Format string compatible with day.js format function
|
|
31
|
+
* (see https://day.js.org/docs/en/display/format for format options)
|
|
32
|
+
* @param defaultValue Value to return if timestamp is null/undefined
|
|
33
|
+
* @returns Formatted date string or defaultValue if timestamp is null/undefined
|
|
34
|
+
*/
|
|
35
|
+
export const formatTimestamp = (timestamp, formatStr = "MMM D, YYYY", defaultValue = "") => {
|
|
36
|
+
if (!timestamp)
|
|
37
|
+
return defaultValue;
|
|
38
|
+
try {
|
|
39
|
+
// Convert timestamp to Date
|
|
40
|
+
const date = new Date(timestamp.seconds * 1000 + timestamp.nanoseconds / 1000000);
|
|
41
|
+
// Use dayjs to format the date according to the format string
|
|
42
|
+
return dayjs(date).format(formatStr);
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
console.error("Error formatting timestamp:", error);
|
|
46
|
+
return defaultValue;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Checks if a Firestore Timestamp is before current time
|
|
51
|
+
* @param timestamp Firestore Timestamp to check
|
|
52
|
+
* @returns boolean indicating if timestamp is in the past
|
|
53
|
+
*/
|
|
54
|
+
export const isTimestampInPast = (timestamp) => {
|
|
55
|
+
if (!timestamp)
|
|
56
|
+
return false;
|
|
57
|
+
// Convert timestamp to milliseconds manually
|
|
58
|
+
const timestampMillis = timestamp.seconds * 1000 + timestamp.nanoseconds / 1000000;
|
|
59
|
+
return timestampMillis < Date.now();
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Checks if a Firestore Timestamp is after current time
|
|
63
|
+
* @param timestamp Firestore Timestamp to check
|
|
64
|
+
* @returns boolean indicating if timestamp is in the future
|
|
65
|
+
*/
|
|
66
|
+
export const isTimestampInFuture = (timestamp) => {
|
|
67
|
+
if (!timestamp)
|
|
68
|
+
return false;
|
|
69
|
+
// Convert timestamp to milliseconds manually
|
|
70
|
+
const timestampMillis = timestamp.seconds * 1000 + timestamp.nanoseconds / 1000000;
|
|
71
|
+
return timestampMillis > Date.now();
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Gets the relative time between now and a Firestore Timestamp (e.g. "2 hours ago", "in 3 days")
|
|
75
|
+
* Uses day.js with relativeTime plugin for localized relative time formatting
|
|
76
|
+
* @param timestamp Firestore Timestamp
|
|
77
|
+
* @returns String representation of relative time
|
|
78
|
+
*/
|
|
79
|
+
export const getRelativeTime = (timestamp) => {
|
|
80
|
+
if (!timestamp)
|
|
81
|
+
return "";
|
|
82
|
+
try {
|
|
83
|
+
// Convert timestamp to milliseconds manually
|
|
84
|
+
const timestampMillis = timestamp.seconds * 1000 + timestamp.nanoseconds / 1000000;
|
|
85
|
+
// Use dayjs to get relative time
|
|
86
|
+
return dayjs(timestampMillis).fromNow();
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
console.error("Error generating relative time:", error);
|
|
90
|
+
return "";
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
//# sourceMappingURL=date.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date.js","sourceRoot":"","sources":["../../src/utils/date.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,YAAY,MAAM,2BAA2B,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,mCAAmC;AACnC,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;AAE3B;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,SAAuC,EAC1B,EAAE;IACf,IAAI,CAAC,SAAS;QAAE,OAAO,IAAI,CAAC;IAC5B,OAAO,IAAI,IAAI,CAAC,SAAS,CAAC,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC,WAAW,GAAG,OAAO,CAAC,CAAC;AAC9E,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,IAA6B,EACX,EAAE;IACpB,IAAI,CAAC,IAAI;QAAE,OAAO,IAAI,CAAC;IACvB,OAAO,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AAClC,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,SAAuC,EACvC,YAAoB,aAAa,EACjC,eAAuB,EAAE,EACjB,EAAE;IACV,IAAI,CAAC,SAAS;QAAE,OAAO,YAAY,CAAC;IAEpC,IAAI,CAAC;QACH,4BAA4B;QAC5B,MAAM,IAAI,GAAG,IAAI,IAAI,CACnB,SAAS,CAAC,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC,WAAW,GAAG,OAAO,CAC3D,CAAC;QAEF,8DAA8D;QAC9D,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACvC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,6BAA6B,EAAE,KAAK,CAAC,CAAC;QACpD,OAAO,YAAY,CAAC;IACtB,CAAC;AACH,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,SAAuC,EAC9B,EAAE;IACX,IAAI,CAAC,SAAS;QAAE,OAAO,KAAK,CAAC;IAE7B,6CAA6C;IAC7C,MAAM,eAAe,GACnB,SAAS,CAAC,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC,WAAW,GAAG,OAAO,CAAC;IAC7D,OAAO,eAAe,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;AACtC,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,SAAuC,EAC9B,EAAE;IACX,IAAI,CAAC,SAAS;QAAE,OAAO,KAAK,CAAC;IAE7B,6CAA6C;IAC7C,MAAM,eAAe,GACnB,SAAS,CAAC,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC,WAAW,GAAG,OAAO,CAAC;IAC7D,OAAO,eAAe,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;AACtC,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,SAAuC,EAC/B,EAAE;IACV,IAAI,CAAC,SAAS;QAAE,OAAO,EAAE,CAAC;IAE1B,IAAI,CAAC;QACH,6CAA6C;QAC7C,MAAM,eAAe,GACnB,SAAS,CAAC,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC,WAAW,GAAG,OAAO,CAAC;QAE7D,iCAAiC;QACjC,OAAO,KAAK,CAAC,eAAe,CAAC,CAAC,OAAO,EAAE,CAAC;IAC1C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,iCAAiC,EAAE,KAAK,CAAC,CAAC;QACxD,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wedance-shared",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.21",
|
|
4
4
|
"description": "This repository contains shared TypeScript types and interfaces used across multiple WeDance applications:",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -15,7 +15,10 @@
|
|
|
15
15
|
"check-format": "prettier --check \"src/**/*.ts\"",
|
|
16
16
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
17
17
|
"clean": "rm -rf dist",
|
|
18
|
-
"
|
|
18
|
+
"version:patch": "script/incrementVersion.sh",
|
|
19
|
+
"version:minor": "script/incrementVersion.sh minor",
|
|
20
|
+
"version:major": "script/incrementVersion.sh major",
|
|
21
|
+
"npm:publish": "npm run build && npm run version:patch && npm publish --access public"
|
|
19
22
|
},
|
|
20
23
|
"keywords": [],
|
|
21
24
|
"author": "",
|
|
@@ -33,6 +36,6 @@
|
|
|
33
36
|
},
|
|
34
37
|
"type": "module",
|
|
35
38
|
"dependencies": {
|
|
36
|
-
"
|
|
39
|
+
"dayjs": "^1.11.13"
|
|
37
40
|
}
|
|
38
41
|
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# This script increments the version in package.json
|
|
4
|
+
# Usage: ./incrementVersion.sh [major|minor|patch]
|
|
5
|
+
# Default is patch if no argument is provided
|
|
6
|
+
|
|
7
|
+
# Function to display usage information
|
|
8
|
+
show_usage() {
|
|
9
|
+
echo "Usage: $0 [major|minor|patch]"
|
|
10
|
+
echo "Default is patch if no argument is provided"
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
# Check if package.json exists
|
|
14
|
+
if [ ! -f "package.json" ]; then
|
|
15
|
+
echo "Error: package.json not found in current directory"
|
|
16
|
+
exit 1
|
|
17
|
+
fi
|
|
18
|
+
|
|
19
|
+
# Determine which version part to increment
|
|
20
|
+
VERSION_PART=${1:-patch}
|
|
21
|
+
|
|
22
|
+
if [[ ! $VERSION_PART =~ ^(major|minor|patch)$ ]]; then
|
|
23
|
+
echo "Error: Invalid version part. Must be one of: major, minor, patch"
|
|
24
|
+
show_usage
|
|
25
|
+
exit 1
|
|
26
|
+
fi
|
|
27
|
+
|
|
28
|
+
# Get current version from package.json
|
|
29
|
+
CURRENT_VERSION=$(grep -o '"version": "[^"]*' package.json | cut -d'"' -f4)
|
|
30
|
+
|
|
31
|
+
if [ -z "$CURRENT_VERSION" ]; then
|
|
32
|
+
echo "Error: Unable to find version in package.json"
|
|
33
|
+
exit 1
|
|
34
|
+
fi
|
|
35
|
+
|
|
36
|
+
echo "Current version: $CURRENT_VERSION"
|
|
37
|
+
|
|
38
|
+
# Split version into components
|
|
39
|
+
IFS='.' read -r -a VERSION_PARTS <<< "$CURRENT_VERSION"
|
|
40
|
+
MAJOR=${VERSION_PARTS[0]}
|
|
41
|
+
MINOR=${VERSION_PARTS[1]}
|
|
42
|
+
PATCH=${VERSION_PARTS[2]}
|
|
43
|
+
|
|
44
|
+
# Increment appropriate version part
|
|
45
|
+
case $VERSION_PART in
|
|
46
|
+
major)
|
|
47
|
+
MAJOR=$((MAJOR + 1))
|
|
48
|
+
MINOR=0
|
|
49
|
+
PATCH=0
|
|
50
|
+
;;
|
|
51
|
+
minor)
|
|
52
|
+
MINOR=$((MINOR + 1))
|
|
53
|
+
PATCH=0
|
|
54
|
+
;;
|
|
55
|
+
patch)
|
|
56
|
+
PATCH=$((PATCH + 1))
|
|
57
|
+
;;
|
|
58
|
+
esac
|
|
59
|
+
|
|
60
|
+
# Construct new version
|
|
61
|
+
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
|
|
62
|
+
echo "New version: $NEW_VERSION"
|
|
63
|
+
|
|
64
|
+
# Update version in package.json
|
|
65
|
+
if [[ "$OSTYPE" == "darwin"* ]]; then
|
|
66
|
+
# macOS requires a slightly different sed syntax
|
|
67
|
+
sed -i '' "s/\"version\": \"$CURRENT_VERSION\"/\"version\": \"$NEW_VERSION\"/" package.json
|
|
68
|
+
else
|
|
69
|
+
# Linux version
|
|
70
|
+
sed -i "s/\"version\": \"$CURRENT_VERSION\"/\"version\": \"$NEW_VERSION\"/" package.json
|
|
71
|
+
fi
|
|
72
|
+
|
|
73
|
+
echo "Updated package.json version to $NEW_VERSION"
|
package/src/Timestamp.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A `Timestamp` represents a point in time independent of any time zone or
|
|
3
|
+
* calendar, represented as seconds and fractions of seconds at nanosecond
|
|
4
|
+
* resolution in UTC Epoch time.
|
|
5
|
+
*
|
|
6
|
+
* It is encoded using the Proleptic Gregorian Calendar which extends the
|
|
7
|
+
* Gregorian calendar backwards to year one. It is encoded assuming all minutes
|
|
8
|
+
* are 60 seconds long, i.e. leap seconds are "smeared" so that no leap second
|
|
9
|
+
* table is needed for interpretation. Range is from 0001-01-01T00:00:00Z to
|
|
10
|
+
* 9999-12-31T23:59:59.999999999Z.
|
|
11
|
+
*
|
|
12
|
+
* For examples and further specifications, refer to the
|
|
13
|
+
* {@link https://github.com/google/protobuf/blob/master/src/google/protobuf/timestamp.proto | Timestamp definition}.
|
|
14
|
+
*/
|
|
15
|
+
export declare class Timestamp {
|
|
16
|
+
readonly seconds: number;
|
|
17
|
+
readonly nanoseconds: number;
|
|
18
|
+
|
|
19
|
+
constructor(seconds: number, nanoseconds: number);
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Creates a new timestamp with the current date, with millisecond precision.
|
|
23
|
+
*
|
|
24
|
+
* @returns a new timestamp representing the current date.
|
|
25
|
+
*/
|
|
26
|
+
static now(): Timestamp;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Creates a new timestamp from the given date.
|
|
30
|
+
*
|
|
31
|
+
* @param date - The date to initialize the `Timestamp` from.
|
|
32
|
+
* @returns A new `Timestamp` representing the same point in time as the given
|
|
33
|
+
* date.
|
|
34
|
+
*/
|
|
35
|
+
static fromDate(date: Date): Timestamp;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Creates a new timestamp from the given number of milliseconds.
|
|
39
|
+
*
|
|
40
|
+
* @param milliseconds - Number of milliseconds since Unix epoch
|
|
41
|
+
* 1970-01-01T00:00:00Z.
|
|
42
|
+
* @returns A new `Timestamp` representing the same point in time as the given
|
|
43
|
+
* number of milliseconds.
|
|
44
|
+
*/
|
|
45
|
+
static fromMillis(milliseconds: number): Timestamp;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Converts a `Timestamp` to a JavaScript `Date` object. This conversion
|
|
49
|
+
* causes a loss of precision since `Date` objects only support millisecond
|
|
50
|
+
* precision.
|
|
51
|
+
*
|
|
52
|
+
* @returns JavaScript `Date` object representing the same point in time as
|
|
53
|
+
* this `Timestamp`, with millisecond precision.
|
|
54
|
+
*/
|
|
55
|
+
toDate(): Date;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Converts a `Timestamp` to a numeric timestamp (in milliseconds since
|
|
59
|
+
* epoch). This operation causes a loss of precision.
|
|
60
|
+
*
|
|
61
|
+
* @returns The point in time corresponding to this timestamp, represented as
|
|
62
|
+
* the number of milliseconds since Unix epoch 1970-01-01T00:00:00Z.
|
|
63
|
+
*/
|
|
64
|
+
toMillis(): number;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Returns true if this `Timestamp` is equal to the provided one.
|
|
68
|
+
*
|
|
69
|
+
* @param other - The `Timestamp` to compare against.
|
|
70
|
+
* @returns true if this `Timestamp` is equal to the provided one.
|
|
71
|
+
*/
|
|
72
|
+
isEqual(other: Timestamp): boolean;
|
|
73
|
+
|
|
74
|
+
/** Returns a JSON-serializable representation of this `Timestamp`. */
|
|
75
|
+
toJSON(): { seconds: number; nanoseconds: number };
|
|
76
|
+
|
|
77
|
+
/** Returns a textual representation of this `Timestamp`. */
|
|
78
|
+
toString(): string;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Converts this object to a primitive string, which allows `Timestamp` objects
|
|
82
|
+
* to be compared using the `>`, `<=`, `>=` and `>` operators.
|
|
83
|
+
*/
|
|
84
|
+
valueOf(): string;
|
|
85
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,9 +1,2 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./ticket";
|
|
4
|
-
export * from "./user";
|
|
5
|
-
export * from "./city";
|
|
6
|
-
export * from "./other";
|
|
7
|
-
export * from "./analytics";
|
|
8
|
-
export * from "./festivals/festival";
|
|
9
|
-
export * from "./festivals/user";
|
|
1
|
+
export * from "./types";
|
|
2
|
+
export * from "./utils/date";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Timestamp } from "
|
|
1
|
+
import { Timestamp } from "../Timestamp";
|
|
2
2
|
import { City } from "./city";
|
|
3
3
|
import { OrganizerName } from "./organizer";
|
|
4
4
|
import { EventTicket } from "./ticket";
|
|
@@ -12,6 +12,7 @@ export type Organizer = {
|
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
export type Links = {
|
|
15
|
+
paymentLink?: string;
|
|
15
16
|
instagram?: string;
|
|
16
17
|
facebook?: string;
|
|
17
18
|
website?: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Timestamp } from "
|
|
1
|
+
import { Timestamp } from "../../Timestamp";
|
|
2
2
|
import { Links } from "../event";
|
|
3
|
-
import { DanceTag } from "wedance-shared";
|
|
3
|
+
import { DanceTag, EventTicket } from "wedance-shared";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* This is the type of the data we get from the server
|
|
@@ -10,7 +10,7 @@ export type FestivalData = {
|
|
|
10
10
|
title: string;
|
|
11
11
|
from: Timestamp;
|
|
12
12
|
until: Timestamp;
|
|
13
|
-
organizerId: string;
|
|
13
|
+
organizerId: string[];
|
|
14
14
|
description: string;
|
|
15
15
|
location: FestivalLocation[];
|
|
16
16
|
|
|
@@ -19,9 +19,6 @@ export type FestivalData = {
|
|
|
19
19
|
|
|
20
20
|
imageData: FestivalImageData[];
|
|
21
21
|
|
|
22
|
-
countryCode: string; // ISO 3166-1 Alpha-2 (e.g., "SE", "FI", "EE")
|
|
23
|
-
region: Region[]; // e.g., ["Nordics"], ["Baltics"], ["Europe"]
|
|
24
|
-
|
|
25
22
|
priceRange?: { min: number; max: number; currency: string };
|
|
26
23
|
|
|
27
24
|
createdAt: Timestamp;
|
|
@@ -35,6 +32,7 @@ export type FestivalData = {
|
|
|
35
32
|
isFree: boolean;
|
|
36
33
|
|
|
37
34
|
artists: FestivalArtist[];
|
|
35
|
+
tickets?: EventTicket[];
|
|
38
36
|
};
|
|
39
37
|
|
|
40
38
|
type FestivalGenre = "salsa" | "bachata" | "kizomba" | "zouk";
|
|
@@ -45,18 +43,18 @@ type FestivalImageData = {
|
|
|
45
43
|
blurhash?: string;
|
|
46
44
|
};
|
|
47
45
|
|
|
48
|
-
type FestivalLocation = {
|
|
49
|
-
id?: string; // Firestore auto-generates if not provided
|
|
46
|
+
export type FestivalLocation = {
|
|
50
47
|
city: string; // e.g., "Stockholm"
|
|
51
48
|
countryCode: string; // ISO 3166-1 (e.g., "SE" for Sweden)
|
|
49
|
+
country: string;
|
|
52
50
|
address?: string; // Optional detailed address (e.g., "Arenavägen 75")
|
|
53
51
|
venue?: string; // Optional (e.g., "Avicii Arena")
|
|
54
52
|
geoLocation?: { lat: number; lng: number }; // For maps
|
|
55
53
|
timeZone: string; // e.g., "Europe/Stockholm"
|
|
56
|
-
region
|
|
54
|
+
region: Region[]; // e.g., "Nordics", "Baltics"
|
|
57
55
|
};
|
|
58
56
|
|
|
59
|
-
type FestivalArtist = {
|
|
57
|
+
export type FestivalArtist = {
|
|
60
58
|
id: string;
|
|
61
59
|
name: string;
|
|
62
60
|
image: string;
|
|
@@ -64,7 +62,7 @@ type FestivalArtist = {
|
|
|
64
62
|
role: FestivalArtistRole;
|
|
65
63
|
};
|
|
66
64
|
|
|
67
|
-
type FestivalArtistRole =
|
|
65
|
+
export type FestivalArtistRole =
|
|
68
66
|
| "dj"
|
|
69
67
|
| "dancer"
|
|
70
68
|
| "mc"
|
|
@@ -72,7 +70,7 @@ type FestivalArtistRole =
|
|
|
72
70
|
| "organizer"
|
|
73
71
|
| "media";
|
|
74
72
|
|
|
75
|
-
type Region =
|
|
73
|
+
export type Region =
|
|
76
74
|
| "Nordics"
|
|
77
75
|
| "Baltics"
|
|
78
76
|
| "Western Europe"
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Re-export all types from individual files
|
|
2
|
+
export * from "./event";
|
|
3
|
+
export * from "./ticket";
|
|
4
|
+
export * from "./city";
|
|
5
|
+
export * from "./organizer";
|
|
6
|
+
export * from "./user";
|
|
7
|
+
export * from "./other";
|
|
8
|
+
export * from "./analytics";
|
|
9
|
+
|
|
10
|
+
// Re-export from subdirectories
|
|
11
|
+
export * from "./festivals";
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import dayjs from "dayjs";
|
|
2
|
+
import relativeTime from "dayjs/plugin/relativeTime";
|
|
3
|
+
import { Timestamp } from "../Timestamp";
|
|
4
|
+
|
|
5
|
+
// Register the relativeTime plugin
|
|
6
|
+
dayjs.extend(relativeTime);
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Converts a Firestore Timestamp to a JavaScript Date object
|
|
10
|
+
* @param timestamp Firestore Timestamp or null/undefined
|
|
11
|
+
* @returns JavaScript Date object or null if input is null/undefined
|
|
12
|
+
*/
|
|
13
|
+
export const timestampToDate = (
|
|
14
|
+
timestamp: Timestamp | null | undefined
|
|
15
|
+
): Date | null => {
|
|
16
|
+
if (!timestamp) return null;
|
|
17
|
+
return new Date(timestamp.seconds * 1000 + timestamp.nanoseconds / 1000000);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Converts a JavaScript Date to a Firestore Timestamp
|
|
22
|
+
* @param date JavaScript Date object or null/undefined
|
|
23
|
+
* @returns Firestore Timestamp or null if input is null/undefined
|
|
24
|
+
*/
|
|
25
|
+
export const dateToTimestamp = (
|
|
26
|
+
date: Date | null | undefined
|
|
27
|
+
): Timestamp | null => {
|
|
28
|
+
if (!date) return null;
|
|
29
|
+
return Timestamp.fromDate(date);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Formats a Firestore Timestamp to a string using the provided format
|
|
34
|
+
* Uses day.js library - install with: npm install dayjs
|
|
35
|
+
* @param timestamp Firestore Timestamp or null/undefined
|
|
36
|
+
* @param formatStr Format string compatible with day.js format function
|
|
37
|
+
* (see https://day.js.org/docs/en/display/format for format options)
|
|
38
|
+
* @param defaultValue Value to return if timestamp is null/undefined
|
|
39
|
+
* @returns Formatted date string or defaultValue if timestamp is null/undefined
|
|
40
|
+
*/
|
|
41
|
+
export const formatTimestamp = (
|
|
42
|
+
timestamp: Timestamp | null | undefined,
|
|
43
|
+
formatStr: string = "MMM D, YYYY",
|
|
44
|
+
defaultValue: string = ""
|
|
45
|
+
): string => {
|
|
46
|
+
if (!timestamp) return defaultValue;
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
// Convert timestamp to Date
|
|
50
|
+
const date = new Date(
|
|
51
|
+
timestamp.seconds * 1000 + timestamp.nanoseconds / 1000000
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
// Use dayjs to format the date according to the format string
|
|
55
|
+
return dayjs(date).format(formatStr);
|
|
56
|
+
} catch (error) {
|
|
57
|
+
console.error("Error formatting timestamp:", error);
|
|
58
|
+
return defaultValue;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Checks if a Firestore Timestamp is before current time
|
|
64
|
+
* @param timestamp Firestore Timestamp to check
|
|
65
|
+
* @returns boolean indicating if timestamp is in the past
|
|
66
|
+
*/
|
|
67
|
+
export const isTimestampInPast = (
|
|
68
|
+
timestamp: Timestamp | null | undefined
|
|
69
|
+
): boolean => {
|
|
70
|
+
if (!timestamp) return false;
|
|
71
|
+
|
|
72
|
+
// Convert timestamp to milliseconds manually
|
|
73
|
+
const timestampMillis =
|
|
74
|
+
timestamp.seconds * 1000 + timestamp.nanoseconds / 1000000;
|
|
75
|
+
return timestampMillis < Date.now();
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Checks if a Firestore Timestamp is after current time
|
|
80
|
+
* @param timestamp Firestore Timestamp to check
|
|
81
|
+
* @returns boolean indicating if timestamp is in the future
|
|
82
|
+
*/
|
|
83
|
+
export const isTimestampInFuture = (
|
|
84
|
+
timestamp: Timestamp | null | undefined
|
|
85
|
+
): boolean => {
|
|
86
|
+
if (!timestamp) return false;
|
|
87
|
+
|
|
88
|
+
// Convert timestamp to milliseconds manually
|
|
89
|
+
const timestampMillis =
|
|
90
|
+
timestamp.seconds * 1000 + timestamp.nanoseconds / 1000000;
|
|
91
|
+
return timestampMillis > Date.now();
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Gets the relative time between now and a Firestore Timestamp (e.g. "2 hours ago", "in 3 days")
|
|
96
|
+
* Uses day.js with relativeTime plugin for localized relative time formatting
|
|
97
|
+
* @param timestamp Firestore Timestamp
|
|
98
|
+
* @returns String representation of relative time
|
|
99
|
+
*/
|
|
100
|
+
export const getRelativeTime = (
|
|
101
|
+
timestamp: Timestamp | null | undefined
|
|
102
|
+
): string => {
|
|
103
|
+
if (!timestamp) return "";
|
|
104
|
+
|
|
105
|
+
try {
|
|
106
|
+
// Convert timestamp to milliseconds manually
|
|
107
|
+
const timestampMillis =
|
|
108
|
+
timestamp.seconds * 1000 + timestamp.nanoseconds / 1000000;
|
|
109
|
+
|
|
110
|
+
// Use dayjs to get relative time
|
|
111
|
+
return dayjs(timestampMillis).fromNow();
|
|
112
|
+
} catch (error) {
|
|
113
|
+
console.error("Error generating relative time:", error);
|
|
114
|
+
return "";
|
|
115
|
+
}
|
|
116
|
+
};
|
package/dist/city.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"city.js","sourceRoot":"","sources":["../src/city.ts"],"names":[],"mappings":"AAgCA,MAAM,CAAC,MAAM,WAAW,GAAe;IACrC;QACE,IAAI,EAAE,UAAU;QAChB,OAAO,EAAE,IAAI;QACb,WAAW,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC;KAChC;IACD;QACE,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,IAAI;QACb,WAAW,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC;KAC/B;IACD;QACE,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,IAAI;QACb,WAAW,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC;KAChC;IACD,IAAI;IACJ,uBAAuB;IACvB,mBAAmB;IACnB,KAAK;IACL;QACE,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,IAAI;QACb,WAAW,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC;KAC/B;IACD;QACE,IAAI,EAAE,YAAY;QAClB,OAAO,EAAE,IAAI;QACb,WAAW,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC;KAChC;IACD;QACE,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,IAAI;QACb,WAAW,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC;KAC9B;CACF,CAAC;AAMF,MAAM,CAAN,IAAY,QAKX;AALD,WAAY,QAAQ;IAClB,uCAA2B,CAAA;IAC3B,yCAA6B,CAAA;IAC7B,uCAA2B,CAAA;IAC3B,kCAAsB,CAAA;AACxB,CAAC,EALW,QAAQ,KAAR,QAAQ,QAKnB"}
|
package/dist/event.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"event.js","sourceRoot":"","sources":["../src/event.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"festival.js","sourceRoot":"","sources":["../../src/festivals/festival.ts"],"names":[],"mappings":""}
|
package/dist/other.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"other.js","sourceRoot":"","sources":["../src/other.ts"],"names":[],"mappings":""}
|
package/dist/ticket.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ticket.js","sourceRoot":"","sources":["../src/ticket.ts"],"names":[],"mappings":""}
|
package/dist/user.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"user.js","sourceRoot":"","sources":["../src/user.ts"],"names":[],"mappings":""}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|