From d50f22f32eb45b8f21f3a44034dc22c3af72f9b3 Mon Sep 17 00:00:00 2001 From: /Aljoscha Date: Sat, 18 Nov 2023 13:30:15 +0100 Subject: [PATCH 1/2] rename formatDate file to dateTime --- components/ContactDetailsHeader/ContactDetailsHeader.js | 2 +- components/InteractionDetailsHeader/InteractionDetailsHeader.js | 2 +- components/InteractionListItem/InteractionListItem.js | 2 +- pages/interactions/[id]/edit/index.js | 2 +- pages/interactions/[id]/index.js | 2 +- utils/{formatDates.js => dateTime.js} | 0 6 files changed, 5 insertions(+), 5 deletions(-) rename utils/{formatDates.js => dateTime.js} (100%) diff --git a/components/ContactDetailsHeader/ContactDetailsHeader.js b/components/ContactDetailsHeader/ContactDetailsHeader.js index 54ff2f5..510af3b 100644 --- a/components/ContactDetailsHeader/ContactDetailsHeader.js +++ b/components/ContactDetailsHeader/ContactDetailsHeader.js @@ -15,7 +15,7 @@ import { materialUpload, } from "@/assets/Icons8"; import Image from "next/image"; -import { formatDate } from "@/utils/formatDates"; +import { formatDate } from "@/utils/dateTime"; import UploadImageModal from "../UploadImageModal/UploadImageModal"; const customStyles = { diff --git a/components/InteractionDetailsHeader/InteractionDetailsHeader.js b/components/InteractionDetailsHeader/InteractionDetailsHeader.js index 8389a43..9ddba27 100644 --- a/components/InteractionDetailsHeader/InteractionDetailsHeader.js +++ b/components/InteractionDetailsHeader/InteractionDetailsHeader.js @@ -6,7 +6,7 @@ import { StyledHeader, } from "./InteractionDetailsHeader.styled"; import { getInteractionIcon } from "@/utils/getInteractionDetails"; -import { formatDate } from "@/utils/formatDates"; +import { formatDate } from "@/utils/dateTime"; import { useMemo } from "react"; export default function InteractionDetailsHeader({ interaction }) { diff --git a/components/InteractionListItem/InteractionListItem.js b/components/InteractionListItem/InteractionListItem.js index 44d1ebe..c6ea6e9 100644 --- a/components/InteractionListItem/InteractionListItem.js +++ b/components/InteractionListItem/InteractionListItem.js @@ -9,7 +9,7 @@ import { ParticipantsContainer, StyledLink, } from "./InteractionListItem.styled"; -import { formatDate } from "@/utils/formatDates"; +import { formatDate } from "@/utils/dateTime"; import { getFullSortName, getShortName } from "@/utils/getContactDetails"; import Image from "next/image"; import { useMemo } from "react"; diff --git a/pages/interactions/[id]/edit/index.js b/pages/interactions/[id]/edit/index.js index 1f43bed..3d7f747 100644 --- a/pages/interactions/[id]/edit/index.js +++ b/pages/interactions/[id]/edit/index.js @@ -1,6 +1,6 @@ import InteractionForm from "@/components/Forms/InteractionForm/InteractionForm"; import DefaultHead from "@/components/Layout/DefaultHead/DefaultHead"; -import { formatDate } from "@/utils/formatDates"; +import { formatDate } from "@/utils/dateTime"; import { useRouter } from "next/router"; export default function EditInteractionPage({ diff --git a/pages/interactions/[id]/index.js b/pages/interactions/[id]/index.js index ae8a918..f1d1f8a 100644 --- a/pages/interactions/[id]/index.js +++ b/pages/interactions/[id]/index.js @@ -14,7 +14,7 @@ import styled from "styled-components"; import { confirmAlert } from "react-confirm-alert"; import ConfirmModal from "@/components/ConfirmModal/ConfirmModal"; import DefaultHead from "@/components/Layout/DefaultHead/DefaultHead"; -import { formatDate } from "@/utils/formatDates"; +import { formatDate } from "@/utils/dateTime"; const ActionButtons = styled.div` display: flex; diff --git a/utils/formatDates.js b/utils/dateTime.js similarity index 100% rename from utils/formatDates.js rename to utils/dateTime.js From af524fa49afaed7a1e5bbebc7d8484e1aa822744 Mon Sep 17 00:00:00 2001 From: /Aljoscha Date: Sat, 18 Nov 2023 14:21:41 +0100 Subject: [PATCH 2/2] implement new function getCurrentTimestamp --- pages/_app.js | 19 ++++++++++--------- utils/dateTime.js | 7 +++++++ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/pages/_app.js b/pages/_app.js index b1990dd..7f23586 100644 --- a/pages/_app.js +++ b/pages/_app.js @@ -7,6 +7,7 @@ import { uid } from "uid"; import Chance from "chance"; import { ToastContainer, toast } from "react-toastify"; import "react-toastify/dist/ReactToastify.css"; +import { getCurrentTimestamp } from "@/utils/dateTime"; export default function App({ Component, pageProps }) { const router = useRouter(); @@ -21,9 +22,6 @@ export default function App({ Component, pageProps }) { (contact) => contact.dateDeleted === null || contact.dateDeleted === "" ); - const date = new Date(); - const currentUtcDateTime = date.toISOString(); - function handleImportDemoContacts() { const demoContact = contactsSampleData.map((contact) => { return { id: uid(), ...contact }; @@ -97,7 +95,7 @@ export default function App({ Component, pageProps }) { const formattedContact = { ...newContact, id: newContactId, - dateCreated: currentUtcDateTime, + dateCreated: getCurrentTimestamp(), dateDeleted: "", deceased: newContact.deceased ? true : false, }; @@ -114,7 +112,7 @@ export default function App({ Component, pageProps }) { setContacts( contacts.map((contact) => { if (contact.id === updatedContact.id) { - return { ...updatedContact, dateLastUpdate: currentUtcDateTime }; + return { ...updatedContact, dateLastUpdate: getCurrentTimestamp() }; } else { return contact; } @@ -131,7 +129,7 @@ export default function App({ Component, pageProps }) { setContacts( contacts.map((contact) => { if (contact.id === IdOfContactToDelete) { - return { ...contact, dateDeleted: currentUtcDateTime }; + return { ...contact, dateDeleted: getCurrentTimestamp() }; } else { return contact; } @@ -151,7 +149,7 @@ export default function App({ Component, pageProps }) { const formattedInteraction = { ...newInteraction, id: newInteractionId, - dateCreated: currentUtcDateTime, + dateCreated: getCurrentTimestamp(), dateDeleted: "", }; @@ -167,7 +165,10 @@ export default function App({ Component, pageProps }) { setInteractions( interactions.map((interaction) => { if (interaction.id === updatedInteraction.id) { - return { ...updatedInteraction, dateLastUpdate: currentUtcDateTime }; + return { + ...updatedInteraction, + dateLastUpdate: getCurrentTimestamp(), + }; } else { return interaction; } @@ -184,7 +185,7 @@ export default function App({ Component, pageProps }) { setInteractions( interactions.map((interaction) => { if (interaction.id === IdOfInteractionToDelete) { - return { ...interaction, dateDeleted: currentUtcDateTime }; + return { ...interaction, dateDeleted: getCurrentTimestamp() }; } else { return interaction; } diff --git a/utils/dateTime.js b/utils/dateTime.js index 3cb49da..4026871 100644 --- a/utils/dateTime.js +++ b/utils/dateTime.js @@ -4,3 +4,10 @@ export function formatDate(initialDate) { const formattedDate = dateObject.toLocaleDateString("en-US", options); return formattedDate; } + +export function getCurrentTimestamp() { + const currentTime = new Date(); + const currentIsoTime = currentTime.toISOString(); + + return currentIsoTime; +}