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' _______________________________________________ Glass mailing list [hidden email] http://lists.gemtalksystems.com/mailman/listinfo/glass |
#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
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 <[hidden email]> wrote:
_______________________________________________ Glass mailing list [hidden email] http://lists.gemtalksystems.com/mailman/listinfo/glass |
On Thu, Feb 23, 2017 at 6:37 PM, Richard Sargent <[hidden email]> wrote:
Hi Richard, Yes, I got up to this far on this method as a result of ProfMonitor. I was using the same code for calculating this I was using on Pharo and that was very slow. Then I found the _asDaysFrom1970 and that was fast. I just tried your idea, and indeed it looks as fast as the one with the primitive. That tells me the speedup was not because of the primitive but that in fact I was doing something very slow on my old implementation (the one I had for Pharo). Thank you very much! Why this is a bottleneck for me? Well... the long short story is that I have some financial reports where the user may have N number of charts. Say... 8 charts average. Each chart may have M numbers of series. Say... 5. These series could be "price-related" series from which we have companies that go back up to 1930. Not only prices but also some other financial data (indexes etc) that also go way beyond 1970. All these series are then answered via JSON to the chart library. And there is where I convert the dates to miliseconds since epoch. Of course, we have things to provide "less resolution" for chats instead of the super daily/hourly resolution etc etc. But that's an story for a different day. Thanks Richard,
_______________________________________________ Glass mailing list [hidden email] http://lists.gemtalksystems.com/mailman/listinfo/glass |
Free forum by Nabble | Edit this page |