Calling a REST Server that returns time as "1467042402"

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Calling a REST Server that returns time as "1467042402"

Dave Nasralla
Hey All,

I'm missing something obvious, I know. I'm using 4D as a REST Client
to pull data from a Moodle service. It gives me a 'timefinish' value
of 1467042402

How do I convert the number to a Date/Time 4D can use?

Thanks,

dave

--
David Nasralla
Clean Air Engineering
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Calling a REST Server that returns time as "1467042402"

Lee Hinde
http://www.epochconverter.com/ <http://www.epochconverter.com/>


> On Jul 11, 2016, at 3:53 PM, Dave Nasralla <[hidden email]> wrote:
>
> Hey All,
>
> I'm missing something obvious, I know. I'm using 4D as a REST Client
> to pull data from a Moodle service. It gives me a 'timefinish' value
> of 1467042402
>
> How do I convert the number to a Date/Time 4D can use?
>
> Thanks,
>
> dave
>
> --
> David Nasralla
> Clean Air Engineering
> **********************************************************************
> 4D Internet Users Group (4D iNUG)
> FAQ:  http://lists.4d.com/faqnug.html
> Archive:  http://lists.4d.com/archives.html
> Options: http://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:[hidden email]
> **********************************************************************

**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Calling a REST Server that returns time as "1467042402"

Dave Nasralla
Thanks Lee. That pointed me in the right direction. I always get
nervous when I don't find existing code for something that seems like
there should be.

Anywho, I came up with the following. It give reasonable results, but
may not be perfect.

  // User name (OS): Dave Nasralla
  // Date and time: 07/11/16, 21:05:12
  // ----------------------------------------------------
  // Method: UT_ConvertEpochToDateTime
  // Description
  // This routine convert Unix Epoch Time to ISO GMT Time and standard
Date and Time as well

C_TEXT($0;$ISO_Date_GMT_vt)
$ISO_Date_GMT_vt:=""

C_REAL($1;$UnixEpochTime_vr)
$UnixEpochTime_vr:=$1  // Equals the number of seconds that have
passed since midnight 1/1/1970

C_DATE($Date_vd)
C_POINTER($Date_vd_ptr)

$Date_vd_ptr:=->$Date_vd
If (Count parameters>1)
  C_POINTER($2)
  $Date_vd_ptr:=$2
End if

C_TIME($Time_vh)
C_POINTER($Time_vh_ptr)
$Time_vh_ptr:=->$Time_vh
If (Count parameters>2)
  C_POINTER($3)
  $Time_vh_ptr:=$3
End if

C_DATE($BaseDate_vd)
$BaseDate_vd:=!1970-01-01!

C_REAL($Days_vr)
$Days_vr:=$UnixEpochTime_vr/60/60/24  //Divide by the number of seconds in a day

C_LONGINT($NumDays_vl)
$NumDays_vl:=Int($Days_vr)
$Date_vd:=$BaseDate_vd+$NumDays_vl

C_LONGINT($Seconds_vl)
$Seconds_vl:=Dec($Days_vr)*60*60*24

$Time_vh:=?00:00:00?+$Seconds_vl

$Date_vd_ptr->:=$Date_vd
$Time_vh_ptr->:=$Time_vh
$0:=String($Date_vd;ISO date GMT;$Time_vh)

On Mon, Jul 11, 2016 at 5:39 PM, Lee Hinde <[hidden email]> wrote:

> http://www.epochconverter.com/ <http://www.epochconverter.com/>
>
>
>> On Jul 11, 2016, at 3:53 PM, Dave Nasralla <[hidden email]> wrote:
>>
>> Hey All,
>>
>> I'm missing something obvious, I know. I'm using 4D as a REST Client
>> to pull data from a Moodle service. It gives me a 'timefinish' value
>> of 1467042402
>>
>> How do I convert the number to a Date/Time 4D can use?
>>
>> Thanks,
>>
>> dave
>>
>> --
>> David Nasralla
>> Clean Air Engineering
>> **********************************************************************
>> 4D Internet Users Group (4D iNUG)
>> FAQ:  http://lists.4d.com/faqnug.html
>> Archive:  http://lists.4d.com/archives.html
>> Options: http://lists.4d.com/mailman/options/4d_tech
>> Unsub:  mailto:[hidden email]
>> **********************************************************************
>
> **********************************************************************
> 4D Internet Users Group (4D iNUG)
> FAQ:  http://lists.4d.com/faqnug.html
> Archive:  http://lists.4d.com/archives.html
> Options: http://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:[hidden email]
> **********************************************************************



