mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-09 07:25:19 +02:00
Handled some edge cases
This commit is contained in:
parent
26af81dc79
commit
8c13fd1ba2
1 changed files with 15 additions and 11 deletions
|
@ -33,25 +33,29 @@ function toFormattedStr(date: string | null, dateFormat: string): string {
|
||||||
return DateTime.fromISO(date).toFormat(dateFormat)
|
return DateTime.fromISO(date).toFormat(dateFormat)
|
||||||
}
|
}
|
||||||
|
|
||||||
// function to get mask from the given format
|
function getMaskArray(dateFormat: string): string[] {
|
||||||
function getMaskArray(dateFormat: String): string[] {
|
if (dateFormat === null) {
|
||||||
return dateFormat
|
return []
|
||||||
.split('/')
|
}
|
||||||
.map((keyword) => keyword.trim())
|
|
||||||
.join('')
|
const matchResult = dateFormat.match(/[a-z]/gi)
|
||||||
.split('')
|
|
||||||
.map((keyword) => keyword.toUpperCase())
|
if (matchResult === null) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
return matchResult.map((char: string) => char.toUpperCase())
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDateFormatPattern(dateFormat: string): string {
|
function getDateFormatPattern(dateFormat: string): string {
|
||||||
const dateComponents = dateFormat.split('/')
|
const dateComponents = dateFormat.split('/')
|
||||||
const pattern = dateComponents
|
const pattern = dateComponents
|
||||||
.map((component) => {
|
.map((component) => {
|
||||||
if (component.includes('d')) {
|
if (component.toLowerCase().includes('d')) {
|
||||||
return ' ## ' // Placeholder for day
|
return ' ## ' // Placeholder for day
|
||||||
} else if (component.includes('m') || component.includes('M')) {
|
} else if (component.toLowerCase().includes('m')) {
|
||||||
return ' ## ' // Placeholder for month
|
return ' ## ' // Placeholder for month
|
||||||
} else if (component.includes('y')) {
|
} else if (component.toLowerCase().includes('y')) {
|
||||||
return ' #### ' // Placeholder for year
|
return ' #### ' // Placeholder for year
|
||||||
}
|
}
|
||||||
return component // Keep non-date components unchanged
|
return component // Keep non-date components unchanged
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue