Skip to content

Commit

Permalink
more tz fixes - utc with local time only in converter, snyk readme fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dylmye committed Jul 8, 2023
1 parent ae02778 commit abddfd8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<p align="center">
<a href="https://github.com/dylmye/lets-plan/actions/workflows/firebase-hosting-merge.yml"><img alt="The status badge for this project's build" src="https://img.shields.io/github/actions/workflow/status/dylmye/lets-plan/firebase-hosting-merge.yml?logo=github"></a>
<a href="https://app.fossa.com/projects/git%2Bgithub.com%2Fdylmye%2Flets-plan?ref=badge_shield"><img alt="FOSSA status" src="https://app.fossa.com/api/projects/git%2Bgithub.com%2Fdylmye%2Flets-plan.svg?type=shield"></a>
<a href="https://snyk.io"><img alt="The status badge for the Snyk-detected vulnerabilities count for this project" src="https://img.shields.io/snyk/vulnerabilities/github/dylmye/lets-plan?logo=snyk"></a>
<a href="https://snyk.io"><img alt="This project is scanned by Snyk" src="https://snyk.io/test/github/dylmye/lets-plan/badge.svg"></a>
</p>

<p align="center">
Expand Down
4 changes: 2 additions & 2 deletions src/components/TripItineraryItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ const TripItineraryItem = ({
updateTripItem(trip.id, {
...values,
id: item.id,
startsAt: dayjs(values.startsAt).utc(true).toISOString(),
endsAt: values?.endsAt && dayjs(values.endsAt).utc(true).toISOString(),
startsAt: dayjs(values.startsAt).format(),
endsAt: values?.endsAt && dayjs(values.endsAt).format(),
});
onToggleEditTripItem(item.id, false);
};
Expand Down
11 changes: 7 additions & 4 deletions src/helpers/converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ export const convertDateStringToTimestamp = (date: string): Timestamp =>
export const convertTripDocument: FirestoreDataConverter<Trip> = {
toFirestore(trip: Trip): TripSnapshot {
const startsAt =
trip.startsAt && dayjs.utc(trip.startsAt).startOf("day").format();
const endsAt = trip.endsAt && dayjs.utc(trip.endsAt).endOf("day").format();
trip.startsAt && dayjs(trip.startsAt).utc(true).startOf("day").format();
const endsAt =
trip.endsAt && dayjs(trip.endsAt).utc(true).endOf("day").format();

return {
...trip,
Expand Down Expand Up @@ -91,11 +92,13 @@ export const convertTripItemDocuments: FirestoreDataConverter<TripItem> = {
tripItem[k] =
!!tripItem[k as keyof TripItem] &&
convertDateStringToTimestamp(
dayjs.utc(tripItem[k as keyof TripItem] as string).format()
dayjs(tripItem[k as keyof TripItem] as string)
.utc(true)
.format()
);
});

const startsAt = dayjs.utc(tripItem.startsAt).format();
const startsAt = dayjs(tripItem.startsAt).utc(true).format();

return {
...tripItem,
Expand Down
6 changes: 4 additions & 2 deletions src/store/features/trips/firestore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,13 @@ const deleteTripById: TripActions["deleteTripById"] = async (id) => {
};

const updateTripById: TripActions["updateTripById"] = async (data) => {
const startsAt = data.startsAt && dayjs(data.startsAt).utc(true).format();
const endsAt = data.endsAt && dayjs(data.endsAt).utc(true).format();
try {
await updateDoc(doc(tripsRef, data.id), {
...data,
startsAt: convertDateStringToTimestamp(data.startsAt as string),
endsAt: convertDateStringToTimestamp(data.endsAt as string),
startsAt: convertDateStringToTimestamp(startsAt!),
endsAt: convertDateStringToTimestamp(endsAt!),
updatedAtUtc: serverTimestamp(),
});
} catch (e) {
Expand Down

0 comments on commit abddfd8

Please sign in to comment.