nmh-workers
[Top] [All Lists]

Re: displaying Date using local timezone

2021-03-17 02:12:21
On Tue, 16 Mar 2021 18:38:11 -0400 Ken Hornstein <kenh@pobox.com> sez:

Oh, sure.  I guess I was thinking of a more robust solution, that
wouldn't require editing that line when my timezone changes twice a
year.  :-)

Boy, EVERYONE's a critic :-)

You could use the %(dst) function to do the appropriate
branching; you might need to duplicate a fair amount of the
format instructions, though.  But ... maybe not.

%<(dst{text})%(void(zone{text}))%(void(ne 
-300))%|%(void(zone{text}))%(void(ne -240))%>

I mean, substitute the correct values for -300 and -240.  I
think that should set num to 1 or 0 depending if the timezone
is equivalent to your local timezone, and then you can go from
there.

I think ... aside from that, we'd need a new format instruction
that tests if a particular timestamp is in your local timezone.
Related question:  HOW do we determine that?  I guess what nmh
does is conver the time to a time_t, and then calls localtime()
on it.  If the timezone offsets don't match, then it's not
local.

I understand what you're trying to do; but it's kind of
limiting with the format language since you only have two
variables and comparisons have to be done against literal
values.

I ... MAY ... be able to finally contribute on this list.  B-)

If the problem is that you're trying to account for the two
Daylight Saving Time changeovers each year, then you don't
actually need to use (dst).

This thread and Ken's suggestion tempted me to fiddle with this
stuff, and I found that (zone) provides you your "standard time"
UTC offset (in minutes), regardless of (dst)'s result.  So, this,
grabbed from my mhl.format file, or something like it might
suffice for you:

     %(void(zone{text}))%<(eq -480)\
      (%(date2local{text})%04(year{text})-%02(mon{text})-%02(mday{text})\
      %02(hour{text}):%02(min{text}):%02(sec{text}))%>

The "-480" bit is because my timezone is US Pacific.  As long as
the Date: header's timezone is the equivalent of PST or PDT, it
Just Works (TM).  Examples follow, using last Sunday morning's
DST switchover moment.

     *  These are all PST or PDT (should produce text):

        % fmttest -format '%(void(zone{text}))%<(eq -480) 
(%(date2local{text})%04(year{text})-%02(mon{text})-%02(mday{text}) 
%02(hour{text}):%02(min{text}):%02(sec{text}))%>' -raw 'Date: Sun, 14 Mar 2021 
01:59:59 -0800'
         (2021-03-14 01:59:59)
        % fmttest -format '%(void(zone{text}))%<(eq -480) 
(%(date2local{text})%04(year{text})-%02(mon{text})-%02(mday{text}) 
%02(hour{text}):%02(min{text}):%02(sec{text}))%>' -raw 'Date: Sun, 14 Mar 2021 
03:00:00 -0700'
         (2021-03-14 03:00:00)
        %

     *  These are not PST or PDT (should produce nothing):

        % fmttest -format '%(void(zone{text}))%<(eq -480) 
(%(date2local{text})%04(year{text})-%02(mon{text})-%02(mday{text}) 
%02(hour{text}):%02(min{text}):%02(sec{text}))%>' -raw 'Date: Sun, 14 Mar 2021 
01:59:59 -0700'
        % fmttest -format '%(void(zone{text}))%<(eq -480) 
(%(date2local{text})%04(year{text})-%02(mon{text})-%02(mday{text}) 
%02(hour{text}):%02(min{text}):%02(sec{text}))%>' -raw 'Date: Sun, 14 Mar 2021 
03:00:00 -0800'
        % fmttest -format '%(void(zone{text}))%<(eq -480) 
(%(date2local{text})%04(year{text})-%02(mon{text})-%02(mday{text}) 
%02(hour{text}):%02(min{text}):%02(sec{text}))%>' -raw 'Date: Sun, 14 Mar 2021 
02:00:00 -0800'
        %

As Ken mentioned before, just edit the number in the equality
check (the "eq -480" part) to be your timezone's # of minutes
away from UTC during "standard time."

Bonus:  no need to duplicate formatting instruction!  B-)

Hope that helps!

                                Bob

<Prev in Thread] Current Thread [Next in Thread>