Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix timestamp creation #44

Merged
merged 2 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/ContactDetailsHeader/ContactDetailsHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) {
Expand Down
2 changes: 1 addition & 1 deletion components/InteractionListItem/InteractionListItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
19 changes: 10 additions & 9 deletions pages/_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 };
Expand Down Expand Up @@ -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,
};
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -151,7 +149,7 @@ export default function App({ Component, pageProps }) {
const formattedInteraction = {
...newInteraction,
id: newInteractionId,
dateCreated: currentUtcDateTime,
dateCreated: getCurrentTimestamp(),
dateDeleted: "",
};

Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion pages/interactions/[id]/edit/index.js
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
2 changes: 1 addition & 1 deletion pages/interactions/[id]/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions utils/formatDates.js → utils/dateTime.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}