RexxTime ... and other associates ...

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

RexxTime ... and other associates ...

ThSITC
Hi Rene, and all,

as You all do know, I did implement nearly all classic Rexx functions in
my Rexx2Nrx package.

Rexx2Nrx has been my attempt to convert Classic COMPILED Rexx to
Netrexx, sometimes early in 2002.

Rene, You did mention the *compatibility* package in Your show MFC did
yust distribute!

I am including heare now Yust RexxTime ;-)

Thomas.

========================================================================================

/*************************************************************************/
/* IBM Materials Licensed under International Components for Unicode     */
/* Licence version 1.8.1 (ICU Licence) - Property of IBM                 */
/* --------------------------------------------------------------------- */
/* The former Rexx2Nrx Run-Time Package (NetRexx Version)                */
/* of Thomas Schneider, ThSITC, 2011. See www.thsitc.com/Product Rexx2Nrx*/
/* for Details. Note that the method names have been adjusted for Java   */
/* naming conventions since the first Rexx2Nrx release, back in 2001!    */
/* --------------------------------------------------------------------- */
/* Copyright (c) 2000-2010 [hidden email]                   */
/* Copyright (c) 2011-oo RexxLA                                        */
/*************************************************************************/

/***************************************************************************/
/* RexxTime contains an emulation of the classic REXX Date & Time
functions*/
/*                                (c) Th. Schneider, Mai
2000              */
/***************************************************************************/
/* 26.06.2002: own function(method) 'edate' added for
convenience          */
/* 04.09.2007: time('N') returns hh':'mm':'ss
added                       */
/***************************************************************************/
options binary

package org.netrexx.thsitc.runtime.compatibility

import java.util.Date
import java.lang.System /* needed for CurrentTimeMillis() */

class RexxTime public

properties static

   /* stub for REXX Date & Time routines */
   months=Rexx 'Jan Feb Mar Apr May Jun Jul Aug Sep Okt Nov Dec'
   month_name=Rexx 'January February March April Mai June July August'-
              'September October November December'
   wday_name=Rexx 'Monday Tuesday Wednesday Thursday Friday Saturday Sunday'

   time1 = long 0              /* start time in millisec past1 1.1.1970 */
   millisecs=long 0            /* elapsed time in milliseconds */
   time0 = long 0              /* current time in millisec past 1.1.1970 */
   time2 = long 0
   first_timer= boolean 1

   elapsed_seconds = Double /* double precision elapsed seconds */
   elapsed = Rexx '' /* same as Rexx object */
   e_elapsed=Rexx '' /* elapsed time as a string */
   trace_timer=boolean 0      /* 1=trace timer */
   iwday = int 0
   idd = int 0
   imm = int 0
   iyy = int 0

method RexxTime()

method timer private static returns long
   time0=java.lang.System.currentTimeMillis()

   if trace_timer then
   say 'timer: 'time0   '(seconds past 1.1.1970)'

   if first_timer then do
      time1=time0
      first_timer=0
   end
   millisecs= time0- time1

   if trace_timer then
   say 'millisecsonds: ' millisecs

   return millisecs

