Support empty {{ date }}
This commit is contained in:
parent
af74d3df62
commit
6499f7a270
|
@ -33,7 +33,7 @@ const outputJSON: Manifest = {}
|
|||
const ADDED_HELPERS = {
|
||||
date: {
|
||||
date: {
|
||||
args: ["datetime", "format", "[options]"],
|
||||
args: ["[datetime]", "[format]", "[options]"],
|
||||
example: '{{date now "DD-MM-YYYY" "America/New_York" }} -> 21-01-2021',
|
||||
description:
|
||||
"Format a date using moment.js date formatting - the timezone is optional and uses the tz database.",
|
||||
|
|
|
@ -71,7 +71,7 @@ function getContext(thisArg: any, locals: any, options: any) {
|
|||
function initialConfig(str: any, pattern: any, options?: any) {
|
||||
if (isOptions(pattern)) {
|
||||
options = pattern
|
||||
pattern = null
|
||||
pattern = DEFAULT_FORMAT
|
||||
}
|
||||
|
||||
if (isOptions(str)) {
|
||||
|
@ -93,13 +93,15 @@ function setLocale(this: any, str: any, pattern: any, options?: any) {
|
|||
dayjs.locale(opts.lang || opts.language)
|
||||
}
|
||||
|
||||
const DEFAULT_FORMAT = "MMMM DD, YYYY"
|
||||
|
||||
export const date = (str: any, pattern: any, options: any) => {
|
||||
const config = initialConfig(str, pattern, options)
|
||||
|
||||
// if no args are passed, return a formatted date
|
||||
if (config.str == null && config.pattern == null) {
|
||||
dayjs.locale("en")
|
||||
return dayjs().format("MMMM DD, YYYY")
|
||||
return dayjs().format(DEFAULT_FORMAT)
|
||||
}
|
||||
|
||||
setLocale(config.str, config.pattern, config.options)
|
||||
|
|
|
@ -1208,8 +1208,8 @@
|
|||
"date": {
|
||||
"date": {
|
||||
"args": [
|
||||
"datetime",
|
||||
"format",
|
||||
"[datetime]",
|
||||
"[format]",
|
||||
"[options]"
|
||||
],
|
||||
"example": "{{date now \"DD-MM-YYYY\" \"America/New_York\" }} -> 21-01-2021",
|
||||
|
|
Loading…
Reference in New Issue