[squeak-dev] UTCDateAndTime updated for Squeak trunk Chronology and Spur (was: UTCDateAndTime updated for Squeak 4.6/5.0)

David T. Lewis lewis at mail.msen.com
Fri Mar 25 15:51:41 UTC 2016


On Thu, Mar 24, 2016 at 10:05:17PM -0700, Eliot Miranda wrote:
> 
> 
> > On Mar 23, 2016, at 6:55 PM, David T. Lewis <lewis at mail.msen.com> wrote:
> > 
> >> On Wed, Mar 23, 2016 at 05:50:19PM -0700, Eliot Miranda wrote:
> >>> On Wed, Mar 23, 2016 at 4:51 PM, David T. Lewis <lewis at mail.msen.com> wrote:
> >>> 
> >>>> On Wed, Mar 23, 2016 at 04:22:21PM -0700, Eliot Miranda wrote:
> >>>> 
> >>>> Turns out this isn't needed for Cog.  I have ioLocalSecondsOffset which
> >>>> answers a value determined at start-up and only changed
> >>>> via ioUpdateVMTimezone, which itself is controlled by
> >>>> primitiveUpdateTimezone, #243.  So ioUTCMicroseconds is all that's needed
> >>>> to get at the clock and timezone atomically.
> >>> 
> >>> If it is updated at start-up, then it's wrong. Think of daylight savings
> >>> time transitions.
> >> 
> >> So update it automatically once a second or some such?
> > 
> > Are you joking, or is that a serious question?
> 
> Yes.  I see two or three system calls in the code below.  gettimeofday, one inside localtime and one inside gmtime.  That's expensive.
> 

It's gettimeofday() and localtime(). The #else is fallback for older unix platforms.

In any case, caching the value and updating it periodically does not sound like a good idea to me.

Dave


> > 
> > Confused,
> > Dave
> > 
> > 
> > /* implementation of ioUtcWithOffset(), defined in config.h to
> > /* override default definition in src/vm/interp.h
> > */
> > sqInt sqUnixUtcWithOffset(sqLong *microSeconds, int *offset)
> > {
> >  struct timeval timeval;
> >  if (gettimeofday(&timeval, NULL) == -1) return -1;
> >  time_t seconds= timeval.tv_sec;
> >  suseconds_t usec= timeval.tv_usec;
> >  *microSeconds= seconds * 1000000 + usec;
> > #if defined(HAVE_TM_GMTOFF)
> >  *offset= localtime(&seconds)->tm_gmtoff;
> > #else
> >  {
> >    struct tm *local= localtime(&seconds);
> >    struct tm *gmt= gmtime(&seconds);
> >    int d= local->tm_yday - gmt->tm_yday;
> >    int h= ((d < -1 ? 24 : 1 < d ? -24 : d * 24) + local->tm_hour - gmt->tm_hour);
> >    int m= h * 60 + local->tm_min - gmt->tm_min;
> >    *offset= m * 60;
> >  }
> > #endif
> >  return 0;
> > }
> > 
> > 
> > 


More information about the Squeak-dev mailing list