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(planex): incorrect times displayed when inspecting a class #115

Merged
merged 1 commit into from
Oct 14, 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
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;
}
Loading