method date(opt=Rexx ' ') public static returns Rexx

   opt1=opt.substr(1,1)
   cal=GregorianCalendar()

   /* use JAVA Date methods */
   idd=cal.get(Calendar.DAY_OF_MONTH)      -- day in month
   imm=cal.get(Calendar.MONTH) + 1         -- month (1 bis 12)

   dd=Rexx(idd);dd=dd.right(2,'0');  -- leading 0 when needed
   mm=Rexx(imm);mm=mm.right(2,'0');  -- leading 0 when needed

   yyyy=cal.get(Calendar.YEAR)                 -- year 4 digits
   iyy = yyyy // 100                 -- two digit year
   yy=Rexx(iyy); yy=yy.right(2,'0')  -- two digit year with leading zero

   iddd = cal.get(Calendar.DAY_OF_YEAR)       -- day of year

   ddd=Rexx(iddd); ddd=ddd.right(3,0)

   iwday = cal.get(Calendar.DAY_OF_WEEK) - 1  -- day of week, 1= Monday

   if iwday=0 then iwday = 7        -- SUNDAY is 7

   select case opt1
     when ' ' then do
       mon3=month_name.word(imm).substr(1,3)
       return dd mon3 yyyy
     end
     when 'B' then do
       -- Base, returns the number of complete days since 1.1.0001
       say 'date(B) not yet implemented'
       return 0 /* not yet implemented*/
     end
     when 'C' then do -- days in Century
       say 'date(C) not yet implemented'
       return 0
     end
     when 'J' then do -- Julian date in format yyddd
       return yy||ddd
     end
     when 'D' then do -- returns days, including the current day
                      -- in the format 'ddd' (no leading zeros or blanks
       return iddd
     end
     when 'E' then do -- European, returns dd/mm/yy
       return dd'/'mm'/'yy
     end
     when 'M' then do -- return full English name of current month
       return month_name.word(imm)
     end
     when 'N' then do -- returns date in default format, see pg. 92
       mmm=months.word(imm) --- three letter month abbreviation
       return dd mmm yyyy
     end
     when 'O' then do -- Ordered, format yy/mm/dd
       return yy'/'mm'/'dd
     end
     when 'S' then do -- Standard (yyyymmdd)
       return yyyy||mm||dd
     end
     when 'U' then do -- USA (mm/dd/yy)
       return mm'/'dd'/'yy
     end
     when 'W' then do -- Weekday (English name for day of the week)
       return wday_name.word(iwday)
     end
     otherwise return yyyy'-'mm'-'dd
   end /* select */

method time(opt=Rexx ' ') public static returns Rexx
     cur_dts=java.util.Date()
     ihh=cur_dts.getHours()    -- hours
     hh=Rexx ihh; hh=hh.right(2,'0')
     inn=cur_dts.getMinutes()  -- minutes, as mm is month
     nn=Rexx inn; nn=nn.right(2,'0')
     iss=cur_dts.getSeconds()  -- seconds
     ss=Rexx iss; ss=ss.right(2,'0')

     opt1=opt.substr(1,1)
     select case opt1
        when 'C' then do
           if ihh>12 then do; ihh=ihh-12; xx='pm'; end
           else xx='am'
           hh=Rexx ihh; hh=hh.right(2,'0')
           return hh':'nn||xx
        end
         when 'E' then do    /* returns elapsed time in seconds */
          time2 = timer()
          elapsed = time2
          /* time as seconds and fraction*/
          elapsed = time2 / 1000
          e_elapsed=elapsed.format(6,6) /* edited form needed*/
          /* always 6 digit fraction!*/
          if trace_timer then
          say 'elapsed time:' e_elapsed 'seconds'
          return e_elapsed
        end
        when 'H' then return hh /* returns hour */
        when 'L' then do
          uuuuuu='00000' /* cannot get Nanoseconds currently */
          return hh':'nn':'ss'.'uuuuuu
        end
        when 'M' then do
          nnnn=ihh*60+inn   /* minutes past midnight */
          return nnnn
        end
        when 'N' then return hh':'nn':'ss  /* own addition */
        when 'R' then do    /* reset timer */
          first_timer=boolean 1
          time2=timer()
          elapsed= time2
          elapsed=elapsed/1000
          e_elapsed=elapsed.format(6,6)
           /* always 6 digit fraction!*/

          if trace_timer then
          say 'elapsed time=' e_elapsed 'seconds'

          return e_elapsed

        end
        when 'S' then do    /* seconds past midnight */
          ssss=(hh*60+nn)*60+ss
          return ssss
        end
        otherwise return hh':'nn':'ss
     end /* select */

method edate(idate = Rexx '') static public returns Rexx;
    /* ... Declare local REXX variables: */
    x_date = Rexx ''                                         /* select */
    dd = Rexx ''
    mm = Rexx ''
    yy = Rexx ''
    cc = Rexx '20'
    yyyy = Rexx ''

    /* ... End of local REXX variable declarations                     */
    /* ... Rexx Procedure (nothing exposed)                            */
select;
       when (idate = '') | (idate = 0) then do;
          x_date = RexxTime.date('E');
          parse x_date dd '/' mm '/' yy
          cc = '20';
          yyyy = cc || yy;
          end /*when*/
       when idate.length() = 6 then do;
          yy = idate.substr(1,2);
          mm = idate.substr(3,2);
          dd = idate.substr(5,2);
          if yy < 50 then do;
             cc = '20';
end
          else do;
             cc = '19';
          end; /*if*/
          yyyy = cc || yy;
          end /*when*/
       when idate.length() = 8 then do;
          yyyy = idate.substr(1,4);
          yy = yyyy.substr(3,2);
          mm = idate.substr(5,2);
          dd = idate.substr(7,2);
          end /*when*/
       otherwise do;
do;
             RexxMsg.error('invalid date: '||idate 'encountered.')
             RexxMsg.abort('please correct source program!')
end;
       end; /* otherwise */                                  /* select */
    end; /* select */

    x_date = dd||'.'||mm||'.'||yyyy;
    return x_date;
/*********************************************************************/
/* 02.07.2002: own function dts() added                              */
/*********************************************************************/
method dts() public static returns Rexx
    odate = RexxTime.date('O');
    parse odate yy '/' mm '/' dd
    yyyy = '20'||yy;
    xdate = yyyy||'-'||mm||'-'||dd;              /* date in ISO format */
    return xdate RexxTime.time();

method StandardDate(xdate=Rexx,image=Rexx) public static returns int --
YYYYMMDD returned
    if image.pos('.') > 0 then do
      parse xdate DD'.'MM'.'YYYY
      ydate=YYYYMMDD(YYYY,MM,DD)
      return ydate
    end
    if image.pos('-') > 0 then do
      parse xdate YYYY'-'MM'-'DD
      ydate=YYYYMMDD(YYYY,MM,DD)
      return ydate
    end
    if image.pos('/') > 0 then do
      parse xdate MM'/'DD'/'YYYY
      ydate=YYYYMMDD(YYYY,MM,DD)
      return ydate
    end
    return int xdate -- YYYYMMDD assumed

method YYYYMMDD(YYYY,MM,DD) public static returns int
    if YYYY < 100 then YYYY='20'YYYY
    if MM>12 | MM < 1 then do
       RexxMsg.error('Illegal month:' MM)
       MM='99'  -- signals error
    end
    if MM<10 then MM='0'MM -- only 1 digit given
    if DD>31 | DD < 1 then do
       RexxMsg.error('Illegal day:' DD)
       DD='99' -- signals error
    end
    if DD < 10 then DD='0'DD  -- only 1 digit given
    ydate=int YYYY||MM||DD
    return ydate






---
This email has been checked for viruses by AVG.
https://urldefense.proofpoint.com/v2/url?u=http-3A__www.avg.com&d=DwICaQ&c=jf_iaSHvJObTbx-siA1ZOg&r=_6rXNpPJ1fYV-3bV1za02NiR4PUelvicfHXwtnTXpXE&m=NUxqurSy4r-Gp2WdmmWH9mOaH4skplgxVUZElKEuNTM&s=0O4DwL0E29qAY8wfHbWvgGMbW5YTnyOgGYiHcyJlcMg&e=

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Thomas Schneider, Vienna, Austria (Europe) :-)

www.thsitc.com
www.db-123.com