Replace moment with date-fns
This commit is contained in:
8 files changed
+70
-25
No files matched your search
@@ -30,6 +30,46 @@ const event = {
|
||||
},
|
||||
};
|
||||
|
||||
it('formats the next occurrence as a Norwegian date with the venue', async () => {
|
||||
mockFetch.mockResolvedValue({ json: async () => ({ events: [event] }) });
|
||||
|
||||
const { findByText } = renderWithProviders(<EventList />);
|
||||
|
||||
expect(await findByText('lø. 1. aug. 2026 kl. 19:00 i Storsalen')).toBeTruthy();
|
||||
});
|
||||
|
||||
it('formats weekday and month abbreviations across the year', async () => {
|
||||
const events = [
|
||||
{ ...event, id: '2', nextOccurrence: { ...event.nextOccurrence, start: '2026-12-30T18:00:00+01:00' } },
|
||||
{ ...event, id: '3', nextOccurrence: { ...event.nextOccurrence, start: '2027-05-17T13:00:00+02:00' } },
|
||||
];
|
||||
mockFetch.mockResolvedValue({ json: async () => ({ events }) });
|
||||
|
||||
const { findByText } = renderWithProviders(<EventList />);
|
||||
|
||||
expect(await findByText('on. 30. des. 2026 kl. 18:00 i Storsalen')).toBeTruthy();
|
||||
expect(await findByText('ma. 17. mai 2027 kl. 13:00 i Storsalen')).toBeTruthy();
|
||||
});
|
||||
|
||||
it('renders venue-local (Oslo) time whatever the API offset and device timezone', async () => {
|
||||
// 17:00 UTC = 19:00 in Oslo (CEST); the suite runs under TZ=America/New_York
|
||||
const events = [{ ...event, nextOccurrence: { ...event.nextOccurrence, start: '2026-08-01T17:00:00Z' } }];
|
||||
mockFetch.mockResolvedValue({ json: async () => ({ events }) });
|
||||
|
||||
const { findByText } = renderWithProviders(<EventList />);
|
||||
|
||||
expect(await findByText('lø. 1. aug. 2026 kl. 19:00 i Storsalen')).toBeTruthy();
|
||||
});
|
||||
|
||||
it('prefixes the time with Neste: when the event has more occurrences', async () => {
|
||||
mockFetch.mockResolvedValue({ json: async () => ({ events: [{ ...event, futureOccurrencesCount: 3 }] }) });
|
||||
|
||||
const { findByText } = renderWithProviders(<EventList />);
|
||||
|
||||
expect(await findByText('Neste: lø. 1. aug. 2026 kl. 19:00 i Storsalen')).toBeTruthy();
|
||||
expect(await findByText('Se flere tider (2)')).toBeTruthy();
|
||||
});
|
||||
|
||||
it('renders events from the API', async () => {
|
||||
mockFetch.mockResolvedValue({ json: async () => ({ events: [event] }) });
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { TZDate } from '@date-fns/tz';
|
||||
import { SimpleLineIcons as Icon } from '@expo/vector-icons';
|
||||
import moment from 'moment';
|
||||
import { format, parseISO } from 'date-fns';
|
||||
import { nb } from 'date-fns/locale';
|
||||
import React from 'react';
|
||||
import { StyleSheet, View, Platform, FlatList, TouchableOpacity, Text, Linking } from 'react-native';
|
||||
import 'moment/locale/nb';
|
||||
|
||||
import Button from '@/components/Button';
|
||||
import theme from '@/theme';
|
||||
@@ -10,10 +11,10 @@ import { EventType } from '@/types/data';
|
||||
|
||||
import useEventList from './useEventList';
|
||||
|
||||
moment.locale('nb');
|
||||
|
||||
// Venue-local (Europe/Oslo) wall-clock time regardless of device timezone,
|
||||
// e.g. "lø. 1. aug. 2026 kl. 19:00"
|
||||
const formatTime = (time: string) => {
|
||||
return moment(time).format('llll');
|
||||
return format(new TZDate(parseISO(time), 'Europe/Oslo'), "EEEEEE. d. MMM y 'kl.' HH:mm", { locale: nb });
|
||||
};
|
||||
|
||||
const Header = () => <View style={styles.listHeader} />;
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
import moment from 'moment';
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
import 'moment/locale/nb';
|
||||
import type { EventType } from '@/types/data';
|
||||
import { fetchWithTimeout } from '@/utils';
|
||||
|
||||
moment.locale('nb');
|
||||
|
||||
/* Ref: https://medium.com/react-native-development/how-to-use-the-flatlist-component-react-native-basics-92c482816fe6 */
|
||||
const useEventList = () => {
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
Reference in new issue
Block a user