Skip to content

Commit

Permalink
Fjerne spredd logikk
Browse files Browse the repository at this point in the history
  • Loading branch information
frodehansen2 committed Jan 18, 2024
1 parent 8ffd6f2 commit 849f467
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 31 deletions.
4 changes: 2 additions & 2 deletions apps/endringsmelding-pleiepenger/src/app/hooks/useSakInfo.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useSøknadContext } from '@hooks';
import { formatName } from '@navikt/sif-common-core-ds/src/utils/personUtils';
import { getDateRangeText, getValidLocale } from '@navikt/sif-common-utils';
import { getDateRangeText } from '@navikt/sif-common-utils';
import { useIntl } from 'react-intl';

export const useSakUtledet = () => {
Expand All @@ -16,7 +16,7 @@ export const useSakUtledet = () => {
søkersNavn,
søkersFornavn: søker.fornavn,
barnetsNavn,
samletSøknadsperiodeTekst: getDateRangeText(sak.samletSøknadsperiode, getValidLocale(locale), {
samletSøknadsperiodeTekst: getDateRangeText(sak.samletSøknadsperiode, locale, {
compact: false,
includeDayName: true,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useMediaQuery } from 'react-responsive';
import { AddCircle } from '@navikt/ds-icons';
import Block from '@navikt/sif-common-core-ds/src/atoms/block/Block';
import { usePrevious } from '@navikt/sif-common-hooks';
import { getDateRangeText, getValidLocale } from '@navikt/sif-common-utils';
import { getDateRangeText } from '@navikt/sif-common-utils';
import EditButton from '../../components/buttons/EditButton';
import { usePagination } from '../../hooks/usePagination';
import { useSelectableList } from '../../hooks/useSelectableList';
Expand Down Expand Up @@ -77,7 +77,7 @@ const ArbeidstidUker: React.FunctionComponent<Props> = ({
const title =
selectedItems.length > 1
? 'Endre valgte uker'
: `Endre uke ${ukenummer} (${getDateRangeText(uke.periode, getValidLocale(locale))})`;
: `Endre uke ${ukenummer} (${getDateRangeText(uke.periode, locale)})`;

return (
<EditButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';
import AriaText from '@navikt/sif-common-core-ds/src/atoms/aria-text/AriaText';
import Block from '@navikt/sif-common-core-ds/src/atoms/block/Block';
import { DurationText } from '@navikt/sif-common-ui';
import { dateFormatter, getDateRangeText, getValidLocale } from '@navikt/sif-common-utils';
import { dateFormatter, getDateRangeText } from '@navikt/sif-common-utils';
import dayjs from 'dayjs';
import { SelectableListType } from '../../../hooks/useSelectableList';
import { ArbeidstidUkerItem } from '../ArbeidstidUkerItem';
Expand Down Expand Up @@ -146,7 +146,7 @@ const ArbeidstidUkeTabell: React.FunctionComponent<Props> = ({
<div>
<div className="arbeidsukeTidsrom">
<span className="arbeidsukeTidsrom__tekst">
{getDateRangeText(uke.periode, getValidLocale(locale))}
{getDateRangeText(uke.periode, locale)}
{(uke.harFeriedager || uke.harFjernetFeriedager) && (
<Block margin="s">
<UkeTags
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getDateRangeText, getValidLocale } from '@navikt/sif-common-utils';
import { getDateRangeText } from '@navikt/sif-common-utils';
import { Arbeidsuke } from '@types';
import dayjs from 'dayjs';
import { erKortArbeidsuke, getDagerTekst, sorterArbeidsuker } from '../../utils/arbeidsukeUtils';
Expand Down Expand Up @@ -88,6 +88,6 @@ export const getUkerForEndring = (arbeidsuker: Arbeidsuke[]): UkerForEndringType

export const getArbeidstidSpørsmålDescription = ({ periode }: Arbeidsuke, locale: string): string => {
return erKortArbeidsuke(periode)
? getDateRangeText(periode, getValidLocale(locale), { compact: false })
? getDateRangeText(periode, locale, { compact: false })
: getDagerTekst(periode, true);
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Heading } from '@navikt/ds-react';
import React from 'react';
import Block from '@navikt/sif-common-core-ds/src/atoms/block/Block';
import InfoList from '@navikt/sif-common-core-ds/src/components/lists/info-list/InfoList';
import { dateRangeToISODateRange, getDateRangeText, getValidLocale } from '@navikt/sif-common-utils';
import { dateRangeToISODateRange, getDateRangeText } from '@navikt/sif-common-utils';
import { LovbestemtFerieApiData } from '@types';
import { getLovbestemtFerieOppsummeringInfo } from '@utils';
import { useIntl } from 'react-intl';
Expand All @@ -25,7 +25,7 @@ const LovbestemtFerieOppsummering: React.FunctionComponent<Props> = ({ lovbestem
{perioderLagtTil.map((periode) => (
<li key={dateRangeToISODateRange(periode)}>
<div className="capsFirstChar">
{getDateRangeText(periode, getValidLocale(locale), {
{getDateRangeText(periode, locale, {
compact: true,
includeDayName: true,
})}
Expand All @@ -44,7 +44,7 @@ const LovbestemtFerieOppsummering: React.FunctionComponent<Props> = ({ lovbestem
{perioderFjernet.map((periode) => (
<li key={dateRangeToISODateRange(periode)}>
<div className="capsFirstChar">
{getDateRangeText(periode, getValidLocale(locale), {
{getDateRangeText(periode, locale, {
compact: true,
includeDayName: true,
})}
Expand Down
30 changes: 14 additions & 16 deletions packages/sif-common-utils/src/dateFormatter.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import dayjs from 'dayjs';
import 'dayjs/locale/nb';
import 'dayjs/locale/nn';
import { ValidLocale } from './localeUtils';
import { getValidLocale } from '.';

dayjs.locale('nb');

const compactFormat = 'DD.MM.YYYY';

const getLocale = (locale?: ValidLocale) => locale || 'nb';

/** Brukt i eldre apper */
export const prettifyDate = (date: Date, locale?: ValidLocale): string => {
export const prettifyDate = (date: Date, locale?: string): string => {
return dateFormatter.compact(date, locale);
};

/** Brukt i eldre apper */
export const prettifyDateExtended = (date: Date, locale?: ValidLocale): string => {
export const prettifyDateExtended = (date: Date, locale?: string): string => {
return dateFormatter.dateShortMonthYear(date, locale);
};

Expand All @@ -25,66 +23,66 @@ export const dateFormatter = {
* @param date: Date
* @returns 01.01.2020
*/
compact: (date: Date, locale?: ValidLocale) => dayjs(date).locale(getLocale(locale)).format(compactFormat),
compact: (date: Date, locale?: string) => dayjs(date).locale(getValidLocale(locale)).format(compactFormat),

/**
*
* @param date: Date
* @returns 1. jan. 2021
*/
dateShortMonthYear: (date: Date, locale?: ValidLocale) =>
dayjs(date).locale(getLocale(locale)).format('D. MMM YYYY'),
dateShortMonthYear: (date: Date, locale?: string) =>
dayjs(date).locale(getValidLocale(locale)).format('D. MMM YYYY'),

/**
*
* @param date: Date
* @returns 1. januar 2021
*/
full: (date: Date, locale?: ValidLocale) => dayjs(date).locale(getLocale(locale)).format('D. MMMM YYYY'),
full: (date: Date, locale?: string) => dayjs(date).locale(getValidLocale(locale)).format('D. MMMM YYYY'),

/**
*
* @param date: Date
* @returns fredag
*/
day: (date: Date, locale?: ValidLocale) => `${dayjs(date).locale(getLocale(locale)).format('dddd')}`,
day: (date: Date, locale?: string) => `${dayjs(date).locale(getValidLocale(locale)).format('dddd')}`,

/**
*
* @param date: Date
* @returns fredag 01.01.2021
*/
dayCompactDate: (date: Date, locale?: ValidLocale) =>
dayCompactDate: (date: Date, locale?: string) =>
`${dateFormatter.day(date, locale)} ${dateFormatter.compact(date, locale)}`,

/**
*
* @param date: Date
* @returns fredag 1. jan. 2021
*/
dayDateShortMonthYear: (date: Date, locale?: ValidLocale) =>
dayDateShortMonthYear: (date: Date, locale?: string) =>
`${dateFormatter.day(date)} ${dateFormatter.dateShortMonthYear(date, locale)}`,

/**
*
* @param date: Date
* @returnsfredag 1. januar 2021
*/
dayDateMonthYear: (date: Date, locale?: ValidLocale) =>
dayDateMonthYear: (date: Date, locale?: string) =>
`${dateFormatter.day(date, locale)} ${dateFormatter.full(date, locale)}`,

/**
*
* @param date: Date
* @returns fredag 1. jan.
*/
dayDateMonth: (date: Date, locale?: ValidLocale) => dayjs(date).locale(getLocale(locale)).format('dddd D. MMMM'),
dayDateMonth: (date: Date, locale?: string) => dayjs(date).locale(getValidLocale(locale)).format('dddd D. MMMM'),

/**
*
* @param date: Date
* @returns fredag 1. januar
*/
dayDateShortMonth: (date: Date, locale?: ValidLocale) =>
dayjs(date).locale(getLocale(locale)).format('dddd D. MMM'),
dayDateShortMonth: (date: Date, locale?: string) =>
dayjs(date).locale(getValidLocale(locale)).format('dddd D. MMM'),
};
6 changes: 3 additions & 3 deletions packages/sif-common-utils/src/dateRangeFormatter.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import dayjs from 'dayjs';
import 'dayjs/locale/nb';
import 'dayjs/locale/nn';
import { ValidLocale } from './';

import { dateFormatter } from './dateFormatter';
import { DateRange } from './types';

const getDateText = (date: Date, locale: ValidLocale, compact = true, inkluderDagNavn?: boolean): string => {
const getDateText = (date: Date, locale: string, compact = true, inkluderDagNavn?: boolean): string => {
const tekst = compact ? dateFormatter.compact(date, locale) : dateFormatter.full(date, locale);
return inkluderDagNavn ? `${dateFormatter.day(date, locale)} ${tekst}` : tekst;
};
Expand All @@ -17,7 +17,7 @@ type Options = {

export const getDateRangeText = (
{ from, to }: DateRange,
locale: ValidLocale,
locale: string,
options: Options = { compact: true, includeDayName: false },
): string => {
const { includeDayName, compact } = options;
Expand Down
2 changes: 1 addition & 1 deletion packages/sif-common-utils/src/localeUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export type ValidLocale = 'nb' | 'nn';

export const getValidLocale = (locale: string): ValidLocale => {
export const getValidLocale = (locale?: string): ValidLocale => {
return locale === 'nn' ? 'nn' : 'nb';
};

0 comments on commit 849f467

Please sign in to comment.