TL;DR. How to go from unix time in seconds to datetime in ISO-8601 format ? This looks more like a library question than a language question.
I would like to be able to interpret the ping timestamp (unix time + microseconds) as a datetime to be able to visualize it or perform date and time operations on it. I have a long ping trace (thousands of lines) where each line indicates the success or failure of the ping.
I already managed to make a toy example using a regular expression to get the unix time (without the microseconds) but I didn't find how to use datetimes in APL. I found the APLtree project on Github by the APLteam and their sub-project called DateAndTime
but I couldn't intall it. I don't know how to proceed.
Note that I know that I already have the datetime written explicitly in ISO-8601 format in front of the ping timestamp but for the sake of learning the basics of APL I would like to manipulate datetimes. I could also perform operations on the unix times and then try (but how) to convert them to a datetime in ISO-8601 format.
The trace is generated on Linux with the command:
ping -n -i 30 -O -D my.domain.name | while read pong; do echo "[WAN] $(date --iso-8601=seconds): $pong"; done
The output trace is:
[WAN] 2020-01-31T18:02:35+0100: [1580490155.323878] 64 bytes from 8.8.8.8: icmp_seq=1037 ttl=234 time=720 ms
[WAN] 2020-01-31T18:03:34+0100: [1580490214.630890] no answer yet for icmp_seq=1038
The APL program:
v←('\[(\d+)\.'⎕S'\1')⊃⎕NGET'/Users/ludo/Desktop/so/ping.txt' 1
v
1580490155 1580490214
⍴v
2
DISPLAY v
┌→──────────────────────────┐
│ ┌→─────────┐ ┌→─────────┐ │
│ │1580490155│ │1580490214│ │
│ └──────────┘ └──────────┘ │
└∊──────────────────────────┘
I have another question: why the rank difference between the usage of []
and ⊃
? Do we have a vector in one case and a simple string in the other one (scalar) ? Why is ⍴⍴v[1]
zero ? See the example below.
v←⎕NGET'/Users/ludo/Desktop/so/ping.txt' 1
v
[WAN] 2020-01-31T18:02:35+0100: [1580490155.323878] 64 bytes from 8.8.8.8: ic
mp_seq=1037 ttl=234 time=720 ms [WAN] 2020-01-31T18:03:34+0100: [1580490
214.630890] no answer yet for icmp_seq=1038 UTF-8-NOBOM 13 10
DISPLAY v
┌→───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ ┌→─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ ┌→──────────┐ ┌→────┐ │
│ │ ┌→───────────────────────────────────────────────────────────────────────────────────────────────────────────┐ ┌→──────────────────────────────────────────────────────────────────────────────────┐ │ │UTF-8-NOBOM│ │13 10│ │
│ │ │[WAN] 2020-01-31T18:02:35+0100: [1580490155.323878] 64 bytes from 8.8.8.8: icmp_seq=1037 ttl=234 time=720 ms│ │[WAN] 2020-01-31T18:03:34+0100: [1580490214.630890] no answer yet for icmp_seq=1038│ │ └───────────┘ └~────┘ │
│ │ └────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ └───────────────────────────────────────────────────────────────────────────────────┘ │ │
│ └∊─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ │
└∊───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
⍴v
3
v[1]
[WAN] 2020-01-31T18:02:35+0100: [1580490155.323878] 64 bytes from 8.8.8.8: ic
mp_seq=1037 ttl=234 time=720 ms [WAN] 2020-01-31T18:03:34+0100: [1580490
214.630890] no answer yet for icmp_seq=1038
⊃v
[WAN] 2020-01-31T18:02:35+0100: [1580490155.323878] 64 bytes from 8.8.8.8: icm
p_seq=1037 ttl=234 time=720 ms [WAN] 2020-01-31T18:03:34+0100: [15804902
14.630890] no answer yet for icmp_seq=1038
⍴v[1]
⍴⊃v
2
⍴⍴v[1]
0
⍴⍴⊃v
1