Skip to content

Commit

Permalink
Merge branch 'date-utils-fix' into pw-psb-test
Browse files Browse the repository at this point in the history
  • Loading branch information
frodehansen2 committed May 24, 2024
2 parents 7e61e51 + 25c5672 commit 78cb3b7
Show file tree
Hide file tree
Showing 48 changed files with 212 additions and 183 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ test('test', async ({ page }) => {
.filter({ hasText: /^Fra og medÅpne datovelger$/ })
.getByRole('button')
.click();
await page.getByRole('button', { name: 'mandag 4' }).click();
await page.getByRole('button', { name: 'mandag 7' }).click();
await page
.locator('div')
.filter({ hasText: /^Til og medÅpne datovelger$/ })
.getByRole('button')
.click();
await page.getByRole('button', { name: 'søndag 10' }).click();
await page.getByRole('button', { name: 'søndag 13' }).click();
await page.getByRole('button', { name: 'Ok' }).click();
await page.getByTestId('dateRangeAccordion_0_header').click();
await page.getByLabel('Fjern ferie fredag 23.12.2022').click();
Expand Down Expand Up @@ -67,7 +67,7 @@ test('test', async ({ page }) => {

/** Oppsummering */
await expect(page.getByText('fredag 23.12.2022 - torsdag')).toBeVisible();
await expect(page.getByText('mandag 04.12.2023 - søndag')).toBeVisible();
await expect(page.getByText('mandag 07.08.2023 - søndag')).toBeVisible();
await expect(page.getByText('- 23.12.2022')).toBeVisible();
await page.getByText('Jeg bekrefter at').click();
await page.getByTestId('arbeidstid-faktisk').click();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Accordion, Ingress } from '@navikt/ds-react';
import React from 'react';
import { DateRange, dateRangeToISODateRange, dateToday, isDateInDateRange } from '@navikt/sif-common-utils';
import { DateRange, dateRangeToISODateRange, getDateToday, isDateInDateRange } from '@navikt/sif-common-utils';

type State = 'all' | 'none' | 'current';

Expand All @@ -18,7 +18,7 @@ const erÅpen = (periode: DateRange, defaultOpenState: State = 'none') => {
case 'none':
return false;
case 'current':
return isDateInDateRange(dateToday, periode);
return isDateInDateRange(getDateToday(), periode);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { getListValidator, getYesOrNoValidator } from '@navikt/sif-common-formik
import getIntlFormErrorHandler from '@navikt/sif-common-formik-ds/src/validation/intlFormErrorHandler';
import { AnnetBarn } from '@navikt/sif-common-forms-ds/src/forms/annet-barn';
import AnnetBarnListAndDialog from '@navikt/sif-common-forms-ds/src/forms/annet-barn/AnnetBarnListAndDialog';
import { dateToday } from '@navikt/sif-common-utils';
import { getDateToday } from '@navikt/sif-common-utils';
import PersistStepFormValues from '../../../components/persist-step-form-values/PersistStepFormValues';
import { useOnValidSubmit } from '../../../hooks/useOnValidSubmit';
import { useStepNavigation } from '../../../hooks/useStepNavigation';
Expand Down Expand Up @@ -182,7 +182,7 @@ const OmOmsorgenForBarnStep = () => {
'steg.omOmsorgenForBarn.annetBarnListAndDialog.modalTitle',
),
}}
maxDate={dateToday}
maxDate={getDateToday()}
minDate={nYearsAgo(19)}
disallowedFødselsnumre={[...[søker.fødselsnummer], ...annetBarnFnr]}
aldersGrenseText={text(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Block from '@navikt/sif-common-core-ds/src/atoms/block/Block';
import { getTypedFormComponents, ValidationError } from '@navikt/sif-common-formik-ds';
import { getDateValidator, getRequiredFieldValidator } from '@navikt/sif-common-formik-ds/src/validation';
import { dateToday } from '@navikt/sif-common-utils';
import { getDateToday } from '@navikt/sif-common-utils';
import { AppIntlShape, useAppIntl } from '../../../i18n';
import {
AleneomsorgTidspunktField,
Expand Down Expand Up @@ -86,12 +86,12 @@ const TidspunktForBarn = ({ barnMedAleneomsorg, aleneomsorgTidspunkt }: Props) =
})}
dropdownCaption={true}
minDate={getMinDateYearAgo()}
maxDate={dateToday}
maxDate={getDateToday()}
validate={(value) => {
const error = getDateValidator({
required: true,
min: getMinDateYearAgo(),
max: dateToday,
max: getDateToday(),
})(value);
return error
? {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { dateToday } from '@navikt/sif-common-utils';
import { getDateToday } from '@navikt/sif-common-utils';
import dayjs from 'dayjs';

export const aldersBegrensingOver = (fødselsdato: Date, maxGrenseYears: number): boolean => {
return dayjs().diff(fødselsdato, 'year') <= maxGrenseYears;
};

export const nYearsAgo = (years: number): Date => {
return dayjs(dateToday).subtract(years, 'y').startOf('year').toDate();
return dayjs(getDateToday()).subtract(years, 'y').startOf('year').toDate();
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getNMonthsAgo } from '../../søknad/steps/situasjon/SituasjonStepUtils';
import { Arbeidsgiver } from '../../types/Arbeidsgiver';
import api, { ApiEndpoint } from '../api';
import { dateToISODate, dateToday } from '@navikt/sif-common-utils/src/dateUtils';
import { dateToISODate, getDateToday } from '@navikt/sif-common-utils/src/dateUtils';

type AAregArbeidsgiver = {
organisasjoner?: {
Expand All @@ -13,7 +13,7 @@ type AAregArbeidsgiver = {
const arbeidsgivereEndpoint = {
fetch: async (): Promise<Arbeidsgiver[]> => {
const threeMonthsAgo = getNMonthsAgo(3);
const today: Date = dateToday;
const today: Date = getDateToday();
try {
const { data } = await api.get<AAregArbeidsgiver>(
ApiEndpoint.arbeidsgiver,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { getListValidator, getYesOrNoValidator } from '@navikt/sif-common-formik
import getIntlFormErrorHandler from '@navikt/sif-common-formik-ds/src/validation/intlFormErrorHandler';
import BostedUtlandListAndDialog from '@navikt/sif-common-forms-ds/src/forms/bosted-utland/BostedUtlandListAndDialog';
import { Utenlandsopphold } from '@navikt/sif-common-forms-ds/src/forms/utenlandsopphold/types';
import { date1YearAgo, dateToday } from '@navikt/sif-common-utils';
import { getDate1YearAgo, getDateToday } from '@navikt/sif-common-utils';
import FormSection from '../../../components/form-section/FormSection';
import PersistStepFormValues from '../../../components/persist-step-form-values/PersistStepFormValues';
import { useOnValidSubmit } from '../../../hooks/useOnValidSubmit';
Expand Down Expand Up @@ -145,8 +145,8 @@ const FraværStep: React.FC = () => {
const fraværDager = getAlleFraværDager(fravær);
const fraværPerioder = getAlleFraværPerioder(fravær);
const harRegistrertFravær = fraværDager.length + fraværPerioder.length > 0;
const minDateForFravær = harRegistrertFravær ? gyldigTidsrom.from : date1YearAgo;
const maxDateForFravær = harRegistrertFravær ? gyldigTidsrom.to : dateToday;
const minDateForFravær = harRegistrertFravær ? gyldigTidsrom.from : getDate1YearAgo();
const maxDateForFravær = harRegistrertFravær ? gyldigTidsrom.to : getDateToday();

return (
<>
Expand Down Expand Up @@ -228,8 +228,8 @@ const FraværStep: React.FC = () => {
<FormBlock margin="m">
<BostedUtlandListAndDialog<FraværStepFormFields>
name={FraværStepFormFields.perioderUtenlandsopphold}
minDate={date1YearAgo}
maxDate={dateToday}
minDate={getDate1YearAgo()}
maxDate={getDateToday()}
labels={{
addLabel: text('step.fravær.værtIUtlandet.leggTilLabel'),
modalTitle: text('step.fravær.værtIUtlandet.modalTittel'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import getIntlFormErrorHandler from '@navikt/sif-common-formik-ds/src/validation
import { ValidationError } from '@navikt/sif-common-formik-ds/src/validation/types';
import BostedUtlandListAndDialog from '@navikt/sif-common-forms-ds/src/forms/bosted-utland/BostedUtlandListAndDialog';
import { Utenlandsopphold } from '@navikt/sif-common-forms-ds/src/forms/utenlandsopphold/types';
import { dateToday } from '@navikt/sif-common-utils/src/dateUtils';
import PersistStepFormValues from '../../../components/persist-step-form-values/PersistStepFormValues';
import { useOnValidSubmit } from '../../../hooks/useOnValidSubmit';
import { useStepNavigation } from '../../../hooks/useStepNavigation';
Expand All @@ -30,6 +29,7 @@ import {
getMedlemskapStepInitialValues,
getMedlemskapSøknadsdataFromFormValues,
} from './medlemskapStepUtils';
import { getDateToday } from '@navikt/sif-common-utils';

export enum MedlemskapFormFields {
harBoddUtenforNorgeSiste12Mnd = 'harBoddUtenforNorgeSiste12Mnd',
Expand All @@ -53,7 +53,7 @@ const { FormikWrapper, Form, YesOrNoQuestion } = getTypedFormComponents<

const MedlemskapStep = () => {
const { text, intl } = useAppIntl();
const { neste12Måneder, siste12Måneder } = getMedlemskapDateRanges(dateToday);
const { neste12Måneder, siste12Måneder } = getMedlemskapDateRanges(getDateToday());
const {
state: { søknadsdata },
} = useSøknadContext();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Utenlandsopphold } from '@navikt/sif-common-forms-ds/src/forms/utenlandsopphold/types';
import { date1YearAgo, date1YearFromNow } from '@navikt/sif-common-utils';
import { getDate1YearAgo, getDate1YearFromNow } from '@navikt/sif-common-utils';
import { dateRangesCollide, dateRangesExceedsRange } from '@navikt/sif-common-utils/src/dateRangeUtils';
import dayjs from 'dayjs';

Expand All @@ -17,7 +17,7 @@ export const validateUtenlandsoppholdSiste12Mnd = (utenlandsopphold: Utenlandsop
if (dateRangesCollide(dateRanges)) {
return UtenlandsoppholdErrors.utenlandsopphold_overlapper;
}
if (dateRangesExceedsRange(dateRanges, { from: date1YearAgo, to: dayjs().subtract(1, 'day').toDate() })) {
if (dateRangesExceedsRange(dateRanges, { from: getDate1YearAgo(), to: dayjs().subtract(1, 'day').toDate() })) {
return UtenlandsoppholdErrors.utenlandsopphold_utenfor_periode;
}
return undefined;
Expand All @@ -31,7 +31,7 @@ export const validateUtenlandsoppholdNeste12Mnd = (utenlandsopphold: Utenlandsop
if (dateRangesCollide(dateRanges)) {
return UtenlandsoppholdErrors.utenlandsopphold_overlapper;
}
if (dateRangesExceedsRange(dateRanges, { from: new Date(), to: date1YearFromNow })) {
if (dateRangesExceedsRange(dateRanges, { from: new Date(), to: getDate1YearFromNow() })) {
return UtenlandsoppholdErrors.utenlandsopphold_utenfor_periode;
}
return undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Block from '@navikt/sif-common-core-ds/src/atoms/block/Block';
import { SummarySection } from '@navikt/sif-common-ui';
import { SummaryList } from '@navikt/sif-common-ui';
import { JaNeiSvar, SummaryBlock } from '@navikt/sif-common-ui';
import { dateToday, ISODateToDate } from '@navikt/sif-common-utils/src';
import { ISODateToDate, getDateToday } from '@navikt/sif-common-utils/src';
import dayjs from 'dayjs';
import isSameOrAfter from 'dayjs/plugin/isSameOrAfter';
import isSameOrBefore from 'dayjs/plugin/isSameOrBefore';
Expand All @@ -21,8 +21,8 @@ export interface Props {
const MedlemskapOppsummering: React.FC<Props> = ({ bosteder }) => {
const { text } = useAppIntl();

const bostederSiste12 = bosteder.filter((b) => dayjs(ISODateToDate(b.tilOgMed)).isSameOrBefore(dateToday));
const bostederNeste12 = bosteder.filter((b) => dayjs(ISODateToDate(b.tilOgMed)).isSameOrAfter(dateToday));
const bostederSiste12 = bosteder.filter((b) => dayjs(ISODateToDate(b.tilOgMed)).isSameOrBefore(getDateToday()));
const bostederNeste12 = bosteder.filter((b) => dayjs(ISODateToDate(b.tilOgMed)).isSameOrAfter(getDateToday()));

return (
<SummarySection header={text('step.oppsummering.medlemskap.header')}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { DateRange } from '@navikt/sif-common-formik-ds/src';
import { FraværDag, FraværPeriode } from '@navikt/sif-common-forms-ds/src/forms/fravær/types';
import { date1YearAgo, dateToday } from '@navikt/sif-common-utils/src';
import dayjs from 'dayjs';
import MinMax from 'dayjs/plugin/minMax';
import { FraværMap } from '../types/FraværTypes';
import { FraværSøknadsdataMap } from '../types/søknadsdata/FraværSøknadsdata';
import { getDate1YearAgo, getDateToday } from '@navikt/sif-common-utils';

dayjs.extend(MinMax);

Expand All @@ -26,12 +26,12 @@ export const getÅrstallFromFravær = (
};
export const getTidsromFromÅrstall = (årstall?: number): DateRange => {
if (årstall === undefined) {
return { from: date1YearAgo, to: dayjs().endOf('day').toDate() };
return { from: getDate1YearAgo(), to: dayjs().endOf('day').toDate() };
}
const førsteDagIÅret = dayjs(`${årstall}-01-01`).toDate();
const sisteDagIÅret = dayjs(`${årstall}-12-31`).toDate();

const minimumDate = dayjs.min([dayjs(sisteDagIÅret), dayjs(dateToday)]);
const minimumDate = dayjs.min([dayjs(sisteDagIÅret), dayjs(getDateToday())]);
const toDate = minimumDate?.isValid() ? minimumDate.toDate() : sisteDagIÅret;

return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { YesOrNo } from '@navikt/sif-common-core-ds/src/types/YesOrNo';
import { DateRange, dateToday } from '@navikt/sif-common-utils';
import { DateRange, getDateToday } from '@navikt/sif-common-utils';
import { getDateValidator, getYesOrNoValidator } from '@navikt/sif-common-formik-ds/src/validation';
import { ValidationError, getTypedFormComponents } from '@navikt/sif-common-formik-ds';
import { ArbeidssituasjonFormFields, ArbeidssituasjonFormValues } from '../ArbeidssituasjonStep';
Expand Down Expand Up @@ -33,11 +33,11 @@ const FrilansFormPart: React.FC<Props> = ({ values, fraværPeriode }) => {
const valgtStartdato = datepickerUtils.getDateFromDateString(frilans_startdato);
const startetDateRange: DateRange = {
from: nYearsAgo(80),
to: fraværPeriode?.to || dateToday,
to: fraværPeriode?.to || getDateToday(),
};
const sluttetDateRange: DateRange = {
from: valgtStartdato || startetDateRange.from || nYearsAgo(80),
to: dateToday,
to: getDateToday(),
};

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { YesOrNo } from '@navikt/sif-common-formik-ds';
import { AnnetBarn } from '@navikt/sif-common-forms-ds/src/forms/annet-barn/types';
import { dateToday } from '@navikt/sif-common-utils';
import dayjs from 'dayjs';
import { BarnAlderInfo } from '../../../types/BarnAlderInfo';
import { DineBarnScenario } from '../../../types/DineBarnScenario';
Expand All @@ -10,9 +9,10 @@ import { SøknadContextState, TempFormValues } from '../../../types/SøknadConte
import { DineBarnSøknadsdata, DineBarnSøknadsdataType } from '../../../types/søknadsdata/DineBarnSøknadsdata';
import { Søknadsdata } from '../../../types/søknadsdata/Søknadsdata';
import { DineBarnFormValues } from './DineBarnStep';
import { getDateToday } from '@navikt/sif-common-utils';

export const nYearsAgo = (years: number): Date => {
return dayjs(dateToday).subtract(years, 'y').startOf('year').toDate();
return dayjs(getDateToday()).subtract(years, 'y').startOf('year').toDate();
};

export const getYesOrNoFromBoolean = (value?: boolean): YesOrNo => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import React from 'react';
import FormBlock from '@navikt/sif-common-core-ds/src/atoms/form-block/FormBlock';
import AnnetBarnListAndDialog from '@navikt/sif-common-forms-ds/src/forms/annet-barn/AnnetBarnListAndDialog';
import { AnnetBarn } from '@navikt/sif-common-forms-ds/src/forms/annet-barn/types';
import { dateToday } from '@navikt/sif-common-utils';

import { useAppIntl } from '../../../../i18n';
import { DineBarnFormFields } from '../DineBarnStep';
import { nYearsAgo } from '../dineBarnStepUtils';
import { getDateToday } from '@navikt/sif-common-utils';

interface Props {
søkerFnr: string;
Expand Down Expand Up @@ -34,7 +35,7 @@ const AndreBarnPart: React.FunctionComponent<Props> = ({

modalTitle: text('step.dineBarn.annetBarnListAndDialog.modalTitle'),
}}
maxDate={dateToday}
maxDate={getDateToday()}
minDate={nYearsAgo(18)}
disallowedFødselsnumre={[...[søkerFnr], ...andreBarnFnr]}
aldersGrenseText={text('step.dineBarn.formLeggTilBarn.aldersGrenseInfo')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import FraværDagerListAndDialog from '@navikt/sif-common-forms-ds/src/forms/fra
import FraværPerioderListAndDialog from '@navikt/sif-common-forms-ds/src/forms/fravær/FraværPerioderListAndDialog';
import { FraværDag, FraværPeriode } from '@navikt/sif-common-forms-ds/src/forms/fravær/types';
import { Utenlandsopphold } from '@navikt/sif-common-forms-ds/src/forms/utenlandsopphold/types';
import { date1YearAgo, dateToday } from '@navikt/sif-common-utils';

import PersistStepFormValues from '../../../components/persist-step-form-values/PersistStepFormValues';
import { useOnValidSubmit } from '../../../hooks/useOnValidSubmit';
import { usePersistTempFormValues } from '../../../hooks/usePersistTempFormValues';
Expand All @@ -35,6 +35,7 @@ import FraværStepInfo from './FraværStepInfo';
import fraværStepUtils, { getFraværStepInitialValues, getFraværSøknadsdataFromFormValues } from './FraværStepUtils';
import OmsorgsdagerInfo from './OmsorgsdagerInfo';
import { useFraværsperiodeDetaljer } from './useFraværsperiodeDetaljer';
import { getDate1YearAgo, getDateToday } from '@navikt/sif-common-utils';

export enum FraværFormFields {
harPerioderMedFravær = 'harPerioderMedFravær',
Expand Down Expand Up @@ -122,8 +123,8 @@ const FraværStep = () => {
const kanIkkeFortsette =
harPerioderMedFravær === YesOrNo.NO && harDagerMedDelvisFravær === YesOrNo.NO;
const harRegistrertFravær = fraværDager.length + fraværPerioder.length > 0;
const minDateForFravær = harRegistrertFravær ? gyldigTidsrom.from : date1YearAgo;
const maxDateForFravær = harRegistrertFravær ? gyldigTidsrom.to : dateToday;
const minDateForFravær = harRegistrertFravær ? gyldigTidsrom.from : getDate1YearAgo();
const maxDateForFravær = harRegistrertFravær ? gyldigTidsrom.to : getDateToday();
return (
<>
<FormikValuesObserver
Expand Down
Loading

0 comments on commit 78cb3b7

Please sign in to comment.