Skip to content

Commit

Permalink
[Improvement]: Set default date time formats on startup based on user…
Browse files Browse the repository at this point in the history
… locale (#554)
  • Loading branch information
kingjia90 authored Jun 18, 2024
1 parent 776fc43 commit 6ae0a3b
Show file tree
Hide file tree
Showing 47 changed files with 309 additions and 80 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"php": "~8.1.0 || ~8.2.0 || ~8.3.0",
"cbschuld/browser.php": "^1.9.6",
"phpoffice/phpspreadsheet": "^1.24 || ^2.1",
"pimcore/pimcore": "^11.3.0",
"pimcore/pimcore": "11.3.0-RC1",
"symfony/webpack-encore-bundle": "^1.13.2"
},
"require-dev": {
Expand Down
2 changes: 1 addition & 1 deletion public/js/pimcore/asset/helpers/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ pimcore.asset.helpers.grid = Class.create({
locked: this.getColumnLock(field),
renderer: function (d) {
var date = new Date(d * 1000);
return Ext.Date.format(date, "Y-m-d H:i:s");
return Ext.Date.format(date, pimcore.globalmanager.get('localeDateTime').getDateTimeFormat());
}
});
} else if (key == "filename") {
Expand Down
2 changes: 1 addition & 1 deletion public/js/pimcore/asset/helpers/gridConfigDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ pimcore.asset.helpers.gridConfigDialog = Class.create(pimcore.element.helpers.gr
} else if ((key == "modificationDate" || key == "creationDate") && value) {
var timestamp = intval(value) * 1000;
var date = new Date(timestamp);
return Ext.Date.format(date, "Y-m-d H:i");
return Ext.Date.format(date, pimcore.globalmanager.get('localeDateTime').getShortDateTimeFormat());

} else {
var fieldType = record.data.dataType;
Expand Down
4 changes: 2 additions & 2 deletions public/js/pimcore/asset/listfolder.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ pimcore.asset.listfolder = Class.create(pimcore.asset.helpers.gridTabAbstract, {
gridColumns.push({text: t(field.label), width: this.getColumnWidth(field, 150), sortable: true, dataIndex: field.key, editable: false, filter: 'date',
renderer: function(d) {
var date = new Date(d * 1000);
return Ext.Date.format(date, "Y-m-d H:i:s");
return Ext.Date.format(date, pimcore.globalmanager.get('localeDateTime').getDateTimeFormat());
}
});
} else if (key == "filename") {
Expand All @@ -396,7 +396,7 @@ pimcore.asset.listfolder = Class.create(pimcore.asset.helpers.gridTabAbstract, {
renderer: function(d) {
if (d) {
var date = new Date(d * 1000);
return Ext.Date.format(date, "Y-m-d");
return Ext.Date.format(date, pimcore.globalmanager.get('localeDateTime').getShortDateFormat());
}

}
Expand Down
9 changes: 3 additions & 6 deletions public/js/pimcore/asset/metadata/tags/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pimcore.asset.metadata.tags.date = Class.create(pimcore.asset.metadata.tags.abst
var timestamp = intval(value) * 1000;
var date = new Date(timestamp);

return Ext.Date.format(date, "Y-m-d");
return Ext.Date.format(date, pimcore.globalmanager.get('localeDateTime').getShortDateFormat());
}
return "";
}.bind(this, field.key)
Expand All @@ -63,7 +63,6 @@ pimcore.asset.metadata.tags.date = Class.create(pimcore.asset.metadata.tags.abst
name:this.fieldConfig.name,
componentCls:"object_field",
width:130,
format: "Y-m-d"
};

if (this.fieldConfig.labelWidth) {
Expand Down Expand Up @@ -96,9 +95,7 @@ pimcore.asset.metadata.tags.date = Class.create(pimcore.asset.metadata.tags.abst
},

getGridCellEditor: function (gridtype, record) {
return Ext.create('Ext.form.field.Date', {
format: "Y-m-d"
});
return Ext.create('Ext.form.field.Date');
},

convertPredefinedGridData: function(v, r) {
Expand All @@ -114,7 +111,7 @@ pimcore.asset.metadata.tags.date = Class.create(pimcore.asset.metadata.tags.abst
if(!(value instanceof Date)) {
value = new Date(value * 1000);
}
return Ext.Date.format(value, "Y-m-d");
return Ext.Date.format(value, pimcore.globalmanager.get('localeDateTime').getShortDateFormat());
}

return Ext.util.Format.htmlEncode(value);
Expand Down
4 changes: 2 additions & 2 deletions public/js/pimcore/asset/versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ pimcore.asset.versions = Class.create({
return "";
}.bind(this), editable: false},
{text: t("date"), width:150, sortable: true, dataIndex: 'date', filter: 'date', renderer: function(d) {
return Ext.Date.format(d, "Y-m-d H:i:s");
return Ext.Date.format(d, pimcore.globalmanager.get('localeDateTime').getDateTimeFormat());
}},
{text: "ID", sortable: true, dataIndex: 'id', editable: false, width: 60},
{text: t("user"), sortable: true, dataIndex: 'name', filter: 'list'},
{text: t("scheduled"), width:130, sortable: true, dataIndex: 'scheduled', renderer: function(d) {
if (d != null){
var date = new Date(d * 1000);
return Ext.Date.format(date, "Y-m-d H:i:s");
return Ext.Date.format(date, pimcore.globalmanager.get('localeDateTime').getDateTimeFormat());
}
}, editable: false},
{text: t("note"), sortable: true, dataIndex: 'note', editor: new Ext.form.TextField(), filter: 'string', renderer: Ext.util.Format.htmlEncode}
Expand Down
2 changes: 1 addition & 1 deletion public/js/pimcore/document/editables/scheduledblock.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ pimcore.document.editables.scheduledblock = Class.create(pimcore.document.editab
var timestamp = new Date(element.date * 1000);

jumpMenuEntries.push({
text: Ext.Date.format(timestamp, 'Y-m-d H:i'),
text: Ext.Date.format(timestamp, pimcore.globalmanager.get('localeDateTime').getShortDateTimeFormat()),
iconCls: 'pimcore_icon_time',
handler: function(element, timestamp) {
this.dateField.setValue(timestamp);
Expand Down
4 changes: 2 additions & 2 deletions public/js/pimcore/document/pages/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ Ext.define('pimcore.document.pages.preview', {
width: '100%',
cls: 'pimcore_document_preview_timeslider',
tipText: function(thumb){
var date = new Date(thumb.value * 1000);
return Ext.Date.format(date, 'H:i');
const date = new Date(thumb.value * 1000);
return Ext.Date.format(date, pimcore.globalmanager.get('localeDateTime').getShortTimeFormat());
},
listeners: {
change: function(field, newValue, oldValue) {
Expand Down
2 changes: 1 addition & 1 deletion public/js/pimcore/document/settings_abstract.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ pimcore.document.settings_abstract = Class.create({

if (this.document.data.staticLastGenerated) {
const date = new Date(this.document.data.staticLastGenerated * 1000);
lastGenerated = Ext.Date.format(date, "Y-m-d H:i");
lastGenerated = Ext.Date.format(date, pimcore.globalmanager.get('localeDateTime').getShortDateTimeFormat());
}else{
lastGenerated = t('never');
}
Expand Down
4 changes: 2 additions & 2 deletions public/js/pimcore/document/versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pimcore.document.versions = Class.create({
},
{
text: t("date"), width: 150, sortable: true, dataIndex: 'date', filter: 'date', renderer: function (d) {
return Ext.Date.format(d, "Y-m-d H:i:s");
return Ext.Date.format(d, pimcore.globalmanager.get('localeDateTime').getDateTimeFormat());
}, editable: false
},
{text: "ID", sortable: true, dataIndex: 'id', editable: false, width: 60},
Expand All @@ -138,7 +138,7 @@ pimcore.document.versions = Class.create({
renderer: function (d) {
if (d != null) {
var date = new Date(d * 1000);
return Ext.Date.format(date, "Y-m-d H:i:s");
return Ext.Date.format(date, pimcore.globalmanager.get('localeDateTime').getDateTimeFormat());
}
return d;
},
Expand Down
2 changes: 1 addition & 1 deletion public/js/pimcore/element/helpers/gridColumnConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ pimcore.element.helpers.gridColumnConfig = {
var value = filterData[i].getValue();

if (value instanceof Date) {
value = Ext.Date.format(value, "Y-m-d");
value = Ext.Date.format(value, pimcore.globalmanager.get('localeDateTime').getShortDateFormat());
}

if (value && typeof value == "object") {
Expand Down
2 changes: 1 addition & 1 deletion public/js/pimcore/element/note_details.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ pimcore.element.note_details = Class.create({
xtype: "textfield",
fieldLabel: t('date'),
readOnly: true,
value: Ext.Date.format(date, "Y-m-d H:i:s")
value: Ext.Date.format(date, pimcore.globalmanager.get('localeDateTime').getDateTimeFormat())
}
);

Expand Down
4 changes: 2 additions & 2 deletions public/js/pimcore/element/notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ pimcore.element.notes = Class.create({
}},
{text: t("date"), sortable: true, dataIndex: 'date', flex: 100, filter: 'date', renderer: function(d) {
var date = new Date(d * 1000);
return Ext.Date.format(date, "Y-m-d H:i:s");
return Ext.Date.format(date, pimcore.globalmanager.get('localeDateTime').getDateTimeFormat());
}}
];

Expand Down Expand Up @@ -291,7 +291,7 @@ pimcore.element.notes = Class.create({
} else if (record.get("type") == "date") {
if(value) {
var date = new Date(value * 1000);
return Ext.Date.format(date, "Y-m-d H:i:s");
return Ext.Date.format(date, pimcore.globalmanager.get('localeDateTime').getDateTimeFormat());
}
}

Expand Down
13 changes: 5 additions & 8 deletions public/js/pimcore/element/scheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pimcore.element.scheduler = Class.create({
td = [
rawTask.id,
d,
Ext.Date.format(d, "H:i"),
Ext.Date.format(d, pimcore.globalmanager.get('localeDateTime').getShortTimeFormat()),
rawTask.action
];

Expand All @@ -63,7 +63,7 @@ pimcore.element.scheduler = Class.create({
convert: function (v, rec) {
var ret = v;
if (v instanceof Date) {
ret = Ext.Date.format(v, "Y-m-d");
ret = Ext.Date.format(v, pimcore.globalmanager.get('localeDateTime').getShortDateFormat());
}
return ret;
}
Expand All @@ -73,7 +73,7 @@ pimcore.element.scheduler = Class.create({
convert: function (v, rec) {
var ret = v;
if (v instanceof Date) {
ret = Ext.Date.format(v, "H:i");
ret = Ext.Date.format(v, pimcore.globalmanager.get('localeDateTime').getShortTimeFormat());
}
return ret;
}
Expand Down Expand Up @@ -112,7 +112,7 @@ pimcore.element.scheduler = Class.create({
fields: ['id', {name: 'date', convert: function (v, rec) {
var d = new Date(intval(v) * 1000);

var ret = Ext.Date.format(d, "Y-m-d H:i");
var ret = Ext.Date.format(d, pimcore.globalmanager.get('localeDateTime').getShortDateTimeFormat());

if (rec.data.note) {
ret += " - " + rec.data.note;
Expand Down Expand Up @@ -141,12 +141,9 @@ pimcore.element.scheduler = Class.create({
});

var propertiesColumns = [
{text: t("date"), width: 120, sortable: true, dataIndex: 'date', editor: new Ext.form.DateField({
format: "Y-m-d"
})
{text: t("date"), width: 120, sortable: true, dataIndex: 'date', editor: new Ext.form.DateField()
},
{text: t("time"), width: 100, sortable: true, dataIndex: 'time', editor: new Ext.form.TimeField({
format: "H:i",
listeners: {
focus : function(component) {
component.setValue(Ext.util.Format.htmlDecode(component.value));
Expand Down
2 changes: 1 addition & 1 deletion public/js/pimcore/layout/portlets/modifiedAssets.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pimcore.layout.portlets.modifiedAssets = Class.create(pimcore.layout.portlets.ab
{text: t('path'), sortable: false, dataIndex: 'path', flex: 1},
{text: t('date'), width: 150, sortable: false, renderer: function (d) {
var date = new Date(d * 1000);
return Ext.Date.format(date,"Y-m-d H:i:s");
return Ext.Date.format(date, pimcore.globalmanager.get('localeDateTime').getDateTimeFormat());
}, dataIndex: 'date'}
],
stripeRows: true,
Expand Down
2 changes: 1 addition & 1 deletion public/js/pimcore/layout/portlets/modifiedDocuments.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pimcore.layout.portlets.modifiedDocuments = Class.create(pimcore.layout.portlets
{text: t('path'), sortable: false, dataIndex: 'path', flex: 1},
{text: t('date'), width: 150, sortable: false, renderer: function (d) {
var date = new Date(d * 1000);
return Ext.Date.format(date,"Y-m-d H:i:s");
return Ext.Date.format(date, pimcore.globalmanager.get('localeDateTime').getDateTimeFormat());
}, dataIndex: 'date'}

],
Expand Down
2 changes: 1 addition & 1 deletion public/js/pimcore/layout/portlets/modifiedObjects.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pimcore.layout.portlets.modifiedObjects = Class.create(pimcore.layout.portlets.a
{text: t('path'), sortable: false, dataIndex: 'path', flex: 1},
{text: t('date'), width: 150, sortable: false, renderer: function (d) {
var date = new Date(d * 1000);
return Ext.Date.format(date,"Y-m-d H:i:s");
return Ext.Date.format(date, pimcore.globalmanager.get('localeDateTime').getDateTimeFormat());
}, dataIndex: 'date'}

],
Expand Down
Loading

0 comments on commit 6ae0a3b

Please sign in to comment.