Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose function to convert dates #35

Merged
merged 1 commit into from
May 15, 2024
Merged

feat: expose function to convert dates #35

merged 1 commit into from
May 15, 2024

Conversation

kabaros
Copy link
Collaborator

@kabaros kabaros commented May 15, 2024

exposes a method to convert dates from one calendar to another.

Usage:

First install the version of the library from alpha (once PR is merged) yarn add "@dhis2/multi-calendar-dates@alpha"

import { convertDate } from '@dhis2/multi-calendar-dates'


let date = convertDate('2022-10-18', 'nepali')
console.log(date.year, date.month, date.day)

date = convertDate('2022-10-18', 'ethiopic')
console.log(date.eraYear, date.month, date.day) 

The method returns a PlainDate object than can be deconstructed into its parts (year/eraYear, month, day), a helper like the one below can be implemented to return an iso-like string

const toString  = (date) => {
    return date.year + '-'
     + String(date.month).padStart(2, '0')
     + '-'
     + String(date.day).padStart(2, '0')
}


let date = convertDate('2022-10-18', 'nepali')
console.log(toString(date)) // logs  2079-07-01

image

@tomzemp tomzemp merged commit 622f0eb into alpha May 15, 2024
11 checks passed
@dhis2-bot
Copy link
Contributor

🎉 This PR is included in version 1.0.0-alpha.24 🎉

The release is available on:

Your semantic-release bot 📦🚀

@dhis2-bot
Copy link
Contributor

🎉 This PR is included in version 1.3.0-alpha.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@dhis2-bot
Copy link
Contributor

🎉 This PR is included in version 1.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants