![]() |
#361 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,450
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
If you are willing to fix the number of days in a year to 360 and the number of days in a month to 30 then the computation is easy. days= whatever; years = floor(days/360); months = floor (mod(days, 360)/30); days = days - ((years*360) + (months * 30)) |
|
![]() |
![]() |
![]() |
#362 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,035
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Yes, I wasn't going for an exact number -- just a rough idea of how long it would be. Thanks.
![]() |
![]() |
![]() |
Advert | |
|
![]() |
#363 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,450
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Code:
program: days = 912; years = if (x = floor(days/360)) > 0 then x else '' fi; months = if (x = floor(mod(days, 360)/30)) > 0 then x else '' fi; days = if (x = days - ((years*360) + (months * 30))) > 0 then x else ''fi; strcat( if years then strcat (years, if years == 1 then ' year ' else ' years ' fi) fi, if months then strcat (months, if months == 1 then ' month ' else ' months ' fi) fi, if days then strcat (days, if days == 1 then ' day ' else ' days ' fi) fi ) Code:
program: days = 912; years = if (x = floor(days/360)) > 0 then x else '' fi; months = if (x = floor(mod(days, 360)/30)) > 0 then x else '' fi; days = if (x = days - ((years*360) + (months * 30))) > 0 then x else ''fi; function to_plural(v, str) { if v == 0 then return '' fi; p = if v == 1 then str else strcat(str, 's') fi; strcat(v, ' ', p, ' ') } strcat( to_plural(years, 'year'), to_plural(months, 'month'), to_plural(days 'day') ) I haven't worked out what happens if there is a name collision. It is likely that I won't allow them to avoid nested symbol tables and all that comes with those. I am also getting tired of writing Code:
strcat('foo', 'bar') Code:
'foo' & 'bar' |
|
![]() |
![]() |
![]() |
#364 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,450
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
This now works. I need to play a bit more with it.
Code:
program: days = 2112; years = floor(days/360); months = floor(mod(days, 360)/30); days = days - ((years*360) + (months * 30)); def to_plural(v, str): if v == 0 then return '' fi; return v & ' ' & (if v == 1 then str else str & 's' fi) & ' ' fed; to_plural(years, 'year') & to_plural(months, 'month') & to_plural(days,'day') I decided to use the same syntax to define functions as used everywhere else, defining the function body with def/fed instead of {}. This is like if/fi and for/rof. As well as being consistent it avoids some problems with matching blocks and also makes using semicolons more consistent. |
![]() |
![]() |
![]() |
#365 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,035
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Thanks. That'll be useful.
![]() New question: Code:
program: if $#fanficcat then 'Fanfiction' elif $#manualtype then 'Documentation & Manuals' else re(sublist($tags, 0, 1, ','), '^(.*?)($|\..*$)', '\1') fi It mostly works unless I have the [Cleanup] tag, which is always listed first and not in the enumerated list. Is there a way to do either of the following? 1. Tell it to skip to the next tag if it finds [Cleanup]. 2. Tell it to search for the first (foo|bar) tag, where the pattern matches the enumerated values. I suspect the latter would be a better option as I sometimes don't clean up bulk-imported tags first, so something like 'Animals' or 'Biography' would come up before Fiction|Nonfiction. Thanks. ![]() Last edited by ownedbycats; 03-28-2022 at 03:04 PM. |
![]() |
![]() |
Advert | |
|
![]() |
#366 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,450
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
If you mean "match any of a list of tags such as "Fiction|Nonfiction" then you can do that. Code:
program: if $#fanficcat then 'Fanfiction' elif $#manualtype then 'Documentation & Manuals' else t = list_intersection($tags, "Fiction, Nonfiction", ','); re(sublist(t, 0, 1, ','), '^(.*?)($|\..*$)', '\1') fi Code:
program: if $#fanficcat then 'Fanfiction' elif $#manualtype then 'Documentation & Manuals' else sublist(list_intersection(subitems($tags, 0, 1), "Fiction, Nonfiction", ','), 0, 1, ',') fi Last edited by chaley; 03-28-2022 at 05:02 PM. |
|
![]() |
![]() |
![]() |
#367 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,035
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Yes, I forgot to mention it was to get the first section of a hierarchical tag.
![]() ![]() |
![]() |
![]() |
![]() |
#368 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,035
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Question: I swapped a bool column to a psuedobool composite returning yes/no. This broke existing check_yes_nos. What's the best option to replace it?
$#column == 'Yes' is what I'm using for now. edit: I am curious as to whether check_yes_no could be extended to bool columns checking for specifically yes/true and no/false, similar to the checkmarks option. Probably too much effort tho. Last edited by ownedbycats; 04-10-2022 at 01:31 AM. |
![]() |
![]() |
![]() |
#369 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,450
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
The stored template: Code:
program: arguments(column, is_undefined, is_false, is_true); f = field(column); if is_undefined == 1 && !f then return 'yes' fi; if is_false == 1 && f == 'no' then return 'yes' fi; if is_true == 1 && f == 'yes'then return 'yes' fi Example use: Code:
program: my_check_yes_no('#mybool', 0, 0, 1) & ' - ' & $#mybool & '.' If you don't care about exact compatibility with the builtin check_yes_no() then you can pass the field value instead of the field name. Also you can use '1' and '' instead of '1' and '0', which would be a bit faster because it wouldn't need the '== 1' part of the test. |
|
![]() |
![]() |
![]() |
#370 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,035
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Thanks.
![]() |
![]() |
![]() |
![]() |
#371 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,450
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
|
![]() |
![]() |
![]() |
#372 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,035
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Would the latter one be a bit better for performance? $#kobostatus is enumerated.
Code:
program: if $#kobostatus=='[Send to Device]' then 'No' elif $#kobostatus then 'Yes' fi Code:
program: if $#kobostatus then if $#kobostatus == '[Send to Device]' then 'No' else 'Yes' fi fi Last edited by ownedbycats; 04-10-2022 at 10:11 PM. |
![]() |
![]() |
![]() |
#373 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,450
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
|
|
![]() |
![]() |
![]() |
#374 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,035
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Quick question: Is a days_between with the current date the only way to check "specified datetime column is more/less/equal to xx days ago" in a template?
If there isn't, I already am figuring out out a days_ago() stored template—though how would I set a variable to choose between ==#|<=#|>=#? Last edited by ownedbycats; 04-16-2022 at 07:57 AM. |
![]() |
![]() |
![]() |
#375 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,450
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
You can also do it with timestamps, using format_date(date, 'to_number') to get the timestamp. Get the timestamp for both dates and do the arithmetic. This lets you get down to differences of seconds. Example: Code:
program: def seconds_between(d1, d2): t1 = format_date(d1, 'to_number'); t2 = format_date(d2, 'to_number'); return t1 - t2 fed; def seconds_to_days(s): s / 86400 fed; s = seconds_between(today(), '20220101'); 'seconds: ' & s & ', days; ' & seconds_to_days(s) Code:
seconds: 9115307.01234293, days; 105.5012385687839 |
|
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Library Management: various questions not worth their own thread | ownedbycats | Library Management | 225 | 08-04-2025 06:31 PM |
[Metadata Source Plugin] Questions regarding parse select, docs and ref templates | Boilerplate4U | Development | 13 | 07-07-2020 02:35 AM |
Questions on Kobo [Interfered with another thread topic] | spdavies | Kobo Reader | 8 | 10-12-2014 11:37 AM |
[OLD Thread] Some questions before buying the fire. | darthreader13 | Kindle Fire | 7 | 05-10-2013 09:19 PM |
Thread management questions | meme | Feedback | 6 | 01-31-2011 05:07 PM |