![]() |
#1 |
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 265
Karma: 724240
Join Date: Aug 2013
Device: KyBook
|
Formatting negative years
Hi,
If, like me, you have a separate year column for birth and death year of an author, you may have thought about formatting them so that negative years are displayed as positive number with 'BCE' as suffix. Problem is you'll lose the sorting order since 300 BCE will still show below 290 AD. So I have an extra custom column built from these two year fields and do the formatting in there so I can still sort on the numeric year counterparts Since I couldn't find a simple way with the template functions I created my own and in case it might be of use here it is. Preferences -> Advanced -> Template Functions and paste in this name: negative arg count:1 documentation: strip minus from negative years and return suffixed with 'BCE' Code:
def evaluate(self, formatter, kwargs, mi, locals, val): if len(val) == 0: return '' if val[0] == '-': pos = val[1:] return '%s BCE' % (pos) else: return '%s' % (val) the template for the column built from the birth/death years (plus 2 letter country code) then has this as template Code:
program: a = test(field('#born'),negative(field('#born')) , ""); b = test(field('#died'), strcat(" - ", negative(field('#died'))), ""); c = test(field('#country'), strcat( " (", field('#country'), ")") , ""); strcat(a,b ,c ); output looks something like this: 348 BCE - 297 BCE (GR) Last edited by At_Libitum; 10-19-2013 at 09:12 PM. |
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Using negative margins | Agama | Conversion | 0 | 03-03-2012 07:29 AM |
Negative publicity | dworth | Writers' Corner | 29 | 09-23-2010 01:59 PM |