Skip to content

Commit

Permalink
fix: age values not filled correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
alaa-yahia committed Dec 16, 2024
1 parent 3f4b055 commit b213bf4
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/core_modules/capture-ui/AgeField/AgeField.component.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// @flow
import React, { Component } from 'react';
import { isValidPositiveInteger } from 'capture-core-utils/validators/form';
import { convertDateObjectToDateFormatString } from 'capture-core/utils/converters/date';
import { systemSettingsStore } from 'capture-core/metaDataMemoryStores';
import i18n from '@dhis2/d2-i18n';
import classNames from 'classnames';
import { IconButton } from 'capture-ui';
Expand Down Expand Up @@ -72,7 +74,8 @@ function getCalculatedValues(
days: '',
};
}
const now = moment();
const dateFormat = systemSettingsStore.get().dateFormat;
const now = moment(convertDateObjectToDateFormatString(moment()), dateFormat);
const age = moment(parseData.momentDate);

const years = now.diff(age, 'years');
Expand Down Expand Up @@ -133,8 +136,8 @@ class D2AgeFieldPlain extends Component<Props> {
this.props.onBlur({ ...values, date: '' });
return;
}

const momentDate = moment(undefined, undefined, true);
const dateFormat = systemSettingsStore.get().dateFormat;
const momentDate = moment(convertDateObjectToDateFormatString(moment(undefined, undefined, true)), dateFormat);
momentDate.subtract(D2AgeFieldPlain.getNumberOrZero(values.years), 'years');
momentDate.subtract(D2AgeFieldPlain.getNumberOrZero(values.months), 'months');
momentDate.subtract(D2AgeFieldPlain.getNumberOrZero(values.days), 'days');
Expand Down

0 comments on commit b213bf4

Please sign in to comment.