Skip to content

Commit

Permalink
refactor: change method name for conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
kabaros committed May 23, 2024
1 parent df3231c commit 4d96fbd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
15 changes: 11 additions & 4 deletions src/utils/convert-date.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { convertDate } from './convert-date'
import { convertFromIso8601 } from './convert-date'

describe('date conversion from gregorian', () => {
describe('to ethiopic', () => {
it('should convert a date', () => {
const result = convertDate('2024-05-23', 'ethiopic')
const result = convertFromIso8601('2024-05-23', { to: 'ethiopic' })

Check failure on line 6 in src/utils/convert-date.spec.ts

View workflow job for this annotation

GitHub Actions / build

Argument of type '{ to: string; }' is not assignable to parameter of type '"iso8601" | "hebrew" | "islamic" | "islamic-umalqura" | "islamic-tbla" | "islamic-civil" | "islamic-rgsa" | "persian" | "ethiopic" | "ethioaa" | "coptic" | "chinese" | "dangi" | ... 5 more ... | "nepali"'.
expect(result.eraYear).toEqual(2016)
expect(result.year).toEqual(7516)
expect(result.month).toEqual(9)
expect(result.day).toEqual(15)
})
it('should convert a date if "ethiopian" is passed instad of "ethiopic"', () => {
const result = convertDate('2024-05-23', 'ethiopian' as any)
const result = convertFromIso8601('2024-05-23', 'ethiopian' as any)
expect(result.eraYear).toEqual(2016)
expect(result.year).toEqual(7516)
expect(result.month).toEqual(9)
Expand All @@ -19,13 +19,20 @@ describe('date conversion from gregorian', () => {
})
describe('to nepali', () => {
it('should convert a date', () => {
const result = convertDate('2024-05-23', 'nepali')
const result = convertFromIso8601('2024-05-23', 'nepali')
expect(result.eraYear).toEqual(2081)
expect(result.year).toEqual(2081)
expect(result.month).toEqual(2)
expect(result.day).toEqual(10)
})
})
it('should convert to islamic date', () => {
const result = convertFromIso8601('2024-05-23', 'islamic')
expect(result.eraYear).toEqual(1445)
expect(result.year).toEqual(1445)
expect(result.month).toEqual(11)
expect(result.day).toEqual(15)
})
})

// gregorian, ethiopic and nepali
Expand Down
2 changes: 1 addition & 1 deletion src/utils/convert-date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type ConvertDateFn = (
calendar: SupportedCalendar
) => Temporal.PlainDate

export const convertDate: ConvertDateFn = (date, userCalendar) => {
export const convertFromIso8601: ConvertDateFn = (date, userCalendar) => {
const calendar = getCustomCalendarIfExists(
dhis2CalendarsMap[userCalendar] ?? userCalendar
) as SupportedCalendar
Expand Down
2 changes: 1 addition & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ export * from './helpers'
export { default as localisationHelpers } from './localisationHelpers'
export { validateDateString } from './validate-date-string'

export { convertDate } from './convert-date'
export { convertFromIso8601 } from './convert-date'

0 comments on commit 4d96fbd

Please sign in to comment.