Skip to content
This repository was archived by the owner on May 3, 2025. It is now read-only.

Commit c9c2161

Browse files
feat: replace luxon with date-fns, gate holiday mode to jan/dec
1 parent 4c3e4c4 commit c9c2161

File tree

4 files changed

+47
-43
lines changed

4 files changed

+47
-43
lines changed

package-lock.json

Lines changed: 18 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"@mantine/hooks": "4.2.1",
1717
"@octokit/rest": "18.12.0",
1818
"@supabase/supabase-js": "1.35.4",
19+
"date-fns": "2.29.3",
1920
"evergreen-ui": "6.13.2",
2021
"glamor": "2.20.40",
2122
"harmonics": "1.1.0",
@@ -24,7 +25,6 @@
2425
"jotai": "1.11.2",
2526
"keymirror": "0.1.1",
2627
"lodash": "4.17.21",
27-
"luxon": "3.0.1",
2828
"opus-media-recorder": "0.8.0",
2929
"react": "18.1.0",
3030
"react-beautiful-dnd": "13.1.0",
@@ -57,7 +57,6 @@
5757
"@types/jest": "26.0.24",
5858
"@types/keymirror": "0.1.1",
5959
"@types/lodash": "4.14.172",
60-
"@types/luxon": "2.0.5",
6160
"@types/node": "12.20.19",
6261
"@types/pluralize": "0.0.29",
6362
"@types/react": "17.0.18",

src/components/sidebar/profile-menu.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { Sitemap } from "sitemap";
1313
import { useLogout } from "hooks/supabase/use-logout";
1414
import { useGlobalState } from "hooks/use-global-state";
1515
import { useTheme } from "hooks/use-theme";
16+
import { isJanuaryOrDecember } from "utils/date-utils";
1617

1718
interface ProfileMenuProps {
1819
onAboutDialogClick: () => void;
@@ -24,7 +25,7 @@ const ProfileMenu: React.FC<ProfileMenuProps> = (props: ProfileMenuProps) => {
2425
const { onAboutDialogClick, onHelpDialogClick, onClose } = props;
2526
const { isAuthenticated, globalState, setGlobalState } = useGlobalState();
2627
const { colors } = useTheme();
27-
const handleLogoutsettled = useCallback(
28+
const handleLogoutSettled = useCallback(
2829
() =>
2930
setGlobalState((prev) =>
3031
prev.merge({
@@ -34,7 +35,7 @@ const ProfileMenu: React.FC<ProfileMenuProps> = (props: ProfileMenuProps) => {
3435
),
3536
[setGlobalState]
3637
);
37-
const { mutate: logout } = useLogout({ onSettled: handleLogoutsettled });
38+
const { mutate: logout } = useLogout({ onSettled: handleLogoutSettled });
3839
const { navigate } = useRouter();
3940

4041
const handleAboutDialogClick = useCallback(() => {
@@ -78,11 +79,14 @@ const ProfileMenu: React.FC<ProfileMenuProps> = (props: ProfileMenuProps) => {
7879

7980
return (
8081
<Menu>
81-
<Menu.Item
82-
icon={<SnowflakeIcon color={snowflakeIconColor} />}
83-
onSelect={handleToggleHolidayMode}>
84-
Holiday Mode
85-
</Menu.Item>
82+
{isJanuaryOrDecember() && (
83+
<Menu.Item
84+
icon={<SnowflakeIcon color={snowflakeIconColor} />}
85+
onSelect={handleToggleHolidayMode}>
86+
Holiday Mode
87+
</Menu.Item>
88+
)}
89+
8690
<Menu.Item icon={InfoSignIcon} onSelect={handleAboutDialogClick}>
8791
About
8892
</Menu.Item>

src/utils/date-utils.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
1-
import { DateTime } from "luxon";
21
import { isNilOrEmpty } from "utils/collection-utils";
3-
4-
const getCurrentTime = () => new Date().toISOString();
2+
import format from "date-fns/format";
3+
import parseISO from "date-fns/parseISO";
4+
import getMonth from "date-fns/getMonth";
55

66
const formatUpdatedOn = (updated_on?: string): string =>
77
isNilOrEmpty(updated_on)
88
? "--"
9-
: DateTime.fromISO(updated_on!).toLocaleString(
10-
DateTime.DATETIME_MED_WITH_WEEKDAY
11-
);
9+
: format(parseISO(updated_on), "E, d LLL u, p");
10+
11+
const getCurrentTime = () => new Date().toISOString();
12+
13+
const isJanuaryOrDecember = (): boolean => {
14+
const currentMonth = getMonth(new Date());
15+
16+
// Months in the Date constructor are index-based
17+
const december = getMonth(new Date(2023, 11, 1));
18+
const january = getMonth(new Date(2023, 0, 1));
19+
20+
return currentMonth === december || currentMonth === january;
21+
};
1222

13-
export { getCurrentTime, formatUpdatedOn };
23+
export { formatUpdatedOn, getCurrentTime, isJanuaryOrDecember };

0 commit comments

Comments
 (0)