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

change for converting date to local timezone #271

Merged
merged 2 commits into from
Jan 31, 2025
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
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ArrowForwardIos } from "@mui/icons-material";
import dateUtils from "@/utils/dateUtils";
import { Link, Typography } from "@mui/material";
import { BCDesignTokens } from "epic.theme";
import { SubmissionPackage } from "@/models/Package";
import dayjs from "dayjs";
import { PackageStatusChipStack } from "../../PackageStatusChip/PackageStatusChipStack";
import {
StyledProjectTableCell,
Expand Down Expand Up @@ -47,9 +47,7 @@ export default function ProponentTableRow({ subPackage }: ProjectRowProps) {
</Link>
</StyledProjectTableCell>
<StyledProjectTableCell align="left">
{subPackage.submitted_on
? dayjs(subPackage.submitted_on).format("DD-MMM-YYYY")
: ""}
{dateUtils.formatDate(String(subPackage.submitted_on))}
</StyledProjectTableCell>
<StyledProjectTableCell align="left">
{subPackage.submitted_by ?? ""}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ArrowForwardIos } from "@mui/icons-material";
import dateutils from "@/utils/dateUtils";
import { Stack, Typography } from "@mui/material";
import { BCDesignTokens } from "epic.theme";
import { SubmissionPackage } from "@/models/Package";
Expand Down Expand Up @@ -96,7 +97,7 @@ export default function StaffTableRow({ submissionPackage }: ProjectRowProps) {
color: BCDesignTokens.typographyFontSizeBody,
}}
>
{submitted_on ? dayjs(submitted_on).format("DD-MMM-YYYY") : ""}
{dateutils.formatDate(String(submitted_on))}
</StyledProjectTableCell>
<StyledProjectTableCell
align="right"
Expand All @@ -116,7 +117,7 @@ export default function StaffTableRow({ submissionPackage }: ProjectRowProps) {
maxWidth: "75px",
}}
>
{cc_completed_on ? dayjs(cc_completed_on).format("DD-MMM-YYYY") : ""}
{dateutils.formatDate(cc_completed_on)}
</StyledProjectTableCell>
<StyledProjectTableCell
align="right"
Expand Down
20 changes: 8 additions & 12 deletions submit-web/src/components/Submission/InfoBox.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import dateUtils from "@/utils/dateUtils";
import { SubmissionPackage } from "@/models/Package";
import { USER_TYPE } from "@/models/User";
import { useAccount } from "@/store/accountStore";
import { Grid, Typography } from "@mui/material";
import { ReactNode } from "@tanstack/react-router";
import dayjs from "dayjs";
import { BCDesignTokens } from "epic.theme";
import { Case, Switch } from "react-if";
import VersionGroup from "./VersionGroup";
Expand Down Expand Up @@ -82,13 +82,13 @@ const ProponentInfoBox = ({ submissionPackage }: InfoBoxProps) => {
<Grid item xs={12} lg={4} container>
<InfoBoxItem
label={"Submitted on"}
value={submitted_on ? dayjs(submitted_on).format("DD-MMM-YYYY") : ""}
value={dateUtils.formatDate(submitted_on)}
/>
</Grid>
<Grid item xs={12} lg={4} container>
<InfoBoxItem
label={"Date Review Completed"}
value={date_review_completed}
value={dateUtils.formatDate(date_review_completed)}
/>
</Grid>
<Grid item xs={12} lg={4} container>
Expand Down Expand Up @@ -139,7 +139,7 @@ const StaffInfoBox = ({ submissionPackage }: InfoBoxProps) => {
<Grid item xs={12} lg={4} container>
<InfoBoxItem
label={"Submitted on"}
value={submitted_on ? dayjs(submitted_on).format("DD-MMM-YYYY") : ""}
value={dateUtils.formatDate(String(submitted_on))}
/>
</Grid>
<Grid item xs={12} lg={4} container>
Expand All @@ -149,7 +149,7 @@ const StaffInfoBox = ({ submissionPackage }: InfoBoxProps) => {
<InfoBoxItem
label={"CC Start Date"}
value={
cc_start_date ? dayjs(cc_start_date).format("DD-MMM-YYYY") : ""
dateUtils.formatDate(cc_start_date)
}
/>
</Grid>
Expand All @@ -166,7 +166,7 @@ const StaffInfoBox = ({ submissionPackage }: InfoBoxProps) => {
<InfoBoxItem
label={"CC Completed"}
value={
cc_completed_on ? dayjs(cc_completed_on).format("DD-MMM-YYYY") : ""
dateUtils.formatDate(cc_completed_on)
}
/>
</Grid>
Expand All @@ -176,9 +176,7 @@ const StaffInfoBox = ({ submissionPackage }: InfoBoxProps) => {
<InfoBoxItem
label={"Review Start Date"}
value={
review_start_date
? dayjs(review_start_date).format("DD-MMM-YYYY")
: ""
dateUtils.formatDate(review_start_date)
}
/>
</Grid>
Expand All @@ -194,9 +192,7 @@ const StaffInfoBox = ({ submissionPackage }: InfoBoxProps) => {
<InfoBoxItem
label={"Review Completed"}
value={
review_completed_on
? dayjs(review_completed_on).format("DD-MMM-YYYY")
: ""
dateUtils.formatDate(review_completed_on)
}
/>
</Grid>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Box, Typography } from "@mui/material";
import { BCDesignTokens } from "epic.theme";
import dayjs from "dayjs";
import dateUtils from "@/utils/dateUtils";
import { UPDATE_REQUEST_TYPE, UpdateRequest } from "@/models/UpdateRequest";
import { Case, Switch, Unless, When } from "react-if";
import { AddRequestNoteSection } from "./AddRequestNoteSection";
Expand All @@ -20,7 +20,7 @@ export default function RequestSection({
}: UpdateRequestProps) {
const { reason, created_date, created_by, note, type, submission_item_ids } =
updateRequest;
const createdDate = dayjs(created_date).format("DD-MMM-YYYY");
const createdDate = dateUtils.formatDate(created_date)

const { roles } = useAccount();
const isEAO = checkIfEAO(roles || []);
Expand Down
40 changes: 40 additions & 0 deletions submit-web/src/utils/dateUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import dayjs, { Dayjs } from "dayjs";
import utc from "dayjs/plugin/utc";


type UnitOfTime = "second" | "minute" | "hour" | "day" | "month" | "year";

export const DATE_FORMAT = "YYYY-MM-DD";
export const DATE_TIME_FORMAT = "YYYY-MM-DD HH:mm";

dayjs.extend(utc);
/**
* @param date Input date string
* @param format Valid date format
* @returns Formatted date string
*/
const formatDate = (date: string | number, format?: string) => {
if (!date) return ""; // Handle null or undefined values

// server date is in UTC, convert to local timezone
return dayjs.utc(String(date)).local().format(format || DATE_FORMAT);
};

const diff = (fromDate: string, toDate: string, unitOfTime: UnitOfTime) => {
return dayjs(fromDate).diff(dayjs(toDate), unitOfTime);
};

const add = (date: Date, unit: number, unitOfTime: UnitOfTime) => {
return dayjs(date).add(unit, unitOfTime);
};

const dateToISO = (date: Date | Dayjs) => {
return dayjs(date).toISOString();
};

export default {
formatDate,
diff,
add,
dateToISO,
};