1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-08-08 15:05:22 +02:00

Handled some edge cases

This commit is contained in:
Shivam0710 2024-01-21 14:01:19 +05:30
parent 26af81dc79
commit 8c13fd1ba2

View file

@ -33,25 +33,29 @@ function toFormattedStr(date: string | null, dateFormat: string): string {
return DateTime.fromISO(date).toFormat(dateFormat)
}
// function to get mask from the given format
function getMaskArray(dateFormat: String): string[] {
return dateFormat
.split('/')
.map((keyword) => keyword.trim())
.join('')
.split('')
.map((keyword) => keyword.toUpperCase())
function getMaskArray(dateFormat: string): string[] {
if (dateFormat === null) {
return []
}
const matchResult = dateFormat.match(/[a-z]/gi)
if (matchResult === null) {
return []
}
return matchResult.map((char: string) => char.toUpperCase())
}
function getDateFormatPattern(dateFormat: string): string {
const dateComponents = dateFormat.split('/')
const pattern = dateComponents
.map((component) => {
if (component.includes('d')) {
if (component.toLowerCase().includes('d')) {
return ' ## ' // Placeholder for day
} else if (component.includes('m') || component.includes('M')) {
} else if (component.toLowerCase().includes('m')) {
return ' ## ' // Placeholder for month
} else if (component.includes('y')) {
} else if (component.toLowerCase().includes('y')) {
return ' #### ' // Placeholder for year
}
return component // Keep non-date components unchanged