-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EZP-30099: Define preferred user date format
- Loading branch information
Showing
48 changed files
with
992 additions
and
109 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
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
96 changes: 36 additions & 60 deletions
96
src/bundle/Resources/public/js/scripts/admin.format.date.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,66 +1,42 @@ | ||
(function(moment) { | ||
const formatEx = /[dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU]/g; | ||
|
||
const formatEx = /[GdayLqDeEc]+/g; | ||
const formatMap = { | ||
d: 'DD', | ||
D: 'ddd', | ||
j: 'D', | ||
l: 'dddd', | ||
N: 'E', | ||
S: function() { | ||
return '[' + this.format('Do').replace(/\d*/g, '') + ']'; | ||
}, | ||
w: 'd', | ||
z: function() { | ||
return this.format('DDD') - 1; | ||
}, | ||
W: 'W', | ||
F: 'MMMM', | ||
m: 'MM', | ||
M: 'MMM', | ||
n: 'M', | ||
t: function() { | ||
return this.daysInMonth(); | ||
}, | ||
L: function() { | ||
return this.isLeapYear() ? 1 : 0; | ||
}, | ||
o: 'GGGG', | ||
Y: 'YYYY', | ||
y: 'YY', | ||
a: 'a', | ||
A: 'A', | ||
B: function() { | ||
var thisUTC = this.clone().utc(), | ||
swatch = ((thisUTC.hours() + 1) % 24) + thisUTC.minutes() / 60 + thisUTC.seconds() / 3600; | ||
return Math.floor((swatch * 1000) / 24); | ||
}, | ||
g: 'h', | ||
G: 'H', | ||
h: 'hh', | ||
H: 'HH', | ||
i: 'mm', | ||
s: 'ss', | ||
u: '[u]', | ||
e: '[e]', | ||
I: function() { | ||
return this.isDST() ? 1 : 0; | ||
}, | ||
O: 'ZZ', | ||
P: 'Z', | ||
T: '[T]', | ||
Z: function() { | ||
return parseInt(this.format('ZZ'), 10) * 36; | ||
}, | ||
c: 'YYYY-MM-DD[T]HH:mm:ssZ', | ||
r: 'ddd, DD MMM YYYY HH:mm:ss ZZ', | ||
U: 'X', | ||
dd: 'DD', | ||
d: 'D', | ||
a: 'A', | ||
y: 'Y', | ||
yy: 'YY', | ||
yyyy: 'YYYY', | ||
LLLL: 'MMMM', | ||
LLL: 'MMM', | ||
LL: 'MM', | ||
L: 'M', | ||
q: 'Q', | ||
D: 'DDD', | ||
eeeeee: 'dd', | ||
eeee: 'dddd', | ||
eee: 'ddd', | ||
ee: 'E', | ||
e: 'E', | ||
EEEEEE: 'dd', | ||
EEEE: 'dddd', | ||
EEE: 'ddd', | ||
EE: 'ddd', | ||
E: 'ddd', | ||
cccccc: 'dd', | ||
cccc: 'dddd', | ||
ccc: 'ddd', | ||
cc: 'E', | ||
c: 'E', | ||
}; | ||
|
||
moment.fn.formatPHP = function(format) { | ||
return this.format( | ||
format.replace(formatEx, (phpStr) => { | ||
return typeof formatMap[phpStr] === 'function' ? formatMap[phpStr].call(this) : formatMap[phpStr]; | ||
}) | ||
); | ||
moment.fn.formatICU = function(format) { | ||
let form = format.replace(formatEx, (icuStr) => { | ||
return typeof formatMap[icuStr] === 'function' ? formatMap[icuStr].call(this) : formatMap[icuStr]; | ||
}); | ||
|
||
return this.format(form); | ||
}; | ||
|
||
})(window.moment); |
19 changes: 19 additions & 0 deletions
19
src/bundle/Resources/public/js/scripts/admin.user_settings.datetime_format.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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
(function(global, doc) { | ||
|
||
const dateDropdown = doc.querySelector('#user_setting_update_value_date_format'); | ||
const timeDropdown = doc.querySelector('#user_setting_update_value_time_format'); | ||
const demoContainer = doc.querySelector('#datetime_format_demo'); | ||
|
||
const updateDemoDateFormat = () => { | ||
let dateFormat = dateDropdown.options[dateDropdown.selectedIndex].value; | ||
let timeFormat = timeDropdown.options[timeDropdown.selectedIndex].value; | ||
let datetimeFormat = dateFormat + ' ' + timeFormat; | ||
|
||
demoContainer.innerHTML = global.eZ.helpers.timezone.formatDate(new Date(), datetimeFormat); | ||
}; | ||
|
||
dateDropdown.addEventListener('change', updateDemoDateFormat, false); | ||
timeDropdown.addEventListener('change', updateDemoDateFormat, false); | ||
updateDemoDateFormat(); | ||
|
||
})(window, document); |
17 changes: 4 additions & 13 deletions
17
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,20 @@ | ||
(function(global, doc, eZ, moment) { | ||
const userPreferedTimezone = eZ.adminUiConfig.timezone; | ||
const userPreferedFullDateFormat = eZ.adminUiConfig.dateFormat.full; | ||
const userPreferedShortDateFormat = eZ.adminUiConfig.dateFormat.short; | ||
const userPreferedDateFormat = eZ.adminUiConfig.dateFormat; | ||
|
||
const convertDateToTimezone = (date, timezone = userPreferedTimezone) => { | ||
return moment(date).tz(timezone); | ||
}; | ||
const formatDate = (date, format = userPreferedFullDateFormat) => { | ||
return moment(date).formatPHP(format); | ||
const formatDate = (date, format = userPreferedDateFormat) => { | ||
return moment(date).formatICU(format); | ||
}; | ||
const formatShortDate = (date, format = userPreferedShortDateFormat) => { | ||
return moment(date).formatPHP(format); | ||
}; | ||
const formatDateWithTimezone = (date, timezone = userPreferedTimezone, format = userPreferedFullDateFormat) => { | ||
return formatDate(convertDateToTimezone(date, timezone), format); | ||
}; | ||
const formatShortDateWithTimezone = (date, timezone = userPreferedTimezone, format = userPreferedShortDateFormat) => { | ||
const formatDateWithTimezone = (date, timezone = userPreferedTimezone, format = userPreferedDateFormat) => { | ||
return formatDate(convertDateToTimezone(date, timezone), format); | ||
}; | ||
|
||
eZ.addConfig('helpers.timezone', { | ||
convertDateToTimezone, | ||
formatDate, | ||
formatShortDate, | ||
formatDateWithTimezone, | ||
formatShortDateWithTimezone, | ||
}); | ||
})(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
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
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
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
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
Oops, something went wrong.