View Single Post
Old 10-19-2013, 09:09 PM   #1
At_Libitum
Addict
At_Libitum ought to be getting tired of karma fortunes by now.At_Libitum ought to be getting tired of karma fortunes by now.At_Libitum ought to be getting tired of karma fortunes by now.At_Libitum ought to be getting tired of karma fortunes by now.At_Libitum ought to be getting tired of karma fortunes by now.At_Libitum ought to be getting tired of karma fortunes by now.At_Libitum ought to be getting tired of karma fortunes by now.At_Libitum ought to be getting tired of karma fortunes by now.At_Libitum ought to be getting tired of karma fortunes by now.At_Libitum ought to be getting tired of karma fortunes by now.At_Libitum ought to be getting tired of karma fortunes by now.
 
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)
turns -348 into 348 BCE

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 );
"negative" is the name I gave to the template function.

output looks something like this: 348 BCE - 297 BCE (GR)

Last edited by At_Libitum; 10-19-2013 at 09:12 PM.
At_Libitum is offline   Reply With Quote