-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable non gregorian calendars in views and lists
- Loading branch information
1 parent
416cfa4
commit 556079f
Showing
19 changed files
with
129 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/core_modules/capture-core/utils/converters/date/convertIsoToLocalCalendar.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// @flow | ||
import { | ||
convertFromIso8601, | ||
} from '@dhis2/multi-calendar-dates'; | ||
import { systemSettingsStore } from '../../../../capture-core/metaDataMemoryStores'; | ||
import { padWithZeros } from './padWithZeros'; | ||
|
||
/** | ||
* Converts a date from ISO calendar to local calendar | ||
* @export | ||
* @param {string} isoDate - date in ISO format | ||
* @returns {string} | ||
*/ | ||
|
||
export function convertIsoToLocalCalendar(isoDate: string): string { | ||
if (!isoDate) { | ||
return ''; | ||
} | ||
const calendar = systemSettingsStore.get().calendar; | ||
const dateFormat = systemSettingsStore.get().dateFormat; | ||
|
||
const { year, eraYear, month, day } = convertFromIso8601(isoDate, calendar); | ||
const localYear = calendar === 'ethiopian' ? eraYear : year; | ||
|
||
return dateFormat === 'DD-MM-YYYY' | ||
? `${padWithZeros(day, 2)}-${padWithZeros(month, 2)}-${padWithZeros(localYear, 4)}` | ||
: `${padWithZeros(localYear, 4)}-${padWithZeros(month, 2)}-${padWithZeros(day, 2)}`; | ||
} |
26 changes: 26 additions & 0 deletions
26
src/core_modules/capture-core/utils/converters/date/convertLocalToIsoCalendar.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// @flow | ||
import moment from 'moment'; | ||
import { | ||
convertToIso8601, | ||
} from '@dhis2/multi-calendar-dates'; | ||
import { systemSettingsStore } from '../../../../capture-core/metaDataMemoryStores'; | ||
import { padWithZeros } from './padWithZeros'; | ||
|
||
/** | ||
* Converts a date from local calendar to ISO calendar | ||
* @export | ||
* @param {string} localDate - date in local calendar format | ||
* @returns {string} | ||
*/ | ||
export function convertLocalToIsoCalendar(localDate: string): string { | ||
if (!localDate) { | ||
return ''; | ||
} | ||
const calendar = systemSettingsStore.get().calendar; | ||
|
||
const { year, month, day } = convertToIso8601(localDate, calendar); | ||
const dateString = `${padWithZeros(year, 4)}-${padWithZeros(month, 2)}-${padWithZeros(day, 2)}`; | ||
const parsedMoment = moment(dateString); | ||
|
||
return parsedMoment.isValid() ? parsedMoment.toISOString() : ''; | ||
} |
10 changes: 5 additions & 5 deletions
10
src/core_modules/capture-core/utils/converters/date/dateObjectToDateFormatString.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
// @flow | ||
import moment from 'moment'; | ||
import { systemSettingsStore } from '../../../metaDataMemoryStores'; | ||
import { convertIsoToLocalCalendar } from './convertIsoToLocalCalendar'; | ||
|
||
/** | ||
* Converts a date instance to a string based on the system date format | ||
* @export | ||
* @param {Date} dateValue: the date instance | ||
* @returns {string} | ||
*/ | ||
export function convertDateObjectToDateFormatString(dateValue: Date) { | ||
const dateFormat = systemSettingsStore.get().dateFormat; | ||
const formattedDateString = moment(dateValue).format(dateFormat); | ||
return formattedDateString; | ||
export function convertDateObjectToDateFormatString(dateValue: Date | moment$Moment) { | ||
const momentDate = moment(dateValue); | ||
const dateString = momentDate.format('YYYY-MM-DD'); | ||
return convertIsoToLocalCalendar(dateString); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/core_modules/capture-core/utils/converters/date/padWithZeros.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// @flow | ||
|
||
/** | ||
* Pads a string or number with zeros at the start to reach a minimum length | ||
* @export | ||
* @param {string|number} value - the value to pad | ||
* @param {number} length - length required | ||
* @returns {string} | ||
*/ | ||
export function padWithZeros(value: string | number, length: number): string { | ||
return String(value).padStart(length, '0'); | ||
} |
Oops, something went wrong.