[squeak-dev] Time now print24

Chris Muller asqueaker at gmail.com
Thu Jul 7 21:12:04 UTC 2016


Hi Eliot, wanted the exact same thing, a short terse representation so
I made one that employs "present context" -- e.g., if it is same day as
today, just print the time, otherwise include both the Date and Time.
This should be extended so if it is outside the current year, then it
should include the year, otherwise not.

Here's the old method, which could use a update, since #makeUTC is no
longer necessary either..

printAbbreviatedOn: aStream
    | date |
    (date := self asDate) makeUTC = Date today
        ifTrue:
            [ self asTime
                print24: false
                showSeconds: false
                on: aStream ]
        ifFalse:
            [ aStream
                 maPrint: ((date printFormat: #(2 1 3 $/ 1 2 1 ))
copyUpToLast: $/) ;
                 maPrint: $@.
            self asTime
                print24: false
                showSeconds: false
                on: aStream ]

Another approach -- you could also play around with
DateAndTime>>#printYMDOn:.

On Thu, Jul 7, 2016 at 11:33 AM, Eliot Miranda <eliot.miranda at gmail.com> wrote:
> Hi All,
>
>     how does one produce a nice timestamp, simply date and time as in
>
>     7/7/2016 09:19:38
>
> 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
>
>
>


More information about the Squeak-dev mailing list