Page 1 of 1

Wrong times on E-Mails?

Posted: Mon Nov 05, 2018 4:55 pm
by pthien
I'm using the 32-bit 5.46 LTS version.

I wrote a Windows monitoring app (watches event viewer events and backup jobs) which sends an E-Mail every day at approx. 9am. It was working fine until the DST shift yesterday.

Now in Thunderbird, the E-Mails are showing as 8am. Looking at the mail header, I see this:

**********
for <phil@removed.com>; Mon, 05 Nov 2018 08:36:14 -0700
Delivery-date: Mon, 05 Nov 2018 08:36:14 -0700
for phil@removed.com; Mon, 05 Nov 2018 08:36:14 -0700
From: notify@removed.com
Subject: M910X event notification
To: phil@removed.com
Date: Mon, 5 Nov 2018 09:36:10 -0500
MIME-Version: 1.0
Content-Type: multipart/mixed;
**********

I think the problem is that it is showing (in the bolded line) that my time zone is -0500, whereas my actual time zone (US CST, I'm in Milwaukee) is -0600.

Any ideas?

Every single machine on which I have this running (approx. 23) is doing the exact same thing. And to the best of my knowledge, there are no other time issues on these machines. Like on my own personal machine, I can send an E-Mail through Thunderbird to myself, and it will show the proper time in my inbox. If I use my app on my exact same machine to generate an E-Mail, it will show minute one hour.

TIA for any help.

Re: Wrong times on E-Mails?

Posted: Mon Nov 05, 2018 8:58 pm
by idle
try this

Code: Select all

Structure tm
   tm_sec.l;   // seconds after the minute - [0, 60] including leap second
   tm_min.l;   // minutes after the hour - [0, 59]
   tm_hour.l;  // hours since midnight - [0, 23]
   tm_mday.l;  // day of the month - [1, 31]
   tm_mon.l;   // months since January - [0, 11]
   tm_year.l;  // years since 1900
   tm_wday.l;  // days since Sunday - [0, 6]
   tm_yday.l;  // days since January 1 - [0, 365]
   tm_isdst.l; // daylight savings time flag
 EndStructure 
 
 ImportC "" 
   time(*tm)
   gmtime(*tm) 
 EndImport  

Procedure.s LocalDate(in)
   Protected *time.tm,date.s,day.s  
   
   *time = gmtime(@in) 
      
   Select *time\tm_wday 
     Case 0 
       day = "Sun"
     Case 1 
       day = "Mon"
     Case 2 
       day = "Tue" 
     Case 3 
       day = "Wed"
     Case 4 
       day = "Thu" 
     Case 5 
       day = "Fri" 
     Case 6 
       day = "Sat" 
   EndSelect     
   
    date + Day + "," + RSet(Str(*time\tm_mday),2,"0") + "/" + RSet(Str(1 + *time\tm_mon),2,"0") + "/" + Str(1900 + *time\tm_year) + "," + RSet(Str(*time\tm_hour),2,"0") + ":" + RSet(Str(*time\tm_min),2,"0")
    ProcedureReturn date 
  EndProcedure  
  
  Debug LocalDate(Date()) 

Re: Wrong times on E-Mails?

Posted: Mon Nov 05, 2018 10:54 pm
by pthien
Thank you.

So it seems I have to set the #PB_Mail_Date attribute to UTC +0000

Pretty much copied that code, but looking at the E-Mail format of stuff that was sent, I discovered I needed the name of the month too. Not sure if it is needed, but that seems to be what clients are sending.

SO... I used that code but for the name of the day and name of the month, I re-wrote that as this:

Code: Select all

Procedure.s GetDay(value)
   ProcedureReturn(StringField("Sun,Mon,Tue,Wed,Thu,Fri,Sat",value+1,","))
EndProcedure

Procedure.s GetMonth(value)
   ProcedureReturn(StringField("Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec",value+1,","))
EndProcedure
... to reduce lines and improve readability a little.

So far it seems to work, but I'm not sure about Month and Day abbreviations, I'll have to dig into that a little. Are they always the first three letters?

Re: Wrong times on E-Mails?

Posted: Tue Nov 06, 2018 12:30 am
by idle
this format?

Code: Select all

Structure tm
   tm_sec.l;   // seconds after the minute - [0, 60] including leap second
   tm_min.l;   // minutes after the hour - [0, 59]
   tm_hour.l;  // hours since midnight - [0, 23]
   tm_mday.l;  // day of the month - [1, 31]
   tm_mon.l;   // months since January - [0, 11]
   tm_year.l;  // years since 1900
   tm_wday.l;  // days since Sunday - [0, 6]
   tm_yday.l;  // days since January 1 - [0, 365]
   tm_isdst.l; // daylight savings time flag
 EndStructure 
 
 ImportC "" 
   time(*tm = #Null)
   gmtime(*tm) 
 EndImport  

Procedure.s LocalDate()
   Protected t,*time.tm,date.s,day.s,month.s,z,zone.s    
   t = Date()
   *time = gmtime(@t) 
   day = StringField("Sun,Mon,Tue,Wed,Thu,Fri,Sat",*time\tm_wday+1,",")
   month = StringField("Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec",*time\tm_mon+1,",")
   z = (t - time()) / 3600 
   If z > 0 
     zone = "+" + LSet(Str(z),4,"0")
   Else 
     zone = "-" + LSet(Str(z),4,"0")
   EndIf 
   date + Day + ", " + RSet(Str(*time\tm_mday),2,"0") + " " + month + " " + Str(1900 + *time\tm_year) + ", " + RSet(Str(*time\tm_hour),2,"0") + ":" + RSet(Str(*time\tm_min),2,"0") + ":" + RSet(Str(*time\tm_sec),2,"0") + " " + zone 
   ProcedureReturn date 
  EndProcedure  
  
  Debug LocalDate()

Re: Wrong times on E-Mails?

Posted: Tue Nov 06, 2018 2:40 am
by pthien
I think that is nearly what I've got.

From this:
https://www.lifewire.com/how-to-underst ... rs-1170524

I found this example:
Sat, 24 Nov 2035 11:45:15 −0500

And I've looked through a bunch of E-Mail I've received and I see some of the senders are just using UTC, I think that is what I'm going to do.

So my date looks like this:
Tue, 6 Nov 2018 01:30:42 +0000

And when it shows up in my Inbox, it has the correct date/time.

I really appreciate all your help!!!