Quite a few products store dates as elapsed seconds after '01-JAN-1970:00:00:00' GMT, 
but users here want to see the local time of the stored date.  Of course PST is 8 
hours behind GMT and  PDT is seven hours so a hard coded offfset will not work.  Also 
the dates on which the change is made from PST to PDT and  back changes.  So I thought 
why not a function...

CREATE OR REPLACE PACKAGE REMEDY  IS
     FUNCTION SLAC_DATE(ELAPSED_SECONDS IN NUMBER) RETURN DATE ;
     PRAGMA RESTRICT_REFERENCES(SLAC_DATE,WNDS, RNDS, TRUST);
END REMEDY;
/
cREATE OR REPLACE PACKAGE BODY REMEDY AS
     FUNCTION SLAC_DATE(ELAPSED_SECONDS IN NUMBER) RETURN DATE is
         is_pdt boolean;
         GMT_TIME VARCHAR2(19);
         YEAR_OF_DATE VARCHAR2(4);
         PDT_BEGIN  VARCHAR2(19);
         PDT_END  VARCHAR2(19);
         local_time date;

bEGIN
    GMT_TIME := TO_CHAR(TO_DATE('01011970000000', 'MMDDYYYYHH24MISS') + 
    (ELAPSED_SECONDS /(60 *60 * 24)), 'YYYYMMDDHH24MISS');
    year_of_date := substr(GMT_TIME, 1,4);
    PDT_BEGIN := to_char(TRUNC(to_date(concat('31-MAR-',year_of_date),
         'DD-MON-YYYY'), 'IW') +6 +10/24, 'YYYYMMDDHH24MISS');
    PDT_END := to_char(TRUNC(to_date(concat('01-NOV-', year_of_date),
         'DD-MON-YYYY'), 'IW') -1 +9/24,'YYYYMMDDHH24MISS');
    IF GMT_TIME >= PdT_BEGIN AND GMT_TIME < PDT_END THEN
       is_pdt := true;
    ELSE
       is_pdt := false;
    end if;
    if is_pdt then 
          local_time := to_date(gmt_time,'YYYYMMDDHH24MISS') -7/24;
    else
          local_time := to_date(gmt_time,'YYYYMMDDHH24MISS') -8/24;
    end if;
    return local_time;
end SLAC_DATE;
end remedy;
/ 

This function takes a Remedy date , elapsed seconds after the "epoch" and converts it 
to GMT it then
obtains the year from the date ,figures when the switch was made between PDT and PST  
that year, and returns what the local date and time was.  

Of couse not every place makes the switch to daylight savings at 10 a.m. GMT on the 
first Sunday in April nor to standard time at 9 a.m. GMT on the last Sunday in 
October, and  the rules for when to switch have changed before and could again.


There are 25 major time zones in the world.  23 which are 15 degrees wide and two 
which are 7.5  degrees in width.  The International Dateline splits the two 7.5  
degree timezones.

Old American joke:  "The world will end at nine, eight Central Time.
Old Canadian joke:  "The world will end at nine, nine-thirty in Newfoundland."


Ian MacGregor
Stanford Linear Accelerator Ceneter
[EMAIL PROTECTED]

-----Original Message-----
Sent: Wednesday, June 06, 2001 2:32 PM
To: Multiple recipients of list ORACLE-L


As I've mentioned here before, NEW_TIME does not automatically handle DST
conversions.  Nor does it take care of the several places in the US that do
not use DST such as Eastern Indiana and Arizona.  You need to write your own
code to manage time zones and DST conversions.  For a good source of the
time zones and DST rules in effect, check out www.timeanddate.com.  And keep
in mind the DST rules and start/end dates can and do change every year
depending on the whims of governments.

Marc Perkowitz
Senior Consultant
TWJ Consulting, LLP

847-256-8866 x15
www.twjconsulting.com

----- Original Message -----
To: "Multiple recipients of list ORACLE-L" <[EMAIL PROTECTED]>
Sent: Wednesday, June 06, 2001 3:09 PM


> Hi All!
> New_time function use just 10  US time zones. I am looking for other world
> time zones.
> Any ideas?
> Thanks.
> Greg.
>
> --
> Please see the official ORACLE-L FAQ: http://www.orafaq.com
> --
> Author: Gregory Faktor
>   INET: [EMAIL PROTECTED]
>
> Fat City Network Services    -- (858) 538-5051  FAX: (858) 538-5051
> San Diego, California        -- Public Internet access / Mailing Lists
> --------------------------------------------------------------------
> To REMOVE yourself from this mailing list, send an E-Mail message
> to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in
> the message BODY, include a line containing: UNSUB ORACLE-L
> (or the name of mailing list you want to be removed from).  You may
> also send the HELP command for other information (like subscribing).
>

-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.com
-- 
Author: Marc Perkowitz
  INET: [EMAIL PROTECTED]

Fat City Network Services    -- (858) 538-5051  FAX: (858) 538-5051
San Diego, California        -- Public Internet access / Mailing Lists
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).
-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.com
-- 
Author: MacGregor, Ian A.
  INET: [EMAIL PROTECTED]

Fat City Network Services    -- (858) 538-5051  FAX: (858) 538-5051
San Diego, California        -- Public Internet access / Mailing Lists
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).

Reply via email to