--
David Nasralla
Clean Air Engineering
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Calling a REST Server that returns time as "1467042402"

Dave Nasralla
Sure enough. After I added this code to my system I found I already
had code elsewhere to do these calculations from David Dancy 5 years
ago... Oh well, it was a good exercise... maybe :-)

dave

On Mon, Jul 11, 2016 at 9:23 PM, Dave Nasralla <[hidden email]> wrote:

> Thanks Lee. That pointed me in the right direction. I always get
> nervous when I don't find existing code for something that seems like
> there should be.
>
> Anywho, I came up with the following. It give reasonable results, but
> may not be perfect.
>
>   // User name (OS): Dave Nasralla
>   // Date and time: 07/11/16, 21:05:12
>   // ----------------------------------------------------
>   // Method: UT_ConvertEpochToDateTime
>   // Description
>   // This routine convert Unix Epoch Time to ISO GMT Time and standard
> Date and Time as well
>
> C_TEXT($0;$ISO_Date_GMT_vt)
> $ISO_Date_GMT_vt:=""
>
> C_REAL($1;$UnixEpochTime_vr)
> $UnixEpochTime_vr:=$1  // Equals the number of seconds that have
> passed since midnight 1/1/1970
>
> C_DATE($Date_vd)
> C_POINTER($Date_vd_ptr)
>
> $Date_vd_ptr:=->$Date_vd
> If (Count parameters>1)
>   C_POINTER($2)
>   $Date_vd_ptr:=$2
> End if
>
> C_TIME($Time_vh)
> C_POINTER($Time_vh_ptr)
> $Time_vh_ptr:=->$Time_vh
> If (Count parameters>2)
>   C_POINTER($3)
>   $Time_vh_ptr:=$3
> End if
>
> C_DATE($BaseDate_vd)
> $BaseDate_vd:=!1970-01-01!
>
> C_REAL($Days_vr)
> $Days_vr:=$UnixEpochTime_vr/60/60/24  //Divide by the number of seconds in a day
>
> C_LONGINT($NumDays_vl)
> $NumDays_vl:=Int($Days_vr)
> $Date_vd:=$BaseDate_vd+$NumDays_vl
>
> C_LONGINT($Seconds_vl)
> $Seconds_vl:=Dec($Days_vr)*60*60*24
>
> $Time_vh:=?00:00:00?+$Seconds_vl
>
> $Date_vd_ptr->:=$Date_vd
> $Time_vh_ptr->:=$Time_vh
> $0:=String($Date_vd;ISO date GMT;$Time_vh)
>
> On Mon, Jul 11, 2016 at 5:39 PM, Lee Hinde <[hidden email]> wrote:
>> http://www.epochconverter.com/ <http://www.epochconverter.com/>
>>
>>
>>> On Jul 11, 2016, at 3:53 PM, Dave Nasralla <[hidden email]> wrote:
>>>
>>> Hey All,
>>>
>>> I'm missing something obvious, I know. I'm using 4D as a REST Client
>>> to pull data from a Moodle service. It gives me a 'timefinish' value
>>> of 1467042402
>>>
>>> How do I convert the number to a Date/Time 4D can use?
>>>
>>> Thanks,
>>>
>>> dave
>>>
>>> --
>>> David Nasralla
>>> Clean Air Engineering
>>> **********************************************************************
>>> 4D Internet Users Group (4D iNUG)
>>> FAQ:  http://lists.4d.com/faqnug.html
>>> Archive:  http://lists.4d.com/archives.html
>>> Options: http://lists.4d.com/mailman/options/4d_tech
>>> Unsub:  mailto:[hidden email]
>>> **********************************************************************
>>
>> **********************************************************************
>> 4D Internet Users Group (4D iNUG)
>> FAQ:  http://lists.4d.com/faqnug.html
>> Archive:  http://lists.4d.com/archives.html
>> Options: http://lists.4d.com/mailman/options/4d_tech
>> Unsub:  mailto:[hidden email]
>> **********************************************************************
>
>
>
> --
> David Nasralla
> Clean Air Engineering



