|
|
|
@ -3,6 +3,7 @@ dayjs.extend(require("dayjs/plugin/duration")) |
|
|
|
dayjs.extend(require("dayjs/plugin/advancedFormat")) |
|
|
|
dayjs.extend(require("dayjs/plugin/relativeTime")) |
|
|
|
dayjs.extend(require("dayjs/plugin/utc")) |
|
|
|
dayjs.extend(require("dayjs/plugin/timezone")) |
|
|
|
|
|
|
|
/** |
|
|
|
* This file was largely taken from the helper-date package - we did this for two reasons: |
|
|
|
@ -72,7 +73,8 @@ function setLocale(str, pattern, options) { |
|
|
|
// if options is null then it'll get updated here
|
|
|
|
const config = initialConfig(str, pattern, options) |
|
|
|
const defaults = { lang: "en", date: new Date(config.str) } |
|
|
|
const opts = getContext(this, defaults, config.options) |
|
|
|
// for now don't allow this to be configurable, don't pass in options
|
|
|
|
const opts = getContext(this, defaults, {}) |
|
|
|
|
|
|
|
// set the language to use
|
|
|
|
dayjs.locale(opts.lang || opts.language) |
|
|
|
@ -89,7 +91,15 @@ module.exports.date = (str, pattern, options) => { |
|
|
|
|
|
|
|
setLocale(config.str, config.pattern, config.options) |
|
|
|
|
|
|
|
const date = dayjs(new Date(config.str)).utc() |
|
|
|
let date = dayjs(new Date(config.str)) |
|
|
|
if (typeof config.options === "string") { |
|
|
|
date = |
|
|
|
config.options.toLowerCase() === "utc" |
|
|
|
? date.utc() |
|
|
|
: date.tz(config.options) |
|
|
|
} else { |
|
|
|
date = date.tz(dayjs.tz.guess()) |
|
|
|
} |
|
|
|
if (config.pattern === "") { |
|
|
|
return date.toISOString() |
|
|
|
} |
|
|
|
|