Community discussions

MikroTik App
 
User avatar
macsrwe
Forum Guru
Forum Guru
Topic Author
Posts: 1007
Joined: Mon Apr 02, 2007 5:43 am
Location: Arizona, USA
Contact:

Manipulating and comparing dates / manual wrong?

Mon Mar 01, 2021 5:22 am

This shouldn't be rocket science, but it's beginning to look like it is.
I'm trying to scan a set of firewall address-list elements to see which one was most recently added. That means doing date comparisons. I can't get them to work.
I've determined that when I do [/ip firewall address-list get [find list="listname"] creation-time], I get strings, not date values. Fine, once I realize that, I can work with it.
So I've been keeping all my date values as strings and then using :totime only at the point of comparison... but the comparison never functions correctly.
Upon examination, any attempt to convert a date-time string to a time value seems to fail miserably:
[me@myrouter] > {
{... :local foo "feb/28/2021 19:01:33";        
{... :put [:typeof $foo]                       
{... }                                  
str                          // right, I expected that...
[me@myrouter] >             
[me@myrouter] > {
{... :local foo [:totime "feb/28/2021 19:01:33"];        
{... :put [:typeof $foo]                                 
{... }                                  
nil
[me@myrouter] >
Now... if I use strings representing times only (e.g., "12:30:04"), I no longer get nil, but time, and the values look correct.
Note that the scripting guide states that the time data type is a "date and time value." However, it doesn't look as if they are actually treated that way.
On the third hand, the guide uses (date) instead of (time) to describe data elements such as last-started (in /system script)... but there is no "date" data type. There certainly isn't a :todate builtin (I tried it).

To summarize, the manual defines the time data type inconsistently, and there doesn't seem to be a way to convert a time-with-date string into a time variable.
Is there a way to do what I want to do without a lot of rocket science?

(Ironically, this task was undertaken solely because there doesn't seem to be a way to do what I REALLY want to do, which is to have a firewall rule shoot off an email.)
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Manipulating and comparing dates / manual wrong?

Mon Mar 01, 2021 12:13 pm

Is there a way to do what I want to do without a lot of rocket science?
It can be done, buts not simple. You have to take care that in current day format of log are no equal as the rest of the logs.


I have commented this several time.
viewtopic.php?p=828794#p828794
MT should change to use RFC-3164 time format everywhere.
In a support email, they say they will look inn to it. But even 7.x is not in RFC format.

Workaround: Send log to an syslog server (Eks Splunk)
 
User avatar
macsrwe
Forum Guru
Forum Guru
Topic Author
Posts: 1007
Joined: Mon Apr 02, 2007 5:43 am
Location: Arizona, USA
Contact:

Re: Manipulating and comparing dates / manual wrong?

Mon Mar 01, 2021 1:03 pm

I appreciate your input, but your advice seems entirely log-specific. I am not doing anything with logs. I am working with scripts and date-time variables/data fields in configuration records.
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Manipulating and comparing dates / manual wrong?

Mon Mar 01, 2021 3:33 pm

If time has been available in epoc time and shown in readable format in view, calculation of time would have been easy.

Who is online

Users browsing this forum: No registered users and 16 guests