--
David Nasralla
Clean Air Engineering
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Calling a REST Server that returns time as "1467042402"

Keith Culotta ns
In reply to this post by Dave Nasralla
Using some built in functions.

C_TIME($time)
C_DATE($date)
C_LONGINT($secsInDay)

$eTime:=1468328714
$secsInDay:=86400

$time:=Time($eTime/$secsInDay)
$days:=Int($eTime/$secsInDay)
$date:=Add to date(!1970-01-01!;0;0;$days)

Keith - CDI


> On Jul 11, 2016, at 5:53 PM, Dave Nasralla <[hidden email]> wrote:
>
> Hey All,
>
> I'm missing something obvious, I know. I'm using 4D as a REST Client
> to pull data from a Moodle service. It gives me a 'timefinish' value
> of 1467042402
>
> How do I convert the number to a Date/Time 4D can use?
>
> Thanks,
>
> dave
>
> --
> David Nasralla
> Clean Air Engineering
> **********************************************************************
> 4D Internet Users Group (4D iNUG)
> FAQ:  http://lists.4d.com/faqnug.html
> Archive:  http://lists.4d.com/archives.html
> Options: http://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:[hidden email]
> **********************************************************************

**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Calling a REST Server that returns time as "1467042402"

Dave Nasralla
Thanks Keith. That's elegant and simple.
dave

On Tue, Jul 12, 2016 at 7:10 AM, Keith Culotta <[hidden email]> wrote:

> Using some built in functions.
>
> C_TIME($time)
> C_DATE($date)
> C_LONGINT($secsInDay)
>
> $eTime:=1468328714
> $secsInDay:=86400
>
> $time:=Time($eTime/$secsInDay)
> $days:=Int($eTime/$secsInDay)
> $date:=Add to date(!1970-01-01!;0;0;$days)
>
> Keith - CDI
>
>
>> On Jul 11, 2016, at 5:53 PM, Dave Nasralla <[hidden email]> wrote:
>>
>> Hey All,
>>
>> I'm missing something obvious, I know. I'm using 4D as a REST Client
>> to pull data from a Moodle service. It gives me a 'timefinish' value
>> of 1467042402
>>
>> How do I convert the number to a Date/Time 4D can use?
>>
>> Thanks,
>>
>> dave
>>
>> --
>> David Nasralla
>> Clean Air Engineering
>> **********************************************************************
>> 4D Internet Users Group (4D iNUG)
>> FAQ:  http://lists.4d.com/faqnug.html
>> Archive:  http://lists.4d.com/archives.html
>> Options: http://lists.4d.com/mailman/options/4d_tech
>> Unsub:  mailto:[hidden email]
>> **********************************************************************
>
> **********************************************************************
> 4D Internet Users Group (4D iNUG)
> FAQ:  http://lists.4d.com/faqnug.html
> Archive:  http://lists.4d.com/archives.html
> Options: http://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:[hidden email]
> **********************************************************************



--
David Nasralla
Clean Air Engineering
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Calling a REST Server that returns time as "1467042402"

Jeremy Roussak
That’s a long time in the future (2047)!

Shouldn’t

        $time:=Time($eTime/$secsInDay)

be

        $time:=Time($eTime%$secsInDay)

Jeremy


> On 12 Jul 2016, at 17:25, Dave Nasralla <[hidden email]> wrote:
>
> Thanks Keith. That's elegant and simple.
> dave
>
> On Tue, Jul 12, 2016 at 7:10 AM, Keith Culotta <[hidden email]> wrote:
>> Using some built in functions.
>>
>> C_TIME($time)
>> C_DATE($date)
>> C_LONGINT($secsInDay)
>>
>> $eTime:=1468328714
>> $secsInDay:=86400
>>
>> $time:=Time($eTime/$secsInDay)
>> $days:=Int($eTime/$secsInDay)
>> $date:=Add to date(!1970-01-01!;0;0;$days)
>>
>> Keith - CDI
>>
>>
>>> On Jul 11, 2016, at 5:53 PM, Dave Nasralla <[hidden email]> wrote:
>>>
>>> Hey All,
>>>
>>> I'm missing something obvious, I know. I'm using 4D as a REST Client
>>> to pull data from a Moodle service. It gives me a 'timefinish' value
>>> of 1467042402
>>>
>>> How do I convert the number to a Date/Time 4D can use?
>>>
>>> Thanks,
>>>
>>> dave


