View Single Post
Old 03-25-2021, 03:40 PM   #433
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,475
Karma: 8025702
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by chaley View Post
However, I think a good solution is to add the 'timestamp' format to format_date, returning a floating point timestamp. I would also change format_date() to allow a timestamp as the first argument (the "date") permitting conversion of timestamps to date strings. This would do what you need and also facilitate arithmetic on dates. Example:
Code:
program:
	t = format_date($last_modified, 'timestamp');
	strcat(t, ' -- ', format_date(t, 'yyyy MMM ddd hh:MM:ss'))

Result: 1616695611.0 -- 2021 Mar Thu 18:03:51
That idea didn't work out. There were too many ambiguities. Instead I added the date format strings:
  • to_number : convert the date & time into a floating point number (a timestamp)
  • from_number : convert a floating point number (a timestamp) into an iso formatted date. If you want a different date format then add the desired formatting string after from_number and a colon ( : ). Example: from_number:MMM dd yyyy
I used '_number' instead of '_timestamp' because I thought that 'number' better describes what it is.

Example:
Code:
program:
	t = format_date(today(), 'to_number');
	format_date(t, 'from_number:MMM dd yyyy')

Result: Mar 25 2021
I submitted the changes to Kovid to see what he thinks.

Last edited by chaley; 03-25-2021 at 04:27 PM.
chaley is offline   Reply With Quote