Skip to content

Commit

Permalink
chore(goal): explicit cast to iso date format
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisVorop committed Jul 28, 2023
1 parent 34c5375 commit a9323be
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
3 changes: 0 additions & 3 deletions src/utils/dateTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,3 @@ export const formatEstimate = (estimate: { date: string; q?: string; y: string }

return date === createLocaleDate(endOfQuarter(q), { locale }) ? `${q}/${y}` : date;
};

export const convertDateByLocale = (date: string | Date, locale: TLocale) =>
createLocaleDate(parseLocaleDate(date, { locale }), { locale });
8 changes: 4 additions & 4 deletions trpc/router/goal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import {
updateCriteriaState,
} from '../../src/schema/criteria';
import type { FieldDiff } from '../../src/types/common';
import { convertDateByLocale, createLocaleDate } from '../../src/utils/dateTime';
import { parseLocaleDate } from '../../src/utils/dateTime';

import { addCalculatedProjectFields } from './project';

Expand Down Expand Up @@ -454,7 +454,7 @@ export const goal = router({
}),
update: protectedProcedure.input(goalUpdateSchema).mutation(async ({ ctx, input }) => {
if (input.estimate && input.estimate.date) {
input.estimate.date = convertDateByLocale(input.estimate.date, 'en');
input.estimate.date = parseLocaleDate(input.estimate.date, { locale: 'en' }).toISOString();
}

const actualGoal = await prisma.goal.findUnique({
Expand Down Expand Up @@ -562,10 +562,10 @@ export const goal = router({
// FIXME: https://github.com/taskany-inc/issues/issues/1359
updatedFields.estimate = [
previousEstimate?.estimate.date
? convertDateByLocale(previousEstimate?.estimate.date, 'en')
? parseLocaleDate(previousEstimate?.estimate.date, { locale: 'en' }).toISOString()
: [previousEstimate?.estimate.q, previousEstimate?.estimate.y].join('/'),
correctEstimate.date
? convertDateByLocale(correctEstimate.date, 'en')
? parseLocaleDate(correctEstimate.date, { locale: 'en' }).toISOString()
: [correctEstimate.q, correctEstimate.y].join('/'),
];
}
Expand Down

0 comments on commit a9323be

Please sign in to comment.