View Single Post
Old 01-10-2022, 05:24 AM   #279
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,467
Karma: 8025600
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Question: Is undefined the same as '0' in a days_between?

Code:
program:

	read = $$#lastread;
	updated = $$#fanficupdated;

	if $$#percentread <# 100 && days_between (read, updated) <=# 0 then '#ffff7f'  fi
This activates on books that have an undefined #fanficupdated, though if I change it to <#0 that fixes it.
days_between() returns the empty string if either parameter isn't a date. Numeric comparison treats the empty string as zero, which is why the comparison succeeds.

I suggest that you don't depend on that, instead being explicit about what happens if dates are undefined. There are at least two ways to do it. The first is to use raw_field() with a default, for example
Code:
	read = raw_field('#lastread', today());
which sets read to today() if #lastread is undefined. You can of course put any date you want for the default.

Another way, one that I prefer, is to test if the two dates are defined and do something explicit. Something like this:
Code:
program:

	read = $$#lastread;
	updated = $$#fanficupdated;

	if read == 'none' || updated == 'none' then
		'#090909'
	elif $$#percentread <# 100 && days_between (read, updated) <=# 0 then 
		'#ffff7f' 
	fi
or this
Code:
program:

	read = $$#lastread;
	updated = $$#fanficupdated;

	if read == 'none' || updated == 'none' then
		days = -1
	else
		days = days_between (read, updated)
	fi;

	if $$#percentread <# 100 && days <=# 0 then 
		'#ffff7f' 
	fi

Last edited by chaley; 01-10-2022 at 03:34 PM. Reason: Fix typo
chaley is offline   Reply With Quote