View Single Post
Old 02-18-2023, 01:32 PM   #515
dunhill
Guru
dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.
 
dunhill's Avatar
 
Posts: 910
Karma: 810834
Join Date: Sep 2017
Location: Buenos Aires, Argentina
Device: moon+ reader, kindle paperwhite
Quote:
Originally Posted by chaley View Post
You don't say what a "bad date" looks like when showing in the booklist or book details. Because you are using a printable date (the value of '#column name') the month names will be in localized. The date functions in calibre are localized to accept 3-letter month names in English, French, and German. See replace_months() in calibre's source calibre.utils.date.

I expect in your case the month abbreviations are in Spanish. In that language many 3-letter month abbreviations are the same as in English, but several differ from their English equivalents such as "abr" instead of "Apr"

You avoid this problem by using raw_field to get the date in ISO-format instead of localized. Something like this, replacing '#mydate' with the real lookup name:
Code:
{:'ifempty(format_date(raw_field('#mydate', ''), 'MMM'), 'Without date')'}
or this, which is more like your original.
Code:
{:'d = raw_field('#mydate', ''); test(d, strcat(format_date(d,'MMM')),'Without date')'}
Note: if this is the only template in the composite column then I suggest you use General Program Mode, as that will be faster because of template caching. Something like this:
Code:
program: ifempty(format_date(raw_field('#mydate', ''), 'MMM'), 'Without date')
Or even faster: a Python template:
Code:
python:
def evaluate(book, context):
	d = book.get('#mydate')
	if d is None:
		return 'Without date'
	# Localize these as you wish
	months = ['ene', 'feb', 'mar', 'abr', 'may', 'jun', 
		  'jul', 'ago', 'sep', 'oct', 'nov', 'dic']
	return months[d.month-1]



Brilliant !! thank you so much !!
dunhill is offline   Reply With Quote