fman icon indicating copy to clipboard operation
fman copied to clipboard

Option to show 4 digit years

Open keith-hall opened this issue 7 years ago • 4 comments

I notice that fman currently always shows 2 digit years in the Modified column. I would like an option to keep the short date/time format exactly as specified in the locale rather than having fman mangle it

keith-hall avatar Sep 21 '18 09:09 keith-hall

You will be able to implement this yourself as a plugin once #294 is implemented. Then, you can simply copy/paste the code you referenced and remove the "mangling". Some pointers for then:

mherrmann avatar Sep 21 '18 10:09 mherrmann

I would love to be able to format the date and time in ISO 8601 format (YYYY-MM-DD HH:MM:SS). If there is a way to do this, please let me know

blokeley avatar Mar 11 '21 10:03 blokeley

@blokeley you could write a plugin that overwrites the get_str(...) method of the Modified column: https://github.com/fman-users/Core/blob/20d328a67fbd13d1adcf840f8b158040bfb3730f/core/init.py#L92

Something like

from core import Modified

def my_get_str(self, url):
	# Make changes here
	try:
		mtime = self._get_mtime(url)
	except OSError:
		return ''
	if mtime is None:
		return ''
	try:
		timestamp = mtime.timestamp()
	except OSError:
		# This can occur in at least Python 3.6 on Windows. To reproduce:
		#     datetime.min.timestamp()
		# This raises `OSError: [Errno 22] Invalid argument`.
		return ''
	mtime_qt = QDateTime.fromMSecsSinceEpoch(int(timestamp * 1000))
	time_format = QLocale().dateTimeFormat(QLocale.ShortFormat)
	# Always show two-digit years, not four digits:
	time_format = time_format.replace('yyyy', 'yy')
	return mtime_qt.toString(time_format)

Modified.get_str = my_get_str

mherrmann avatar Mar 12 '21 08:03 mherrmann

Thanks @mherrmann If anyone else wants the datetime in ISO 8601 format (YYYY-MM-DD HH:MM to minute resolution) then here is the code I used in a plugin:

from core import Modified


def get_iso_datetime(self, url):
    try:
        mtime = self._get_mtime(url)

    except OSError:
        return ''

    return mtime.isoformat(sep=' ', timespec='minutes') if mtime else ''


Modified.get_str = get_iso_datetime

blokeley avatar Mar 13 '21 15:03 blokeley