| 
 | |||||||
|  | 
|  | Thread Tools | Search this Thread | 
|  10-12-2020, 05: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, 06:37 AM | #2 | |
| Grand Sorcerer            Posts: 12,525 Karma: 8065948 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 06:44 AM. Reason: Added example universe specifiers | |
|   |   | 
|  10-12-2020, 07:52 AM | #3 | 
| Grand Sorcerer            Posts: 12,525 Karma: 8065948 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, 03: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, 04:45 PM | #5 | |
| Grand Sorcerer            Posts: 12,525 Karma: 8065948 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 04:55 PM. | |
|   |   | 
|  10-13-2020, 05:15 AM | #6 | 
| Grand Sorcerer            Posts: 12,525 Karma: 8065948 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 | 
| Thread Tools | Search this Thread | 
| 
 | 
|  Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post | 
| Integer Column | Quetico | Reading and Management | 0 | 07-09-2017 11:27 PM | 
| Method to set Date from user integer column | macnab69 | Library Management | 9 | 07-07-2013 07:52 AM | 
| Rounding to nearest integer in Custom Column - Hijri Year | oelgamal | Calibre | 2 | 03-28-2013 07:12 PM | 
| Rounding to nearest integer in Custom Column - Hijri Year | oelgamal | Recipes | 0 | 03-28-2013 02:58 AM | 
| positive/negative experience with onyx support? | Clark G. Flipper | Onyx Boox | 69 | 03-19-2012 11:23 AM |