× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



With most approaches, if the times are not converted to UTC time immediately, it is virtually impossible to account for the 1am-2am Fallback repeated hour.
That is because the Time would have to know if DST was active or Inactive. Which requires more information that in saved in the default timestamp.

If the Timestamp was converted to UTC time and that is the time being converted, then you can always convert back to the Time zone and know if you are were before DST change or after DST change.

If you have a UTC time you can then use QWCCVTDT and it will return the "Current Daylight Savings Time Indicator" for the time zone you are converting to.


Use WRKTIMZON to see all the time zones on your system.

When you know what time zone you are in, then you can use QWCCVTDT to convert from that time to the UTC time zone.

If converting old timestamps you can check the date against when the time zone entry was effective.
For the United States, I'd suggest checking out the History of Time on Wikipedia.

Here is an example to convert from the current version of Mountain time to UTC time.
NewTimestamp = AdjustTimestamp( RecordTimestamp : 'QN0700MST3' : 'Q0000UTC');

// An example of DST before 2006.
If %subdt(RecordTimestamp:*YEARS) < 2006 and %subdt(RecordTimestamp:*YEARS) >= 1987;
NewTimestamp = AdjustTimestamp( RecordTimestamp : 'QN0700MST' : 'Q0000UTC');
Endif;


Dcl-Proc AdjustTimestamp Export;
Dcl-Pi *N Timestamp;
parmInputTS Timestamp Const;
parmInputTZ Char(10) Const;
parmOutputTZ Char(10) Const;
End-Pi;

Dcl-Pr CvtDateTimeFmt ExtPgm('QWCCVTDT');
InputFormat Char(10) Const;
InputTS Const LikeDS(dsDateStruc);
OutputFormat Char(10) Const;
OutputTS LikeDS(dsDateStruc);
dsErrCode LikeDS(dsErrCode);
InputTZ Char(10) Const;
OutputTZ Char(10) Const;
TimeZoneInfo LikeDs(dsTimeZone);
TimeZoneInfoL Int(10) Const;
PrecisionInd Char(1) Const;
End-Pr;

Dcl-Ds dsErrCode Qualified;
BytesProvided Int(10) Inz(%Size(dsErrCode.MsgData));
BytesAvail Int(10);
ExceptionID Char(7);
Reserved Char(1);
MsgData Char(128);
End-Ds;

Dcl-Ds dsDateStruc Qualified;
Date Zoned(8);
Time Zoned(6);
MilliSec Zoned(6);
End-Ds;

Dcl-Ds InputStruc LikeDS(dsDateStruc) Inz;
Dcl-Ds OutputStruc LikeDS(dsDateStruc) Inz;

Dcl-Ds dsTimeZone Qualified;
BytesReturned Int(10);
BytesAvailable Int(10);
TimeZoneName Char(10);
Reserved1 Char(1);
DaylightSaving Char(1);
CurOffset Int(10);
CurFullName Char(50);
CurAbbrName Char(50);
MsgFile Char(10);
MsgFileLib Char(10);
End-Ds;

Dcl-S WrkTimeStamp Char(26);
InputStruc.Date=%Dec(%Date(parmInputTS):*ISO);
InputStruc.Time=%Dec(%Time(parmInputTS):*ISO);
InputStruc.MilliSec=%SubDt(parmInputTS:*MS);
CvtDateTimeFmt('*YYMD':
InputStruc:
'*YYMD':
OutputStruc:
dsErrCode:
parmInputTZ:
parmOutputTZ:
dsTimeZone:
%Size(dsTimeZone):
(InputStruc.MilliSec>0));
WrkTimeStamp=%Char(%Date(OutputStruc.Date:*ISO):*ISO)+'-'+
%Char(%Time(OutputStruc.Time:*ISO):*ISO)+'.'+
%EditC(OutputStruc.MilliSec:'X');
Return %TimeStamp(WrkTimeStamp);
Begsr *Pssr;
Return *Loval;
Endsr;
End-Proc;


When Dealing with the Current Time you can use something like this to generate the Unix Timestamp representation.
CEEUTCO gets the current system offset amount and can be used to convert a timestamp to the current unix time.
This does not work for prior timestamps which would need to know the status of daily savings time.

Dcl-Proc TimestampToUnix;
Dcl-Pi *n Int(10);
pTime timestamp Const;
End-pi;

Dcl-pr CEEUTCO;
hours INT(10);
minutes INT(10);
seconds FLOAT(8);
fb Char(16) Options(*Omit);
End-pr;
Dcl-S Epoch Timestamp Inz(Z'1970-01-01-00.00.00');

DCL-S hours INT(10);
DCL-S mins INT(10);
DCL-S FSecs FLOAT(8);
Dcl-s wkTime Int(10);
Dcl-s Fc Char(16);

// Get timezone offset amount.
CEEUTCO(hours: mins: FSecs : Fc);

Monitor;
// Convert from time
Wktime = %Diff( pTime : Epoch : *S );
// Apply the timezone offset (-43200< < +46800)
wkTime = Wktime - Fsecs;
On-error;
wkTime = *Loval;
Endmon;
Return wkTime;
End-proc;




Now, if you used AdjustTimestamp from above to generate the UTC timestamp you could then use this procedure to generate the Unix value:

Dcl-Proc UtcTimestampToUnix;
Dcl-Pi *n Int(10);
pTime timestamp Const;
End-pi;
Dcl-S Epoch Timestamp Inz(Z'1970-01-01-00.00.00');
Dcl-s wkTime Int(10);
Monitor;
// Convert from time
Wktime = %Diff( pTime : Epoch : *S );
On-error;
wkTime = *Loval;
Endmon;
Return wkTime;
End-proc;



For reference, here is a way of converting your current system time to a Unix timestamp:

Dcl-Proc UnixToTimestamp;
Dcl-Pi *n Timestamp;
pTime Int(10) Const;
End-pi;

Dcl-pr CEEUTCO;
hours INT(10);
minutes INT(10);
seconds FLOAT(8);
fb Char(16) Options(*Omit);
End-pr;
Dcl-S Epoch Timestamp Inz(Z'1970-01-01-00.00.00');
Dcl-s Wkts Timestamp;

DCL-S hours INT(10);
DCL-S mins INT(10);
DCL-S FSecs FLOAT(8);
Dcl-s wkTime Int(10);
Dcl-s Fc Char(16);

// Get timezone offset amount.
CEEUTCO(hours: mins: FSecs : Fc);

Monitor;
// Apply the timezone offset (-43200< < +46800)
wkTime = pTime + Fsecs;
// Convert the time.
Wkts = Epoch + %Seconds( wkTime );
On-error;
Wkts = *Loval;
Endmon;
Return Wkts;
End-proc;


Chris Hiebert
Senior Programmer/Analyst
Disclaimer: Any views or opinions presented are solely those of the author and do not necessarily represent those of the company.
-----Original Message-----
From: RPG400-L [mailto:rpg400-l-bounces@xxxxxxxxxxxxxxxxxx] On Behalf Of Slanina, John via RPG400-L
Sent: Friday, May 3, 2019 9:45 AM
To: RPG programming on IBM i <rpg400-l@xxxxxxxxxxxxxxxxxx>
Cc: Slanina, John <jslanina@xxxxxxxxxx>
Subject: Time zone for a Date and Time

Is there a way to know if a date and time is in the daylight time zone or the standard time zone via an RPGLE program ?
I need to take date and time to its unix timestamp value which is in UTC.

Thanks
John Slanina

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.