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 4e50063
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
6 changes: 5 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export * from './hooks'
export * as constants from './constants'
export * from './period-calculation'
export { getNowInCalendar, validateDateString, convertDate } from './utils'
export {
getNowInCalendar,
validateDateString,
convertFromIso8601,
} from './utils'
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', 'ethiopic')
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)

Check warning on line 13 in src/utils/convert-date.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
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 4e50063

Please sign in to comment.