|
@@ -4,24 +4,16 @@ import * as fc from 'fullcalendar'
|
|
|
(fc as any).Moment = {
|
|
(fc as any).Moment = {
|
|
|
|
|
|
|
|
toMoment: function(calendar: fc.Calendar, date: Date): moment.Moment {
|
|
toMoment: function(calendar: fc.Calendar, date: Date): moment.Moment {
|
|
|
- let timeZone = calendar.dateEnv.timeZone
|
|
|
|
|
- let mom: moment.Moment
|
|
|
|
|
-
|
|
|
|
|
- if (timeZone === 'local') {
|
|
|
|
|
- mom = moment(date)
|
|
|
|
|
- } else if (timeZone === 'UTC' || !(moment as any).tz) {
|
|
|
|
|
- mom = moment.utc(date)
|
|
|
|
|
- } else {
|
|
|
|
|
- mom = (moment as any).tz(date, timeZone)
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- mom.locale(calendar.dateEnv.locale.codes[0])
|
|
|
|
|
-
|
|
|
|
|
- return mom
|
|
|
|
|
|
|
+ return convertToMoment(
|
|
|
|
|
+ date,
|
|
|
|
|
+ calendar.dateEnv.timeZone,
|
|
|
|
|
+ null,
|
|
|
|
|
+ calendar.dateEnv.locale.codes[0]
|
|
|
|
|
+ )
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
toDuration: function(fcDuration: fc.Duration): moment.Duration {
|
|
toDuration: function(fcDuration: fc.Duration): moment.Duration {
|
|
|
- return moment.duration(fcDuration) // i think all props are accepted?
|
|
|
|
|
|
|
+ return moment.duration(fcDuration) // momment accepts all the props that fc.Duration already has!
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
@@ -29,19 +21,36 @@ import * as fc from 'fullcalendar'
|
|
|
// TODO: what about range!!??
|
|
// TODO: what about range!!??
|
|
|
|
|
|
|
|
fc.registerCmdFormatter('moment', function(cmdStr: string, arg: fc.VerboseFormattingArg) {
|
|
fc.registerCmdFormatter('moment', function(cmdStr: string, arg: fc.VerboseFormattingArg) {
|
|
|
|
|
+ return convertToMoment(
|
|
|
|
|
+ arg.date.array,
|
|
|
|
|
+ arg.timeZone,
|
|
|
|
|
+ arg.date.timeZoneOffset,
|
|
|
|
|
+ arg.localeCodes[0]
|
|
|
|
|
+ ).format(cmdStr)
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+function convertToMoment(input: any, timeZone: string, timeZoneOffset: number | null, locale: string): moment.Moment {
|
|
|
let mom: moment.Moment
|
|
let mom: moment.Moment
|
|
|
|
|
|
|
|
- if (arg.timeZone === 'local') {
|
|
|
|
|
- mom = moment(arg.date.array)
|
|
|
|
|
- } else if (arg.timeZone === 'UTC' || !(moment as any).tz) {
|
|
|
|
|
- mom = moment.utc(arg.date.array)
|
|
|
|
|
|
|
+ if (timeZone === 'local') {
|
|
|
|
|
+ mom = moment(input)
|
|
|
|
|
+
|
|
|
|
|
+ } else if (timeZone === 'UTC') {
|
|
|
|
|
+ mom = moment.utc(input)
|
|
|
|
|
+
|
|
|
|
|
+ } else if ((moment as any).tz) {
|
|
|
|
|
+ mom = (moment as any).tz(input, timeZone)
|
|
|
|
|
+
|
|
|
} else {
|
|
} else {
|
|
|
- mom = (moment as any).tz(arg.date.array, arg.timeZone)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ mom = moment.utc(input)
|
|
|
|
|
|
|
|
- // what about accepting a forced timezone if .tz isn't present?
|
|
|
|
|
|
|
+ if (timeZoneOffset != null) {
|
|
|
|
|
+ mom.utcOffset(timeZoneOffset)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- mom.locale(arg.localeCodes[0])
|
|
|
|
|
|
|
+ mom.locale(locale)
|
|
|
|
|
|
|
|
- return mom.format(cmdStr)
|
|
|
|
|
-})
|
|
|
|
|
|
|
+ return mom
|
|
|
|
|
+}
|