Skip to content

Commit

Permalink
fix(planex): incorrect times displayed when inspecting a class
Browse files Browse the repository at this point in the history
  • Loading branch information
ignyx committed Oct 14, 2024
1 parent 2ffd94b commit 87e8032
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
24 changes: 24 additions & 0 deletions __tests__/utils/PlanningEventManager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,30 @@ test('dateToDateTimeString', () => {
expect(Planning.dateToDateTimeString(testDate)).toBe('2022-12-31 09:10');
});

test('dateToTimeString', () => {
expect(Planning.dateToTimeString(new Date('2020-01-14T09:15:00.000'))).toBe(
'09:15'
);
expect(Planning.dateToTimeString(new Date('2020-01-14T00:00:00.000'))).toBe(
'00:00'
);
expect(Planning.dateToTimeString(new Date('2020-01-14T23:59:59.999'))).toBe(
'23:59'
);
});

test('dateToTimeStringUTC', () => {
expect(
Planning.dateToTimeStringUTC(new Date('2020-01-14T09:15:00.000Z'))
).toBe('09:15');
expect(
Planning.dateToTimeStringUTC(new Date('2020-01-14T00:00:00.000Z'))
).toBe('00:00');
expect(
Planning.dateToTimeStringUTC(new Date('2020-01-14T23:59:59.999Z'))
).toBe('23:59');
});

test('generateEventAgenda empty agenda', () => {
const eventList = [];

Expand Down
6 changes: 3 additions & 3 deletions src/screens/Planex/PlanexScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { StyleSheet, View } from 'react-native';
import { useNavigation } from '@react-navigation/native';
import Autolink from 'react-native-autolink';
import AlertDialog from '../../components/Dialogs/AlertDialog';
import { dateToTimeString } from '../../utils/Planning';
import { dateToTimeStringUTC } from '../../utils/Planning';
import DateManager from '../../managers/DateManager';
import type { PlanexGroupType } from './GroupSelectionScreen';
import { MASCOT_STYLE } from '../../components/Mascot/Mascot';
Expand Down Expand Up @@ -148,8 +148,8 @@ function PlanexScreen() {
} = JSON.parse(event.nativeEvent.data);
console.log(data);
const start = new Date(data.start);
const startTime = dateToTimeString(start, true);
const endTime = dateToTimeString(new Date(data.end), true);
const startTime = dateToTimeStringUTC(start);
const endTime = dateToTimeStringUTC(new Date(data.end));

let msg = `${DateManager.getInstance().getTranslatedDateFromDate(
start
Expand Down
18 changes: 16 additions & 2 deletions src/utils/Planning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,20 @@ export function dateToTimeString(date: Date): string {
return `${hours}:${minutes}`;
}

/**
* Converts a date object to a string in the format
* HH-MM (UTC)
*
* @param date The date object to convert
* @return {string} The converted string
*/
export function dateToTimeStringUTC(date: Date): string {
const h = date.getUTCHours();
const hours = String(h).padStart(2, '0');
const minutes = String(date.getUTCMinutes()).padStart(2, '0');
return `${hours}:${minutes}`;
}

/**
* Generates an object with an array of eventObject at each key.
* Each key is a date string in the format
Expand Down Expand Up @@ -180,9 +194,9 @@ export function getSubtitle(

let subtitle = '';
if (includeStartDay) subtitle = dateToDateStringHuman(start) + ' ';
subtitle += dateToTimeString(start, true) + '-';
subtitle += dateToTimeString(start) + '-';
if (over12hLong) subtitle += dateToDateStringHuman(end) + ' ';
subtitle += dateToTimeString(end, true);
subtitle += dateToTimeString(end);
if (event.location) subtitle += ' @ ' + event.location.trim();
return subtitle;
}

0 comments on commit 87e8032

Please sign in to comment.