number of seconds since epoch in eiffel for a DATE_TIME object

78 Views Asked by At

how would you calculate the number of seconds since epoch in eiffel for a DATE_TIME object?

What is the proper way to do it with the current libraries?

1

There are 1 best solutions below

0
On BEST ANSWER

You can calculate the number of seconds since epoch like this

number_of_seconds_since_epoch
        -- calculate the number of seconds since epoch in eiffel
    local
        l_date_epoch: DATE_TIME
        l_date_now: DATE_TIME
        l_diff: INTEGER_64
    do
        create l_date_epoch.make_from_epoch (0)
        create l_date_now.make_now_utc
        l_diff := l_date_now.definite_duration (l_date_epoch).seconds_count
        print ("%NEpoch:" + l_date_epoch.out)
        print ("%NNow:" + l_date_now.out)
        print ("%NDiff in seconds:" + l_diff.out)
    end