first commit
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
// src/utils/dateBR.js
|
||||
|
||||
export function pad2(n) {
|
||||
return String(n).padStart(2, '0')
|
||||
}
|
||||
|
||||
// ISO (YYYY-MM-DD) -> BR (DD-MM-YYYY)
|
||||
export function isoToBR(iso) {
|
||||
if (!iso) return ''
|
||||
const s = String(iso).slice(0, 10)
|
||||
const [y, m, d] = s.split('-')
|
||||
if (!y || !m || !d) return ''
|
||||
return `${pad2(d)}-${pad2(m)}-${y}`
|
||||
}
|
||||
|
||||
// BR (DD-MM-YYYY) -> ISO (YYYY-MM-DD)
|
||||
export function brToISO(br) {
|
||||
if (!br) return null
|
||||
const s = String(br).trim()
|
||||
const m = s.match(/^(\d{2})-(\d{2})-(\d{4})$/)
|
||||
if (!m) return null
|
||||
const [, dd, mm, yyyy] = m
|
||||
return `${yyyy}-${mm}-${dd}`
|
||||
}
|
||||
Reference in New Issue
Block a user