fhg
Volume 6, Number 21 -- May 24, 2006

Present Timestamps in the Local Time Zone

Published: May 24, 2006

by Michael Sansoterra


The code for this article is available for download.

For companies with locations in multiple time zones that connect to a central iSeries, time stamp presentation can be a problem. For instance, consider a legacy shipping application that records the date and time of a shipment. If the legacy application isn't time zone aware, the shipments at the various locations will all be stamped with the date and time of the system's time zone. A desirable solution for this problem would be a routine that can adjust a timestamp from the main time zone to a local time zone.

Fortunately the "Convert Date and Time Format" (QWCCVTDT) API can help. As of V5R3, this API is capable of converting a timestamp from one time zone to another. RPG service program ADJTS, which you can see by clicking here, shows sample subprocedure ADJTIMESTAMP that uses this API for time zone conversion. The subprocedure's parameters are: an input timestamp, the input timestamp's time zone followed by the output time zone. The subprocedure returns the timestamp adjusted for the requested time zone.

Here is a free form example that converts the current date and time to Atlantic Standard Time:

AdjustedTime=AdjTimeStamp(%Timestamp:
                          '*SYS':'QN0400AST');

The input/output time zones are the names of time zone (*TIMZON) objects that define the time zone's name, offset from Coordinated Universal Time (UTC) and daylight savings information. The predefined IBM time zones can be viewed by issuing the WRKTIMZON command or by clicking here. Here are a few examples of the default time zone values:


*TIMZON Name

 

Offset

Description

Q0000UTC

0:00

Coordinated Universal Time (UTC)

Q0000GMT

0:00

Greenwich Mean Time (GMT)

QN0400AST

-4:00

Atlantic Standard Time (AST)

QN0500EST

-5:00

Eastern Standard Time (EST)

QN0500EST2

-5:00

Eastern Standard Time (EST)

QN0600CST

-6:00

Central Standard Time (CST)

QN0700MST

-7:00

Mountain Standard Time (MST)

QN0700MST2

-7:00

Mountain Standard Time (MST)

QN0700T

-7:00

Mountain Standard Time (T)

QN0800PST

-8:00

Pacific Standard Time (PST)

QN0800U

-8:00

Pacific Standard Time (U)

QN0900AST

-9:00

Alaska Standard Time (AST)


If for some reason IBM doesn't have one defined to fit your needs, you can create a *TIMZON object with the CRTTIMZON command.

In addition to these pre-defined time zones, the following special values are allowed by the API:

  • *SYS -- System Time Zone
  • *UTC -- Coordinated Universal Time
  • *JOB -- The current job's defined time zone

This subprocedure can be wrapped with a myriad of related signatures (i.e. parameter lists) to meet any number of variations. For example, a wrapper can be created to accept a numeric date and a numeric time from a legacy application. These two pieces of information can be combined into a timestamp to call the base AdjTimeStamp subprocedure.

For SQL users, an SQL CREATE FUNCTION statement can be used as follows to make the function available to SQL:

Create Function xxxxx/AdjTS 
(parmTimeStamp   Timestamp, 
 parmInTimeZone  Char(10), 
 parmOutTimeZone Char(10)) 
Returns TimeStamp 
Language RPGLE 
External Name 'xxxxx/ADJTS(ADJTIMESTAMP)' 
Parameter Style General 

The function could be used in SQL to convert a timestamp from the system's time zone to Eastern Standard Time as follows:

Select AdjTS(Timestamp('2006-10-02 10:25:30'),        
       Char('*SYS'),Char('QN0500EST')) 
  From SysIBM/SysDummy1

In order to implement this function, an application would need a way to track time zone by user or location. One approach is to store all of the date and time information in a single base time zone such as Coordinated Univeral Time (UTC) or the central system's default time zone. The time zone adjustment subprocedure would be used to adjust a timestamp for display purposes. It would also be used to adjust user input to convert it back to the application's base time zone. A second approach would be to record a time stamp in its native time zone along with the time zone indicator so that it could be properly converted to any other time zone when appropriate.

Applications can quickly jump time zone boundaries for localized date and time display with the use of the QWCCVTDT API.



Sponsored By
ADVANCED SYSTEMS CONCEPTS

SEQUEL can be used for virtually ALL data access functions on the iSeries.

A Windows-based user interface makes it easy to design queries and reports.

SEQUEL offers executive dashboards, drill-down data analysis and run-time prompts to deliver important iSeries data to managers and other non-technical users.

E-mail and FTP delivery let you deliver information to remote users and servers.

www.asc-iseries.com



Senior Technical Editor: Ted Holt
Technical Editors: Howard Arner, Joe Hertvik, Shannon O'Donnell, Kevin Vandever
Contributing Technical Editors: Joel Cochran, Wayne O. Evans, Raymond Everhart,
Bruce Guetzkow, Brian Kelly, Marc Logemann, David Morris
Publisher and Advertising Director: Jenny Thomas
Advertising Sales Representative: Kim Reed
Contact the Editors: To contact anyone on the IT Jungle Team
Go to our contacts page and send us a message.

Sponsored Links

Bug Busters Software Engineering:  Quality software solutions for the iSeries since 1988
COMMON:  Join us at the Fall 2006 conference, September 17-21, in Miami Beach, Florida
Xperia:  Fully integrated suite of applications for small- to mid-sized companies

 


 
Subscription Information:
You can unsubscribe, change your email address, or sign up for any of IT Jungle's free e-newsletters through our Web site at http://www.itjungle.com/sub/subscribe.html.

Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.
Guild Companies, Inc., 50 Park Terrace East, Suite 8F, New York, NY 10034

Privacy Statement