Last year Jake published a really good article (as he generally does) about how to create Ruby style dates in LotusScript. So for example, instead of displaying “28/06/2009 09:35” the page will show “about 30 minutes ago”.
It’s a technique I bookmarked until I had a need for it, which I now have, but for an XPages app. So I have ported Jakes code across to use Server Side Javascript instead of LotusScript, and in “share and share alike” fashion, thought I should republish it for you to use as you see fit.
So you can download the code here: xpDates.jss
Please let me know if you spot any bugs.
An interesting side note is, that if you compare Jakes LotusScript and my server side Javascript, you can see just how easy it is to port code from one syntax to the other. So if you’re just starting out in XPages development and are worried about losing all of your existing LotusScript agents, there really is no need to. You can spend (an admittedly boring) few hours reformatting and not lose any of your existing code at all.
It may not suit all cases, but for the majority of code it’s easier than starting from scratch.
Nice work Matt. Thanks for the nod.
This all makes me realise how backwards I am right now. Must start using XPages….
I wonder how easy it would be to turn this into a ‘converter’ for field values rather then a function to call.
Actually very easy…
Removed the function prototyping so that is it just a plain script and set the dt_then as follows :
dt_then = session.createDateTime(value);
‘value’ is what is passed into the converter. I set the include Seconds as true directly in the script. and bingo, works great.
Good stuff Dec, that’s probably an easier way of using the code.
Thank you for sharing!