Skip to content

Commit

Permalink
refactor: extract parser formats in constants
Browse files Browse the repository at this point in the history
  • Loading branch information
Devessier committed Dec 11, 2024
1 parent e00e692 commit 1ce4d95
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const DATE_PARSER_FORMAT = 'MM/dd/yyyy';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const DATE_TIME_PARSER_FORMAT = 'MM/dd/yyyy HH:mm';
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { DATE_PARSER_FORMAT } from '@/ui/input/components/internal/date/constants/DateParserFormat';
import { DATE_TIME_PARSER_FORMAT } from '@/ui/input/components/internal/date/constants/DateTimeParserFormat';
import { DateTime } from 'luxon';

type ParseDateToStringArgs = {
Expand All @@ -11,7 +13,9 @@ export const parseDateToString = ({
isDateTimeInput,
userTimezone,
}: ParseDateToStringArgs) => {
const parsingFormat = isDateTimeInput ? 'MM/dd/yyyy HH:mm' : 'MM/dd/yyyy';
const parsingFormat = isDateTimeInput
? DATE_TIME_PARSER_FORMAT
: DATE_PARSER_FORMAT;

const dateParsed = DateTime.fromJSDate(date, { zone: userTimezone });

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { DATE_PARSER_FORMAT } from '@/ui/input/components/internal/date/constants/DateParserFormat';
import { DATE_TIME_PARSER_FORMAT } from '@/ui/input/components/internal/date/constants/DateTimeParserFormat';
import { DateTime } from 'luxon';

type ParseStringToDateArgs = {
Expand All @@ -11,7 +13,9 @@ export const parseStringToDate = ({
isDateTimeInput,
userTimezone,
}: ParseStringToDateArgs) => {
const parsingFormat = isDateTimeInput ? 'MM/dd/yyyy HH:mm' : 'MM/dd/yyyy';
const parsingFormat = isDateTimeInput
? DATE_TIME_PARSER_FORMAT
: DATE_PARSER_FORMAT;

const parsedDate = isDateTimeInput
? DateTime.fromFormat(dateAsString, parsingFormat, { zone: userTimezone })
Expand Down

0 comments on commit 1ce4d95

Please sign in to comment.