Quote:
Originally Posted by ownedbycats
format_date and partial dates
I'm using this template to display a list of dates formatted as 'yyyy-MM-dd' as 'MMM d yyyy':
Code:
program:
new_dates = '';
for dates in '#datesread':
converted = format_date(dates, 'MMM d yyyy');
new_dates = list_union(new_dates, converted, ',')
rof
However, several entries are just a year; e.g. '2017, 2023-06-13.' When I run them through this template, it ends up filling in the rest of the date so it becomes 2017-03-15.
What should I do here to get '2017, Jun 13 2023'? Alternately, I'd be fine removing the partial dates.
|
The format_date() function expects a date. A year by itself isn't a date, so calibre's parse_date() makes it into one by using the 15th day of the current month. This isn't going to change.
You don't say if you can have a date like '2020-05'. Assuming you can, a variation of this template might give you what you want.
Code:
program:
new_dates = '';
for dates in '2020, 2021-05, 2022-03-10':
if list_count(dates,'-') ==# 3 then
converted = format_date(dates, 'MMM d yyyy')
elif '-' in dates then
converted = re(format_date(dates, 'MMM d yyyy'), ' 15 ', ' ')
else
converted = dates
fi;
new_dates = list_union(new_dates, converted, ',')
rof
It gives the answer
Code:
Mar 10 2022, May 2021, 2020