Unix Epoch

Question: The Unix epoch is the starting point of time for Unix based computing systems, and it is set to January 1, 1970. Unix epoch time an an integer which represents the time elapsed since the Unix epoch. In q, we can cast integers to timestamps, with the integer being interpreted as the number of nanoseconds since epoch. The epoch for q, however, is January 1, 2000, so this poses a problem if you simply cast a Unix epoch time to a q timestamp. The Unix epoch has to be accounted for and adjusted. Define a function 'frmUnixEp' (from Unix epoch) that takes in an integer representing the Unix epoch time (in nanoseconds) and converts it to q epoch time.

More Information:

https://en.wikipedia.org/wiki/Unix_time

Example

                                
                                q)frmUnixEp 1589841242176*1e6 //convert to nanos
6.431564e+17
q)"p"$frmUnixEp 1589841242176*1e6
2020.05.18D22:34:02.176000000
q)"p"$frmUnixEp 1e9*"J"$first system"date +%s" // convert current Unix epoch time to q timestamp
2020.05.18D23:20:55.000000000
                                
                            

Solution

Tags:
functions math temporal
Searchable Tags
algorithms api architecture c csv data structures dictionaries disk feedhandler finance functions ingestion ipc iterators machine learning math multithreading optimizations realtime shared library sql statistics streaming strings tables temporal websockets

Email sent!

Email not sent