Update datetimeformat

This commit is contained in:
kwaroran
2024-04-25 00:33:49 +09:00
parent 3e5b922c8b
commit 06742fe16e

View File

@@ -904,6 +904,11 @@ const matcher = (p1:string,matcherArg:matcherArg) => {
} }
return out return out
} }
case 'date':
case 'time':
case 'datetimeformat':{
return dateTimeFormat(arra[1])
}
} }
} }
if(p1.startsWith('random')){ if(p1.startsWith('random')){
@@ -957,8 +962,17 @@ const matcher = (p1:string,matcherArg:matcherArg) => {
return (Math.floor(Math.random() * maxRoll) + 1).toString() return (Math.floor(Math.random() * maxRoll) + 1).toString()
} }
if(p1.startsWith('datetimeformat')){ if(p1.startsWith('datetimeformat')){
const date = new Date()
let main = p1.substring("datetimeformat".length + 1) let main = p1.substring("datetimeformat".length + 1)
return dateTimeFormat(main)
}
return null
} catch (error) {
return null
}
}
const dateTimeFormat = (main:string) => {
const date = new Date()
if(!main){ if(!main){
return '' return ''
} }
@@ -975,13 +989,11 @@ const matcher = (p1:string,matcherArg:matcherArg) => {
.replace(/hh?/g, (date.getHours() % 12).toString().padStart(2, '0')) .replace(/hh?/g, (date.getHours() % 12).toString().padStart(2, '0'))
.replace(/mm?/g, date.getMinutes().toString().padStart(2, '0')) .replace(/mm?/g, date.getMinutes().toString().padStart(2, '0'))
.replace(/ss?/g, date.getSeconds().toString().padStart(2, '0')) .replace(/ss?/g, date.getSeconds().toString().padStart(2, '0'))
.replace(/X?/g, (Date.now() / 1000).toFixed(2))
.replace(/x?/g, Date.now().toFixed())
.replace(/A/g, date.getHours() >= 12 ? 'PM' : 'AM') .replace(/A/g, date.getHours() >= 12 ? 'PM' : 'AM')
.replace(/MMMM?/g, Intl.DateTimeFormat('en', { month: 'long' }).format(date)) .replace(/MMMM?/g, Intl.DateTimeFormat('en', { month: 'long' }).format(date))
}
return null
} catch (error) {
return null
}
} }
const smMatcher = (p1:string,matcherArg:matcherArg) => { const smMatcher = (p1:string,matcherArg:matcherArg) => {