Jeremy Roussak
[hidden email]



**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Calling a REST Server that returns time as "1467042402"

Keith Culotta ns
$eTime:=1468343098
$secsInDay:=86400
$time:=Time($eTime/$secsInDay)  //  = 04:43:15
$time1:=Time($eTime%$secsInDay) //  = 17:04:58 - correct!

Keith - CDI

> On Jul 12, 2016, at 11:48 AM, Jeremy Roussak <[hidden email]> wrote:
>
> That’s a long time in the future (2047)!
>
> Shouldn’t
>
> $time:=Time($eTime/$secsInDay)
>
> be
>
> $time:=Time($eTime%$secsInDay)
>
> Jeremy
>
>
>> On 12 Jul 2016, at 17:25, Dave Nasralla <[hidden email]> wrote:
>>
>> Thanks Keith. That's elegant and simple.
>> dave
>>
>> On Tue, Jul 12, 2016 at 7:10 AM, Keith Culotta <[hidden email]> wrote:
>>> Using some built in functions.
>>>
>>> C_TIME($time)
>>> C_DATE($date)
>>> C_LONGINT($secsInDay)
>>>
>>> $eTime:=1468328714
>>> $secsInDay:=86400
>>>
>>> $time:=Time($eTime/$secsInDay)
>>> $days:=Int($eTime/$secsInDay)
>>> $date:=Add to date(!1970-01-01!;0;0;$days)
>>>
>>> Keith - CDI
>>>
>>>
>>>> On Jul 11, 2016, at 5:53 PM, Dave Nasralla <[hidden email]> wrote:
>>>>
>>>> Hey All,
>>>>
>>>> I'm missing something obvious, I know. I'm using 4D as a REST Client
>>>> to pull data from a Moodle service. It gives me a 'timefinish' value
>>>> of 1467042402
>>>>
>>>> How do I convert the number to a Date/Time 4D can use?
>>>>
>>>> Thanks,
>>>>
>>>> dave
>
>
> Jeremy Roussak
> [hidden email]
>
>
>
> **********************************************************************
> 4D Internet Users Group (4D iNUG)
> FAQ:  http://lists.4d.com/faqnug.html
> Archive:  http://lists.4d.com/archives.html
> Options: http://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:[hidden email]
> **********************************************************************

**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

RE: Calling a REST Server that returns time as "1467042402"

Timothy Penner
Quote:
>
> $eTime:=1468343098
> $secsInDay:=86400
> $time:=Time($eTime/$secsInDay)  //  = 04:43:15
> $time1:=Time($eTime%$secsInDay) //  = 17:04:58 - correct!
>

Just a quick reminder of the different types of numeric operators in 4D:
http://doc.4d.com/4Dv15R4/4D/15-R4/Numeric-Operators.300-2825419.en.html

----
An expression that uses a numeric operator returns a number. The following table shows the numeric operators:

Operation       Syntax  Returns Expression      Value
Addition        Number + Number Number  2 + 3   5
Subtraction     Number – Number Number  3 – 2   1
Multiplication  Number * Number Number  5 * 2   10
Division        Number /Number  Number  5 / 2   2.5
Longint division        Number \ Number Number  5 \ 2   2
Modulo  Number % Number Number  5 % 2   1
Exponentiation  Number ^ Number Number  2 ^ 3   8

The modulo operator % divides the first number by the second number and returns a whole number remainder. Here are some examples:
10 % 2 returns 0 because 10 is evenly divided by 2.
10 % 3 returns 1 because the remainder is 1.
10.5 % 2 returns 0 because the remainder is not a whole number.

WARNING:

The modulo operator % returns significant values with numbers that are in the Long Integer range (from minus 2^31 to 2^31 minus one). To calculate the modulo with numbers outside of this range, use the Mod command.

The longint division operator \ returns significant values with integer numbers only.
---

-tp





**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************