forked from ezsystems/ezplatform-admin-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EZP-30263 : User date format don't apply to date fields in content it…
…em update and preview (ezsystems#909) * EZP-30263 : User date format don't apply to date fields in content item update and preview * forces UTC on ezdate and eztime * formats ezdate, eztime, ezdatetime according to user preferences * fixes cs * default timezone form user preferences
- Loading branch information
Showing
7 changed files
with
98 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 45 additions & 13 deletions
58
src/bundle/Resources/public/js/scripts/helpers/timezone.helper.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,61 @@ | ||
(function(global, doc, eZ, moment) { | ||
const userPreferedTimezone = eZ.adminUiConfig.timezone; | ||
const userPreferedFullDateFormat = eZ.adminUiConfig.dateFormat.full; | ||
const userPreferedShortDateFormat = eZ.adminUiConfig.dateFormat.short; | ||
const userPreferedFullDateTimeFormat = eZ.adminUiConfig.dateFormat.fullDateTime; | ||
const userPreferedShortDateTimeFormat = eZ.adminUiConfig.dateFormat.shortDateTime; | ||
|
||
const convertDateToTimezone = (date, timezone = userPreferedTimezone, forceSameTime = false) => { | ||
return moment(date).tz(timezone, forceSameTime); | ||
}; | ||
const formatDate = (date, format = userPreferedFullDateFormat) => { | ||
const formatDate = (date, timezone = null, format) => { | ||
if (timezone) { | ||
date = convertDateToTimezone(date, timezone); | ||
} | ||
|
||
return moment(date).formatICU(format); | ||
}; | ||
const formatDateWithTimezone = (date, timezone = userPreferedTimezone, format = userPreferedFullDateFormat) => { | ||
return formatDate(convertDateToTimezone(date, timezone), format); | ||
const formatFullDateTime = (date, timezone = userPreferedTimezone, format = userPreferedFullDateTimeFormat) => { | ||
return formatDate(date, timezone, format); | ||
}; | ||
const formatShortDate = (date, format = userPreferedShortDateFormat) => { | ||
return formatDate(date, format); | ||
const formatShortDateTime = (date, timezone = userPreferedTimezone, format = userPreferedShortDateTimeFormat) => { | ||
return formatDate(date, timezone, format); | ||
}; | ||
const formatShortDateWithTimezone = (date, timezone = userPreferedTimezone, format = userPreferedShortDateFormat) => { | ||
return formatDateWithTimezone(date, timezone, format); | ||
|
||
const deprecatedFormatDate = (date, format = userPreferedFullDateTimeFormat) => { | ||
console.warn('[DEPRECATED] formatDate function is deprecated'); | ||
console.warn('[DEPRECATED] it will change behaviour from ezplatform-admin-ui 2.0'); | ||
console.warn('[DEPRECATED] use formatFullDateTime instead'); | ||
|
||
return formatFullDateTime(date, null, format); | ||
}; | ||
const deprecatedFormatShortDate = (date, format = userPreferedShortDateTimeFormat) => { | ||
console.warn('[DEPRECATED] formatShortDate function is deprecated'); | ||
console.warn('[DEPRECATED] it will change behaviour from ezplatform-admin-ui 2.0'); | ||
console.warn('[DEPRECATED] use formatShortDateTime instead'); | ||
|
||
return formatShortDateTime(date, null, format); | ||
}; | ||
const deprecatedFormatDateWithTimezone = (date, timezone = userPreferedTimezone, format = userPreferedFullDateTimeFormat) => { | ||
console.warn('[DEPRECATED] formatDateWithTimezone function is deprecated'); | ||
console.warn('[DEPRECATED] it will be removed from ezplatform-admin-ui 2.0'); | ||
console.warn('[DEPRECATED] use formatFullDateTime instead'); | ||
|
||
return formatFullDateTime(date, timezone, format); | ||
}; | ||
const deprecatedFormatShortDateWithTimezone = (date, timezone = userPreferedTimezone, format = userPreferedShortDateTimeFormat) => { | ||
console.warn('[DEPRECATED] formatShortDateWithTimezone function is deprecated'); | ||
console.warn('[DEPRECATED] it will be removed from ezplatform-admin-ui 2.0'); | ||
console.warn('[DEPRECATED] use formatShortDateTime instead'); | ||
|
||
return formatShortDateTime(date, timezone, format); | ||
}; | ||
|
||
eZ.addConfig('helpers.timezone', { | ||
convertDateToTimezone, | ||
formatDate, | ||
formatShortDate, | ||
formatDateWithTimezone, | ||
formatShortDateWithTimezone, | ||
formatFullDateTime, | ||
formatShortDateTime, | ||
formatDate: deprecatedFormatDate, | ||
formatShortDate: deprecatedFormatShortDate, | ||
formatDateWithTimezone: deprecatedFormatDateWithTimezone, | ||
formatShortDateWithTimezone: deprecatedFormatShortDateWithTimezone, | ||
}); | ||
})(window, document, window.eZ, window.moment); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters