Skip to content

Commit b737f1b

Browse files
authored
Merge pull request #461 from Aspireve/feature/american-dates
[FEAT] change dates to the American people #156
2 parents ce36b87 + e66557c commit b737f1b

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

apps/frontend/src/components/launches/calendar.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,18 @@ import isSameOrBefore from 'dayjs/plugin/isSameOrBefore';
2727
import { groupBy, sortBy } from 'lodash';
2828
import Image from 'next/image';
2929
import { extend } from 'dayjs';
30+
import { isUSCitizen } from './helpers/isuscitizen.utils';
3031
extend(isSameOrAfter);
3132
extend(isSameOrBefore);
3233

34+
const convertTimeFormatBasedOnLocality = (time: number) => {
35+
if (isUSCitizen()) {
36+
return `${time === 12 ? 12 : time%12}:00 ${time >= 12 ? "PM" : "AM"}`
37+
} else {
38+
return `${time}:00`
39+
}
40+
}
41+
3342
export const days = [
3443
'Monday',
3544
'Tuesday',
@@ -91,7 +100,7 @@ export const DayView = () => {
91100
.startOf('day')
92101
.add(option[0].time, 'minute')
93102
.local()
94-
.format('HH:mm')}
103+
.format(isUSCitizen() ? "hh:mm A": "HH:mm")}
95104
</div>
96105
<div
97106
key={option[0].time}
@@ -140,7 +149,8 @@ export const WeekView = () => {
140149
{hours.map((hour) => (
141150
<Fragment key={hour}>
142151
<div className="p-2 pr-4 bg-secondary text-center items-center justify-center flex">
143-
{hour.toString().padStart(2, '0')}:00
152+
{/* {hour.toString().padStart(2, '0')}:00 */}
153+
{convertTimeFormatBasedOnLocality(hour)}
144154
</div>
145155
{days.map((day, indexDay) => (
146156
<Fragment key={`${day}-${hour}`}>

apps/frontend/src/components/launches/filters.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useCalendar } from '@gitroom/frontend/components/launches/calendar.cont
33
import clsx from 'clsx';
44
import dayjs from 'dayjs';
55
import { useCallback } from 'react';
6+
import { isUSCitizen } from './helpers/isuscitizen.utils';
67

78
export const Filters = () => {
89
const week = useCalendar();
@@ -12,30 +13,30 @@ export const Filters = () => {
1213
.year(week.currentYear)
1314
.isoWeek(week.currentWeek)
1415
.day(week.currentDay)
15-
.format('DD/MM/YYYY')
16+
.format(isUSCitizen() ? 'MM/DD/YYYY' :'DD/MM/YYYY')
1617
: week.display === 'week'
1718
? dayjs()
1819
.year(week.currentYear)
1920
.isoWeek(week.currentWeek)
2021
.startOf('isoWeek')
21-
.format('DD/MM/YYYY') +
22+
.format(isUSCitizen() ? 'MM/DD/YYYY' :'DD/MM/YYYY') +
2223
' - ' +
2324
dayjs()
2425
.year(week.currentYear)
2526
.isoWeek(week.currentWeek)
2627
.endOf('isoWeek')
27-
.format('DD/MM/YYYY')
28+
.format(isUSCitizen() ? 'MM/DD/YYYY' :'DD/MM/YYYY')
2829
: dayjs()
2930
.year(week.currentYear)
3031
.month(week.currentMonth)
3132
.startOf('month')
32-
.format('DD/MM/YYYY') +
33+
.format(isUSCitizen() ? 'MM/DD/YYYY' :'DD/MM/YYYY') +
3334
' - ' +
3435
dayjs()
3536
.year(week.currentYear)
3637
.month(week.currentMonth)
3738
.endOf('month')
38-
.format('DD/MM/YYYY');
39+
.format(isUSCitizen() ? 'MM/DD/YYYY' :'DD/MM/YYYY');
3940

4041
const setDay = useCallback(() => {
4142
week.setFilters({

apps/frontend/src/components/launches/helpers/date.picker.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import dayjs from 'dayjs';
33
import { Calendar, TimeInput } from '@mantine/dates';
44
import { useClickOutside } from '@mantine/hooks';
55
import { Button } from '@gitroom/react/form/button';
6+
import { isUSCitizen } from './isuscitizen.utils';
67

78
export const DatePicker: FC<{
89
date: dayjs.Dayjs;
@@ -39,7 +40,7 @@ export const DatePicker: FC<{
3940
onClick={changeShow}
4041
ref={ref}
4142
>
42-
<div className="cursor-pointer">{date.format('DD/MM/YYYY HH:mm')}</div>
43+
<div className="cursor-pointer">{date.format(isUSCitizen() ? 'MM/DD/YYYY hh:mm A' : 'DD/MM/YYYY HH:mm')}</div>
4344
<div className="cursor-pointer">
4445
<svg
4546
xmlns="http://www.w3.org/2000/svg"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
export const isUSCitizen = () => {
3+
const userLanguage = navigator.language || navigator.languages[0];
4+
return userLanguage.startsWith('en-US')
5+
}

0 commit comments

Comments
 (0)