瀏覽代碼

feat: add "timestamp" format in `$date` function

Ahmad Kholid 3 年之前
父節點
當前提交
3072a77eb7
共有 1 個文件被更改,包括 4 次插入4 次删除
  1. 4 4
      src/utils/reference-data/mustache-replacer.js

+ 4 - 4
src/utils/reference-data/mustache-replacer.js

@@ -25,10 +25,10 @@ export const functions = {
     const isValidDate = date instanceof Date && !isNaN(date);
     const dayjsDate = dayjs(isValidDate ? date : Date.now());
 
-    const result =
-      dateFormat === 'relative'
-        ? dayjsDate.fromNow()
-        : dayjsDate.format(dateFormat);
+    let result = dayjsDate.format(dateFormat);
+
+    if (dateFormat === 'relative') result = dayjsDate.fromNow();
+    else if (dateFormat === 'timestamp') result = dayjsDate.valueOf();
 
     return result;
   },