I like the idea of Go to have a separate date-printer.
Stef
Le 8/7/16 à 11:23, Sven Van Caekenberghe a écrit :
On 08 Jul 2016, at 10:49, Tobias Pape <das.li...@gmx.de> wrote:
On 07.07.2016, at 18:33, Eliot Miranda <eliot.mira...@gmail.com> wrote:
Hi All,
how does one produce a nice timestamp, simply date and time as in
7/7/2016 09:19:38
What's with 'TimeStamp now' (prints '8 July 2016 10:34:36 am')
or this one:
TimeStamp now in: [:t |
String streamContents: [:s |
t asDate printOn: s format: #(2 1 3 $/ 1 1 2).
s space.
t asTime print24: true showSeconds: true on: s]]
Too bad TimeStamp is deprecated in Pharo4, so this works in pharo:
Yes, it is gone. It was a subclass whose only feature was a different print
representation. It was also confusing, why choose it or DateAndTime.
We folded TimeStamp's functionality into DateAndTime (see
#printSeparateDateAndTimeOn: and #readSeparateDateAndTimeFrom:)
DateAndTime now rounded in: [:t |
String streamContents: [:s |
t asDate printOn: s format: #(2 1 3 $/ 1 1 2).
s space.
t asTime print24: true showSeconds: true on: s]]
But DateAndTime knows no #rounded in Squeak, buuut:
=======================
This works for both:
DateAndTime now in: [:t |
String streamContents: [:s |
t asDate printOn: s format: #(2 1 3 $/ 1 1 2).
s space.
t printHMSOn: s]]
=====
Best regards
-Tobias
PS: I'd prefer ISO, nonetheless: https://xkcd.com/1179/
Yes, that was my point exactly. Thanks for the cool link!
In the same line, the AM/PM don't make sense, and the timezone (or Z) is
required.
https://en.wikipedia.org/wiki/ISO_8601
Something like 2016-07-08 08:41:52 Z or 2016-07-08 08:41:52 +00:00 is perfectly
readable.
BTW, these are unambigiously parseable as well (for example, using ZTimestamp).
ZTimestamp readFromString: '2016-07-08 08:41:52 Z'.
"2016-07-08T08:41:52Z"
ZTimestamp readFromString: '2016-07-08 08:41:52 +00:00'.
"2016-07-08T08:41:52Z"
Using ZTimestampFormat, which is an example based formatter/parser, like Go's,
you can easily produce this slightly more human friendly format.
(ZTimestampFormat fromString: '2001-02-03 16:05:06 +00:00') format: DateAndTime
now.
"'2016-07-08 11:16:54 +02:00'"
And the reverse (obviously you share/predefine/cache the specific format
object).
(ZTimestampFormat fromString: '2001-02-03 16:05:06 +00:00') createDateAndTime;
parse: '2016-07-08 11:16:54 +02:00'.
"2016-07-08T11:16:54+02:00"
(or the German way: 25.12.2015 :P)
Trivial, right?
So
Date today mmddyyyy, ' ', Time now print24 '7/7/2016 09:22:40.914'
.914, ah, nanos. How useful. Let's get rid of them. No nanos: accessor so
Date today mmddyyyy, ' ', (Time now nanos: 0) print24 => MNU
but there's a seconds accessor, so
Date today mmddyyyy, ' ', (Time now seconds: Time now seconds; print24)
'7/7/2016 00:00:41
?? So seconds: is private, and isn't the dual of Time seconds:
Time seconds
^ self second
Time second
^ self asDuration seconds
Duration seconds
"Answer the number of seconds the receiver represents."
^seconds rem: SecondsInMinute
Looks broken to me.
Personally I think print24 should not print sub seconds.
cc'ing to Pharo because I want this timestamp to be the same in both dialects
for a profiling tool we want to use in both dialects.
_,,,^..^,,,_
best, Eliot