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
------------------------------
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
------------------------------
Sign up
Already have an account? Login
Welcome to the Rocket Forum!
Please log in or register:
Employee Login | Registration Member Login | RegistrationEnter your E-mail address. We'll send you an e-mail with instructions to reset your password.
