mirror of
https://github.com/misterunknown/ifm.git
synced 2025-08-11 10:34:00 +02:00
Enable custom date formats. Closes #202
This commit is contained in:
33
src/ifm.js
33
src/ifm.js
@@ -1386,6 +1386,33 @@ function IFM(params) {
|
|||||||
return args.join( '/' );
|
return args.join( '/' );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Formats a date like strftime
|
||||||
|
*
|
||||||
|
* @param {Date} date - Date object
|
||||||
|
* @param {string} format - strftime compatible format string
|
||||||
|
* @returns {string} - formatted date
|
||||||
|
*/
|
||||||
|
this.customStrftime = function(date, format) {
|
||||||
|
const pad = (num, size = 2) => String(num).padStart(size, '0');
|
||||||
|
|
||||||
|
const replacements = {
|
||||||
|
'%Y': date.getFullYear(),
|
||||||
|
'%m': pad(date.getMonth() + 1),
|
||||||
|
'%d': pad(date.getDate()),
|
||||||
|
'%H': pad(date.getHours()),
|
||||||
|
'%M': pad(date.getMinutes()),
|
||||||
|
'%S': pad(date.getSeconds()),
|
||||||
|
'%y': String(date.getFullYear()).slice(-2),
|
||||||
|
'%b': date.toLocaleString('default', { month: 'short' }),
|
||||||
|
'%B': date.toLocaleString('default', { month: 'long' }),
|
||||||
|
'%a': date.toLocaleString('default', { weekday: 'short' }),
|
||||||
|
'%A': date.toLocaleString('default', { weekday: 'long' }),
|
||||||
|
};
|
||||||
|
|
||||||
|
return format.replace(/%[a-zA-Z]/g, match => replacements[match] || match);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prevents a user to submit a form via clicking enter
|
* Prevents a user to submit a form via clicking enter
|
||||||
*
|
*
|
||||||
@@ -1416,9 +1443,13 @@ function IFM(params) {
|
|||||||
* @param {integer} timestamp - UNIX timestamp
|
* @param {integer} timestamp - UNIX timestamp
|
||||||
*/
|
*/
|
||||||
this.formatDate = function(timestamp) {
|
this.formatDate = function(timestamp) {
|
||||||
let d = new Date( timestamp * 1000 );
|
let d = new Date(timestamp * 1000)
|
||||||
|
|
||||||
|
if (self.config.customDateFormat) {
|
||||||
|
return self.customStrftime(d, self.config.customDateFormat)
|
||||||
|
} else {
|
||||||
return d.toLocaleString(navigator.language || "en-US");
|
return d.toLocaleString(navigator.language || "en-US");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.getClipboardLink = function( relpath ) {
|
this.getClipboardLink = function( relpath ) {
|
||||||
|
@@ -69,7 +69,8 @@ class IFM {
|
|||||||
"disable_mime_detection" => 0,
|
"disable_mime_detection" => 0,
|
||||||
"showrefresh" => 1,
|
"showrefresh" => 1,
|
||||||
"forceproxy" => 0,
|
"forceproxy" => 0,
|
||||||
"confirmoverwrite" => 1
|
"confirmoverwrite" => 1,
|
||||||
|
"customDateFormat" => false
|
||||||
];
|
];
|
||||||
|
|
||||||
private $config = [];
|
private $config = [];
|
||||||
|
Reference in New Issue
Block a user