Dec 29, 2015; 10:50
Jolle Carlestam
The date -> format year trap
There’s a quirk in Lasso 9 date formatting that can bite you on rare occasions if you’re using the modern style Lasso 9 date format symbols. Especially likely to happen for us that also write javascript. I got reminded of this since Rick asked me about it earlier today.
In javascript a proper ISO date formatting would be `YYYY-MM-DD`. If we use the same in Lasso things will go wrong. But, and that’s the trap, not on every call.
Check the following example:
date('2015-01-01') -> format(`YYYY`)
'<br>'
date('2016-01-01') -> format(`YYYY`)
->
2015
2015
Not what you expected huh? The cause is found in the docs:
http://lassoguide.com/operations/date-duration.html
The list of ICU Date Formatting Symbols tells that
y = year
whereas
Y = year of “Week of Year”
I honestly have little idea of what “Week of Year” means. But I know the result. Sometimes dates around the end of one year and the beginning of next will be displayed wrong when using YYYY as format.
The correct, and safe, way of formatting an ISO date in Lasso is:
`yyyy-MM-dd`
Yes, lower case yyyy for full year and dd for day of month. Upper case MM for month.
You can’t go all lower case (too simple) since that will display minute of hour instead of month.
Now, you might think that it would be safer and better to use Lassos old style formatting symbols. Like %Y to display the year. And, yes, that is possible. But it also slows Lasso down. As soon as Lasso discovers old style formatting it will parse the formatting string in a cumbersome way and convert old style to the proper ICU symbols. A small but measurable slowdown.
One last tidbit tip. Notice I use backticks to enclose the formatting symbols? That’s a good habit since it’s the easiest way to also include litteral strings in your date output.
Examples:
date -> format(`d MMM yyyy eeee ’W' ww`)
date -> format(`yyyyMMdd'T'HHmmss'Z’`)
Enjoy your new year with a safe date formatting!
HDB
Jolle
#############################################################
This message is sent to you because you are subscribed to
the mailing list Lasso Lasso@lists.lassosoft.com
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <Lasso-unsubscribe@lists.lassosoft.com>
Send administrative queries to <Lasso-request@lists.lassosoft.com>
Dec 29, 2015; 10:23
Douglas Burchard
Re: The date -> format year trap
Dec 30, 2015; 13:41
Johan Solve
Re: The date -> format year trap
Dec 31, 2015; 12:08
Jolle Carlestam
Re: The date -> format year trap