Skip to main content
Jonathan Smith
Rocketeer
Jul 8, 2022 1:17 PM UTC

UniBasic code to perform your own OCONV / ICONV using UniVersal Date Time Stamps

As a normal practice I wouldn't be posting example code onto the forum unless someone was needing help about a specific problem. We did have a question come in from a customer this week asking for a new conversion code be added to UniData. This brought up a couple of interesting subjects. The customer was not aware that you could write your own code following a template to create your own conversion codes. It took me some time to find where this was buried in the manuals I can understand why they would not have come across it.

So just in case others were not aware you could do this I thought I'd share with you how you do this.

SUBROUTINE SUBNAME( return_val, STATUS, input_val, TYPE )
***************************************************************
*
* Brief functional description
*
* (c) Copyright notice
**************************************************************
*
* Detailed description
*
* Usage, such as return_val = OCONV(input_val,"USUBNAME")
*
**************************************************************
* processing code area:
* Arguments:
* return_val = final data to return.
* STATUS = 0 for success, other for failure.
* input_val= data to be converted or processed.
* TYPE: 0 for ICONV, 1 for OCONV.
*
RETURN
END

The customer was asking for some conversion codes to be added around UTL time stamps. So I'm attaching my example code I provided to the customer to demonstrate some ideas around around UTL conversions and would welcome any comments around UTL and in particular handling time zones.

So my example does the following it takes the input of UTL string in for format 2019-06-06T08:58:42.1878669+09:00 or 2019-06-06T08:58:42+09:00 and it will return on ICONV the internal date and internal time of the UTC time. So ICONV(" 2019-06-06T08:58:42.1878669+09:00", "UUTCL") returns 19912 86322.1878669
where 19912 = 17/07/2022 and 86322.1878669 = 23:58:42

In terms of the OCONV it takes 19912 86322.1878669 and then converts that into UTL time stamp of the timezone that the server is running in, so on my Windows Laptop (being UK based) OCONV("19912 86322.1878669","UUTCL") returns 2022-07-07T23:58:42.1878669+00:00 (Dublin, Edinburgh, Lisbon, London) if I use the same example on one of our Denver based unix servers it returns 2022-07-07T23:58:42.1878669-06:00 (MDT Mountain Daylight Time)

So in terms of the attachments with post the user conversion program is called UTCL, there is a testing program called TIME.TEST and there is a look up file called TIMEZONES, the TIMEZONES and D_TIMEZONES files are the Windows / Linux Versions and the TIMEZONES.UX and D_TIMEZONES.UK files are for AIX / HPUX and Solaris.

I hope they provide an example to those of you who didn't know you could do this and also I'd be interested to hear your thoughts about how you want to determine a timezone programmatically.

------------------------------
Jonathan Smith
UniData ATS
Rocket Support
------------------------------

    12 replies

    Henry Unger
    Participating Frequently
    Jul 13, 2022 2:52 PM UTC
    Chuck,

    As two trains of thought:
    1) You can always pass a dynamic array as an argument - e.g. both the data and extended conversion options in separate elements. A Multivalue data set in field1 and conversion options in field 2 for example.

    2) CALLC is also an option for anything particularly awkward or performance sensitive.
    I have used CALLC many times in the past for tasks such as:
    • Time-critical byte-level processing of data blocks.
    • TCP communications (before this was made available in BASIC)
    • File-transfer (MV-to-Other MV - long before FTP and TCP were available) using peer-to-peer. MV to IBM mainframe ('Pick Angel' of memory)
    • Driving auto-diallers, modems, interactive voice synthesisers and a cash-register interface (amongst others).
    (I have been around long enough to remember when 'Interrupt-Clock-Reset-Sense Switch One-Load-Run was a weekly -and occasionally suddenly  required - event).

    Regards

    JJ

    ------------------------------
    John Jenkins
    Thame, Oxfordshire
    ------------------------------

    "With a conversion code of Uuser_exit  The user_exit just specifies which catalogued program to use it does not have any other options as was never designed to do so. "

    UniVerse does have user-defined conversion options. For example, you can specify the conversion as "U1234ABCD" and UniVerse will call $1234 and pass in "U1234ABCD".

    For example:

    function u1234(branch, value, type)
    params = branch[6, len(branch)]

    etc.

    We use dozens of user-defined conversions and most use such parameters.

    Henry




    ------------------------------
    Henry Unger
    President
    Hitech Systems Inc
    Encino CA US
    ------------------------------
    Jonathan Smith
    Rocketeer
    Jul 13, 2022 5:43 PM UTC
    Jonathan - I believe "Bill" was asking about your statement..."As a normal practice I wouldn't be posting example code onto the forum unless" - why? As a developer's forum, this is where I go to bounce ideas/code with other developers, we share code snippets and the like.  Yes, we have to be mindful of relevant IP and NDAs, but a snippet of code is not a violation, especially in this case of an OCONV/ICONV hack.  I, as well, am curious, "as a normal practice", why not post code? A lot of colleagues on this site, post, we analyze, discuss, bounce ideas off each other, etc.  This is more or less our sandbox to play discuss/develop ideas/concepts and the like.

    ------------------------------
    Stacy Mecklenburg
    Senior Developer
    Software Solutions Unlimited
    San Anselmo CA US
    ------------------------------
    Hi all

    What i should have said was i wouldn't normally post code on the forum about something unless someone has directly asked a question about it ... however a customer contacted support with a question so i thought I'd share with this everyone as others may not know as well

    Thanks ​​​

    ------------------------------
    Jonathan Smith
    UniData ATS
    Rocket Support
    ------------------------------
    Rocket Software - Senior Principal Technical Support Engineer - UniData ATS