ceylon-sdk icon indicating copy to clipboard operation
ceylon-sdk copied to clipboard

datestamp() function

Open gavinking opened this issue 8 years ago • 6 comments

Currently ceylon.time can produce ISO timestamps. I would also like to have a convenience function for rendering "date stamps", of form 20161102.

@DiegoCoronel @luolong WDYT?

gavinking avatar Dec 03 '16 11:12 gavinking

parseDate not good enough?

luolong avatar Apr 21 '17 14:04 luolong

or do you mean the other way around — that would be Date.string, I guess...

luolong avatar Apr 21 '17 14:04 luolong

Nope, it uses this format:

"Returns ISO-8601 formatted String representation of this date.\n
 Reference: https://en.wikipedia.org/wiki/ISO_8601#Dates"
shared actual String string 
        => "``year.string.padLeading(4, '0')``-``month.integer.string.padLeading(2, '0')``-``day.string.padLeading(2, '0')``";

I want, literally: 20161102.

gavinking avatar Apr 21 '17 14:04 gavinking

Well, the trouble here is that all those *.string methods are currently returning similarly formatted output across the board.

Date.string returns yyyy-mm-dd, Time.string returns hh:mm:ss, DateTime.string returns Date.string + 'T' + Time.string and Instant (the timestamp) simply returns ZoneDateTime.string at UTC.

I suppose the correct way to approach this would be to put those specific formats into ceylon.formatter module.

luolong avatar Apr 21 '17 21:04 luolong

On the other hand, the YYMMDD and HHmmss formats are also valid ISO representations. so it would be relatively easy to change default output to the shorter variant.

I personally dislike those though. They are useful at times, but I prefer to keep the variants with dashes and colons as default textual representation.

luolong avatar Apr 21 '17 21:04 luolong

Well, the trouble here is that all those *.string methods are currently returning similarly formatted output across the board.

And I think that's perfectly fine. I don't want to change that.

But the shorter YYMMDD and HHmmss formats are also sometimes useful, and I think we should have convenience functions (or attributes, perhaps) for generating them.

gavinking avatar Apr 22 '17 07:04 gavinking