|
|
Thread Tools | Search this Thread |
10-12-2020, 06:40 AM | #1 |
Junior Member
Posts: 5
Karma: 10
Join Date: Mar 2012
Device: Android
|
Customize the positive and negative number format on an integer column
I posted this as a Calibre feature request here, but I'm beginning to wonder if it's possible to do already.
Basically, I'd like to have a column for in-universe dating systems. Eg. Star Wars uses "[year] BBY" or "[year] ABY" for dating events, similar to how we have BC and AD (or BCE and ACE if you prefer) on our years. I think the solution would have to involve 3 custom columns:
I may be overthinking this, I admit, but can anyone point me in the right direction here? |
10-12-2020, 07:37 AM | #2 | |
Grand Sorcerer
Posts: 12,029
Karma: 7257323
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
I would make three custom columns:
Code:
program: universe = field('#text'); year = raw_field('#myint'); first_non_empty( if universe == 'Star Wars' then if year < 0 then strcat(floor(multiply(year, -1)), ' BBY') else strcat(year, ' ABY') fi fi, if universe == 'Dune' then if year < 0 then strcat(floor(multiply(year, -1)), ' BG') else strcat(year, ' AG') fi fi ) This screen capture shows the result. Alternatively, and just for fun, it can be made more readable using the new stored template feature. I first define a stored template called 'universe_year' that formats the year: Code:
program: arguments(year, lt, gt); if year < 0 then strcat(floor(multiply(year, -1)), ' ', lt) else strcat(year, ' ', gt) fi Code:
program: universe = field('#text'); year = raw_field('#myint'); first_non_empty( if universe == 'Star Wars' then universe_year(year, 'BBY', 'ABY') fi, if universe == 'Dune' then universe_year(year, 'BG', 'AG') fi) Last edited by chaley; 10-12-2020 at 07:44 AM. Reason: Added example universe specifiers |
|
10-12-2020, 08:52 AM | #3 |
Grand Sorcerer
Posts: 12,029
Karma: 7257323
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
And for more fun, an equivalent but more compact template that uses the stored template:
Code:
program: universe = field('#text'); year = raw_field('#myint'); first_non_empty( test(universe == 'Star Wars', universe_year(year, 'BBY', 'ABY'), ''), test(universe == 'Dune', universe_year(year, 'BG', 'AG'), ''), 'Unknown Universe' ) |
10-12-2020, 04:49 PM | #4 |
Junior Member
Posts: 5
Karma: 10
Join Date: Mar 2012
Device: Android
|
Ooh, that looks perfect!
I tried to implement it, but I've not messed around with Calibre templates before. How do I put multi-line template code into the single-line input field when editing a custom column? Or am I barking up the wrong preferences panel? |
10-12-2020, 05:45 PM | #5 | |
Grand Sorcerer
Posts: 12,029
Karma: 7257323
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
As for your question: copy the template and paste it into the line. Go through the process and create the column. You can then select the column in the library view, press F2 to edit it, and be presented with the full template editor. Last edited by chaley; 10-12-2020 at 05:55 PM. |
|
10-13-2020, 06:15 AM | #6 |
Grand Sorcerer
Posts: 12,029
Karma: 7257323
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Starting with the next release, when creating/editing "columns built from other columns" you can right-click on the template box and open the full template editor.
|
Tags |
chronological order, custom columns, year |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Integer Column | Quetico | Reading and Management | 0 | 07-10-2017 12:27 AM |
Method to set Date from user integer column | macnab69 | Library Management | 9 | 07-07-2013 08:52 AM |
Rounding to nearest integer in Custom Column - Hijri Year | oelgamal | Calibre | 2 | 03-28-2013 08:12 PM |
Rounding to nearest integer in Custom Column - Hijri Year | oelgamal | Recipes | 0 | 03-28-2013 03:58 AM |
positive/negative experience with onyx support? | Clark G. Flipper | Onyx Boox | 69 | 03-19-2012 12:23 PM |