Skip to content

Commit

Permalink
Tolerate both . and : as time separator
Browse files Browse the repository at this point in the history
  • Loading branch information
tu55eladd committed May 10, 2024
1 parent ff42e6a commit 0de72ab
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const MoteAktivitetForm = (props: Props) => {

const defaultValues: Partial<MoteAktivitetFormValues> = {
tittel: aktivitet?.tittel,
klokkeslett: moteTid?.klokkeslett,
klokkeslett: moteTid?.klokkeslett?.replace('.', ':'),
// Keep field as string since input natively returns string
varighet: moteTid?.varighet,
kanal: aktivitet?.kanal,
Expand Down
9 changes: 6 additions & 3 deletions src/moduler/aktivitet/aktivitet-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ interface Klokkeslett {
minute: number;
}
const validKlokkeslett = (val: string): boolean => {
const hourMinute = val.split(':');
const hourMinute = val.replace('.', ':').split(':');
if (hourMinute.length != 2) return false;
const [hour, minute] = hourMinute;
const hourInt = parseInt(hour);
Expand All @@ -143,7 +143,10 @@ const validKlokkeslett = (val: string): boolean => {
};
const toHourAndMinutes = (klokkeslett: string | number): Klokkeslett => {
if (typeof klokkeslett !== 'number') {
const [hour, minute] = klokkeslett.split(':').map((it) => parseInt(it));
const [hour, minute] = klokkeslett
.replace('.', ':')
.split(':')
.map((it) => parseInt(it));
return {
hour,
minute,
Expand Down Expand Up @@ -195,7 +198,7 @@ const prefixMed0 = (val: string) => (val.length === 1 ? '0' + val : val);
export function formatterKlokkeslett(klokkeslett?: string): string | undefined {
if (!klokkeslett || !validKlokkeslett(klokkeslett)) return undefined;
const { hour, minute } = toHourAndMinutes(klokkeslett);
return `${prefixMed0(hour.toString())}:${prefixMed0(minute.toString())}`;
return `${prefixMed0(hour.toString())}.${prefixMed0(minute.toString())}`;
}

function moteManglerPubliseringAvSamtalereferat(type: AktivitetType, erReferatPublisert?: boolean): boolean {
Expand Down

0 comments on commit 0de72ab

Please sign in to comment.