Skip to content

Commit

Permalink
fix: GEO-1197 fix incorrect UTC dates (#882)
Browse files Browse the repository at this point in the history
  • Loading branch information
banders authored Dec 12, 2024
1 parent ab39e1c commit 4d77b47
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
11 changes: 11 additions & 0 deletions backend/src/v1/services/announcements-service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,7 @@ describe('AnnouncementsService', () => {
linkDisplayName: faker.lorem.words(3),
linkUrl: faker.internet.url(),
};
const now = new Date();
await announcementService.updateAnnouncement(
'announcement-id',
announcementInput,
Expand Down Expand Up @@ -738,6 +739,16 @@ describe('AnnouncementsService', () => {
}),
}),
);

//Ensure the update date saved to the database is approximately now
//(within 5 seconds of now)
const updateObj = mockUpdate.mock.calls[0][0];
const updatedDate = updateObj.data.updated_date;
const expectedUpdateDate = now;
const updateDateDiffMs =
updatedDate.getTime() - expectedUpdateDate.getTime();
expect(updateDateDiffMs).toBeGreaterThanOrEqual(0);
expect(updateDateDiffMs).toBeLessThan(5000);
});
});
describe('with existing attachment resource', () => {
Expand Down
5 changes: 2 additions & 3 deletions backend/src/v1/services/announcements-service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
convert,
DateTimeFormatter,
LocalDateTime,
ZonedDateTime,
ZoneId,
} from '@js-joda/core';
Expand All @@ -15,6 +14,7 @@ import {
import { DefaultArgs } from '@prisma/client/runtime/library';
import isEmpty from 'lodash/isEmpty';
import { config } from '../../config';
import { deleteFiles } from '../../external/services/s3-api';
import { logger } from '../../logger';
import prisma from '../prisma/prisma-client';
import { PaginatedResult } from '../types';
Expand All @@ -26,7 +26,6 @@ import {
} from '../types/announcements';
import { UserInputError } from '../types/errors';
import { utils } from './utils-service';
import { deleteFiles } from '../../external/services/s3-api';

const saveHistory = async (
tx: Omit<
Expand Down Expand Up @@ -321,7 +320,7 @@ export const announcementService = {
input: AnnouncementDataType,
currentUserId: string,
) {
const updateDate = convert(LocalDateTime.now(ZoneId.UTC)).toDate();
const updateDate = convert(ZonedDateTime.now(ZoneId.UTC)).toDate();
await prisma.$transaction(async (tx) => {
const announcementData = await tx.announcement.findUniqueOrThrow({
where: {
Expand Down

0 comments on commit 4d77b47

Please sign in to comment.