Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: GEO-1197 fix incorrect UTC dates #882

Merged
merged 3 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading