Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

different time in request and reponse #23

Closed
cherepanovic opened this issue Mar 23, 2020 · 4 comments
Closed

different time in request and reponse #23

cherepanovic opened this issue Mar 23, 2020 · 4 comments

Comments

@cherepanovic
Copy link

cherepanovic commented Mar 23, 2020

Hello bgpstream team,

following issue which I faced to. I make a request with your library to rrc04 collector with the time range of

"2001-09-21", "09:56:00" - "2001-09-21", "10:00:00"

however the packages which I get in the response have timestamp with two hours more.

elem:  update|S|1001066362.000000|ris|rrc04|None|None|8327|192.65.185.151|None|None|None|None|ACTIVE|CONNECT
package time: 1001066362.0
2001-09-21 11:59:22
elem:  update|S|1001066362.000000|ris|rrc04|None|None|8327|192.65.185.151|None|None|None|None|CONNECT|ACTIVE
package time: 1001066362.0
2001-09-21 11:59:22
elem:  update|A|1001066367.000000|ris|rrc04|None|None|559|192.65.185.130|204.219.88.0/24|192.65.185.130|559 6730 702 6595||None|None
package time: 1001066367.0
2001-09-21 11:59:27
elem:  update|A|1001066367.000000|ris|rrc04|None|None|559|192.65.185.130|204.219.89.0/24|192.65.185.130|559 6730 702 6595||None|None
package time: 1001066367.0
2001-09-21 11:59:27

Do have different collector different time zones? And if it is the case, how to deal with that?

thanks!

@alistairking
Copy link
Member

Hi,
thanks for using BGPStream!

All the timestamps from the library are in UTC.
My best guess is that the range you're giving to Python is being interpreted as local time since you don't specify a timezone.
Can you provide a snippet of Python code to reproduce this issue and we'll take a look.

@cherepanovic
Copy link
Author

cherepanovic commented Mar 23, 2020

thanks for using BGPStream!

thank you too for the existing shared work!

here is the simplest snippet:

    stream = pybgpstream.BGPStream(
        from_time="2001-09-21 09:56:00", until_time="2001-09-21 10:00:00",
        collectors=["rrc04"],
        record_type="updates",  # there is record_type="ribs"
    )
    for rec in stream.records():
        for elem in rec:
            print('elem: ', elem)
            print('package time:', elem.time)
            print(datetime.fromtimestamp(elem.time))

output

elem:  update|S|1001066362.000000|ris|rrc04|None|None|8327|192.65.185.151|None|None|None|None|ACTIVE|CONNECT
package time: 1001066362.0
2001-09-21 11:59:22
elem:  update|S|1001066362.000000|ris|rrc04|None|None|8327|192.65.185.151|None|None|None|None|CONNECT|ACTIVE
package time: 1001066362.0
2001-09-21 11:59:22
elem:  update|A|1001066367.000000|ris|rrc04|None|None|559|192.65.185.130|204.219.88.0/24|192.65.185.130|559 6730 702 6595||None|None
package time: 1001066367.0
2001-09-21 11:59:27
elem:  update|A|1001066367.000000|ris|rrc04|None|None|559|192.65.185.130|204.219.89.0/24|192.65.185.130|559 6730 702 6595||None|None
package time: 1001066367.0
2001-09-21 11:59:27
elem:  update|A|1001066367.000000|ris|rrc04|None|None|559|192.65.185.130|204.219.90.0/24|192.65.185.130|559 6730 702 6595||None|None
package time: 1001066367.0
2001-09-21 11:59:27
elem:  update|A|1001066367.000000|ris|rrc04|None|None|559|192.65.185.130|204.219.90.0/23|192.65.185.130|559 6730 702 6595||None|None
package time: 1001066367.0
2001-09-21 11:59:27
elem:  update|A|1001066367.000000|ris|rrc04|None|None|559|192.65.185.130|204.219.92.0/24|192.65.185.130|559 6730 702 6595||None|None
package time: 1001066367.0
2001-09-21 11:59:27
elem:  update|A|1001066367.000000|ris|rrc04|None|None|559|192.65.185.130|204.219.93.0/24|192.65.185.130|559 6730 702 6595||None|None
package time: 1001066367.0
2001-09-21 11:59:27
elem:  update|A|1001066367.000000|ris|rrc04|None|None|559|192.65.185.130|212.75.226.0/24|192.65.185.130|559 1836 286 3300 13131 13131 13131 13131||None|None
package time: 1001066367.0
2001-09-21 11:59:27

My best guess is that the range you're giving to Python is being interpreted as local time since you don't specify a timezone.

how to deal it and make it consistently?

Thanks!

@alistairking
Copy link
Member

Ah, I see the problem.
You're actually converting the returned timestamp to your local timezone when you do:

datetime.fromtimestamp(elem.time)

See https://docs.python.org/3/library/datetime.html#datetime.date.fromtimestamp which says:

Return the local date corresponding to the POSIX timestamp...

You probably want to use datetime.datetime.utcfromtimestamp instead: https://docs.python.org/3/library/datetime.html#datetime.datetime.utcfromtimestamp

E.g.,:

$ python
>>> import datetime
>>> print datetime.datetime.fromtimestamp(0)
1969-12-31 16:00:00
>>> print datetime.datetime.utcfromtimestamp(0)
1970-01-01 00:00:00

@cherepanovic
Copy link
Author

was my unawareness of libraries knowledge, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants