Quote:
Originally Posted by ownedbycats
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