mirror of
https://github.com/misterunknown/ifm.git
synced 2025-08-10 18:14:00 +02:00
Enable custom date formats. Closes #202
This commit is contained in:
35
src/ifm.js
35
src/ifm.js
@@ -1386,6 +1386,33 @@ function IFM(params) {
|
||||
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
|
||||
*
|
||||
@@ -1415,10 +1442,14 @@ function IFM(params) {
|
||||
*
|
||||
* @param {integer} timestamp - UNIX timestamp
|
||||
*/
|
||||
this.formatDate = function( timestamp ) {
|
||||
let d = new Date( timestamp * 1000 );
|
||||
this.formatDate = function(timestamp) {
|
||||
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");
|
||||
}
|
||||
};
|
||||
|
||||
this.getClipboardLink = function( relpath ) {
|
||||
|
@@ -69,7 +69,8 @@ class IFM {
|
||||
"disable_mime_detection" => 0,
|
||||
"showrefresh" => 1,
|
||||
"forceproxy" => 0,
|
||||
"confirmoverwrite" => 1
|
||||
"confirmoverwrite" => 1,
|
||||
"customDateFormat" => false
|
||||
];
|
||||
|
||||
private $config = [];
|
||||
|
Reference in New Issue
Block a user