[Python] Robot framework or Python compare dates

Discussão em 'Python' iniciado por Stack, Maio 4, 2025.

  1. Stack

    Stack Membro Participativo

    I have example date (which must be RFC3339 format) 2021-07-23T14:07:21Z

    Next there is an endpoint which takes that date lets say /setdate Next I want verify whather it was set OK using another endpoint /getdate for examples. The problem is that this second endpoit returns this date as 2021-07-23T16:07:21+02:00 whis effectively is the same date but its diffent string so I cant simply compare those two in robot framework. Are there any robot framework keywords to create two date objects which will be the same when we compare their values?

    How is it possible?

    Documentation:

    Fails if the given objects are unequal.
    Start / End / Elapsed: 20240513 21:06:22.031 / 20240513 21:06:22.031 / 00:00:00.000
    21:06:22.031 DEBUG Argument types are:
    <class 'datetime.datetime'>
    <class 'datetime.datetime'>
    21:06:22.031 FAIL 2021-07-23 14:07:21+02:00 != 2021-07-23 12:07:21


    how can I compare two datetime objects as they are not as strings?

    Also,

    def main():
    d1 ='2021-07-23T14:07:21+00:00'
    d2='2021-07-23T14:07:21Z'
    res = compare_rfc_dates(d1, d2)
    print(res)


    prints:

    2021-07-23 14:07:21+00:00 2021-07-23 14:07:21
    False


    when compared as datetime objects. What does this mean?

    Continue reading...

Compartilhe esta Página