[Glass] Kind of _asDaysFrom1970 that answers negative numbers?

Richard Sargent via Glass glass at lists.gemtalksystems.com
Thu Feb 23 13:37:25 PST 2017


#julianDay is also a primitive. Couple it with a pre-computed Julian day
for January 1, 1970. The subtraction is also fast.

(Date newDay: 1 year: 1960) julianDay - (Date newDay: 1 year: 1970)
julianDay

-3653


Unless this date conversion is THE bottleneck in your system, you are
wasting time on unnecessary optimizations. Remember the rule "measure
first, then optimize" (coupled with "micro-optimizations are usually as
useful as micro-benchmarks").



On Thu, Feb 23, 2017 at 3:30 PM, Mariano Martinez Peck via Glass <
glass at lists.gemtalksystems.com> wrote:

> Hi guys,
>
> I am using  _asDaysFrom1970 to convert Smalltalk dates to Javascript dates
> that I pass via JSON (as milliseconds since 1907 epoch) to a chart library.
>
> The problem is that I need this even for dates before 1970. I checked that:
>
> 1) JS can accept this:
>
> new Date(-100000000)
> ->  Tue Dec 30 1969 17:13:20 GMT-0300 (ART)
>
> 2) The chart lib  I use, I can also specify this:
>
>    data: [
>             [-1394104654000, 42],
>         ]
>
>
> So... my remaining problem is that I would like a primitive-based (for
> performance) like _asDaysFrom1970 but that knows how to answer negative
> numbers for those dates prior to 1970.
>
> Do we have already something like this? Could this be added?
>
> Below is the method in question.
>
> Thanks in advance,
>
> Best regards.
>
>
> ---------------------
>
>
> _asDaysFrom1970
>   "Convert the receiver to a SmallInteger representing the number of days
> since
> January 1, 1970."
>
>   "Primitive does not support instances which represent a date before
> 1970."
>
>   <primitive: 540>
>   ^ self _primitiveFailed: #'_asDaysFrom1970'
>
>
>
>
> --
> Mariano
> http://marianopeck.wordpress.com
>
> _______________________________________________
> Glass mailing list
> Glass at lists.gemtalksystems.com
> http://lists.gemtalksystems.com/mailman/listinfo/glass
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gemtalksystems.com/mailman/private/glass/attachments/20170223/ad417dbd/attachment.html>


More information about the Glass mailing list