Skip to content

Commit

Permalink
Merge pull request #420 from ITPNYU/hotfix/time_zone
Browse files Browse the repository at this point in the history
Fix time zone function
  • Loading branch information
rlho authored Sep 25, 2024
2 parents 4ff6f1f + 0c54061 commit 33a057d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions booking-app/app.development.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ automatic_scaling:
env_variables:
NEXT_PUBLIC_BRANCH_NAME: "development"
NODE_OPTIONS: "--max-old-space-size=4096"
TZ: "America/New_York"

build_env_variables:
NODE_OPTIONS: "--max-old-space-size=4096"
Expand Down
1 change: 1 addition & 0 deletions booking-app/app.production.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ automatic_scaling:
env_variables:
NEXT_PUBLIC_BRANCH_NAME: "production"
NODE_OPTIONS: "--max-old-space-size=4096"
TZ: "America/New_York"

build_env_variables:
NODE_OPTIONS: "--max-old-space-size=4096"
Expand Down
1 change: 1 addition & 0 deletions booking-app/app.staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ automatic_scaling:
env_variables:
NEXT_PUBLIC_BRANCH_NAME: "staging"
NODE_OPTIONS: "--max-old-space-size=4096"
TZ: "America/New_York"

build_env_variables:
NODE_OPTIONS: "--max-old-space-size=4096"
Expand Down
22 changes: 16 additions & 6 deletions booking-app/components/src/client/utils/serverDate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Timestamp } from "firebase-admin/firestore";
import { format } from "date-fns";
import { toZonedTime } from "date-fns-tz";
import { parseISO } from "date-fns";
import { format } from "date-fns-tz";

type DateInput = Date | Timestamp | { [key: string]: any } | number | string;

Expand All @@ -16,15 +17,24 @@ const parseTimestamp = (value: DateInput): Timestamp => {
};

export const serverFormatDate = (
input: DateInput,
input: string,
timeZone: string = "America/New_York"
): string => {
if (!input) return "";
try {
const timestamp = parseTimestamp(input);
const utcDate = timestamp.toDate();
const zonedDate = toZonedTime(utcDate, timeZone);
const formattedResult = format(zonedDate, "yyyy-MM-dd hh:mm a");
const date = new Date(input);

const zonedDate = toZonedTime(date, timeZone);

const formattedResult = format(zonedDate, "yyyy-MM-dd hh:mm a", {
timeZone,
});

console.log("Input:", input);
console.log("Parsed Date:", date.toISOString());
console.log("Zoned Date:", zonedDate.toString());
console.log("Formatted Result:", formattedResult);
console.log("Timezone:", timeZone);

return formattedResult;
} catch (error) {
Expand Down

0 comments on commit 33a057d

Please sign in to comment.