730 questions
0
votes
0
answers
102
views
pytz library timezone conversion issue [duplicate]
I am trying to work with django and converting timezones between UTC and my timezone ("America/Winnipeg"), but I keep running into issues and I think there might be a bug. Here is my code:
#...
0
votes
1
answer
53
views
Rendering datetime and proper formatting
I have a Django project to keep track of tasks in an office environment. I have this model for tasks, and it has a finish_date attribute that is assigned as soon as I access the route to do the ...
1
vote
2
answers
108
views
In python (pytz), how can I add a "day" to a datetime in a DST-aware fashion? (Sometimes the result should be 23 or 25 hours in in the future)
I'm doing some datetime math in python with the pytz library (although I'm open to using other libraries if necessary). I have an iterator that needs to increase by one day for each iteration of the ...
0
votes
1
answer
34
views
use closing hours by default
Using this piece of the pytz script,
import dateutil
import pytz
utc = pytz.UTC
print(utc.localize(dateutil.parser.parse('2024-10-31')))
the output shows:
2024-10-31 00:00:00+00:00
We want to ...
1
vote
0
answers
44
views
Possible faulty python datetime/pytz module behaviour [duplicate]
I think there may be a problem with the pytz/datetime module in python. Either that or I am not using it correctly.
Please look at the coding below which highlights the issues I'm currently facing. I'...
0
votes
0
answers
57
views
pandas timezones conversion malfunction [duplicate]
Trying to build an algorithm for processing stocks. I'm not a dev, so basically my knowledge is limited.
I'm retrieving findata with an API. Looks like it's done correctly, sorted ascending. First ...
0
votes
1
answer
90
views
Python's America/New_York time offset showing -04:56 [duplicate]
I'm currently using Python 3.9.6 and have this simple code
import datetime
import pytz
est = pytz.timezone('America/New_York')
myDateTime = datetime.datetime(year=2024, month=8, day=15, hour=17, ...
1
vote
1
answer
70
views
Datetime doesn't seem to be converting
I am trying to cast from a 'created_at' value in UTC to a value in Eastern Time. But after converting the time using astimezone, the time is the same and raises the assert error that the two times are ...
0
votes
0
answers
46
views
Unexpected difference when subtracting the same time from two different time zones? Python [duplicate]
The total second difference between 2 datetime objects set in different time zones but on the same date does not yield 0.0 in some circumstances.
import datetime
from pytz import timezone
from ...
1
vote
1
answer
410
views
zoneinfo is missing timezone names that pytz has
I am comparing the timezone names that pytz and zoneinfo support because I would like to transition to zoneinfo from pytz.
It seems that zoneinfo lacks a lot of timezones:
>>> import pytz
>...
2
votes
1
answer
66
views
How to get the epoch value for any given Local Time with Time Zone & Daylight Saving Time in Python?
I'm new to Python and I have a use case which deals with datetime. Unfortunately, the data is not in UTC, so I have to rely on Local Time, Time Zones & Daylight Savings. I tried with datetime &...
0
votes
0
answers
39
views
Issues with pytz.timezone in threading.Thread
I ran across an interesting bug yesterday with using pytz.timezone in a threading.Thread. When running the example code below, the Consumer.run() method appears to crash after the 1st iteration i.e., ...
0
votes
1
answer
1k
views
Python UTC America/New York Time Conversion
Working on a problem where I have to evaluate whether a time stamp (UTC) exceeds 7PM Americas/New_York.
I naively did my check as:
if (timestamp - timedelta(hours=4)).time() > 19:
__logic__
...
0
votes
1
answer
222
views
mktime resulting in OverflowError: mktime argument out of range
When attempting to get a time using mktime, I get a overflow exception. This occurs on a Debian docker image, but not on my host machine:
docker pull python:3.9.7
https://hub.docker.com/layers/...
1
vote
1
answer
68
views
Handling Local Time in Python Worldwide
I am working on an application in which events occur at specific times. The event creator can create events in a time zone where daylight saving time might or might not be applicable. Therefore, the ...
0
votes
2
answers
139
views
datetime module is not working properly on vps
my code works properly in local machine:
from datetime import datetime
import pytz
def convert_time(timestamp):
formats = ['%a, %d %b %Y %H:%M:%S %Z',
'%a, %d %b %Y %H:%M:%S %z',
...
0
votes
0
answers
55
views
Timezone conversion failed due to winter hour change pytz
in my code I am trying to convert a date with pytz timezone, but due to the change to winter hour at 3 am, my code crash. I have two questions : one, why does changing hours makes the timezone ...
-1
votes
1
answer
389
views
Local start and end of day in UTC
I would like to find out what the start and end time of a specific day is expressed in UTC and in Python.
For instance:
the current date and time is Sun 29 Oct 2023, 01:33:49 CEST (Central European ...
1
vote
1
answer
358
views
Getting NonExistentTimeError in pytz
With this example:
import pandas as pd
import pytz
timestamp = pd.Timestamp('2023-04-30 02:20:28.594000')
timezone = pytz.timezone('Africa/Casablanca')
print(
timestamp.tz_localize(timezone, ...
1
vote
1
answer
216
views
Why do these datetime conversions using pytz not land on hours before December of 1901?
Perhaps I am not using the libraries correctly, or perhaps there was some kind of standard change on December 15, 1901 concerning world wide time keeping. But I stumbled across this odd behavior while ...
1
vote
0
answers
258
views
Python Time Zone issue with pytz module
I have written a code to deal with datetime but it is giving inconsistent results.:
def date_time_conversion(str_dt):
brussels = pytz.timezone("Europe/Brussels")
converted_date = ...
3
votes
1
answer
2k
views
Python pytz, zoneinfo and daylight savings time
I am currently attempting to migrate a code base from using pytz to using Python's zoneinfo library. I've run into an issue with how zoneinfo handles daylight saving time transitions when compared to ...
0
votes
2
answers
216
views
How to convert difference in hours to timezone in python?
I am currently working with apscheduler with multiple users located in different timezones.
There is no possibility to get the timezone from them automatically, so I need to do this with input data. ...
1
vote
1
answer
280
views
PYTZ python is incorrectly adjusting for daylight saving on timezone Mexico_City
is PYTZ **incorrectly ** observing daylight saving for timezone Mexico_City ?
I think daylight saving is no longer observed in Mexico asper this article:
https://time.is/time_zone_news/...
15
votes
1
answer
9k
views
Is `pytz` deprecated now or in the future in Python?
pytz is used in the Django version: <=3.2 doc Selecting the current time zone as shown below:
import pytz # Here
from django.utils import timezone
class TimezoneMiddleware:
def __init__(self, ...
0
votes
1
answer
176
views
pandas how to override attibute error from timezome localization
I have a idaydf.index that I am trying to localize timezone
DatetimeIndex(['2022-10-24 16:00:00', '2022-10-24 16:15:00',
...
'2023-06-16 21:58:00', '2023-06-16 22:00:00'],...
0
votes
1
answer
481
views
Convert ZoneInfo to Pytz timezone name
I have a datetime string such as date = "2023-06-16T07:46:00-03:00"
Extracting timezone information from it give me the following results:
>>> formatted_date = datetime.strptime(...
0
votes
0
answers
51
views
Python String to TimeZone Aware ISO8601 datetime format [duplicate]
from datetime import datetime
import pytz
some_date = "2019-01-01"
tzone = "America/Los_Angeles"
print(tzone)
iso_datetime = datetime.strptime(some_date , "%Y-%m-%d")....
0
votes
1
answer
893
views
How to calculate current time in different timezone correctly in Python
I was trying to calculate the current time in NYC (EST time aka Eastern Daylight time or GMT-4) given current time in Israel (Israel daylight time, currently GMT+3) where I'm currently located. So ...
0
votes
1
answer
83
views
Python Time zone conversion confusion
I have this simple function and test here:
def convert_to_current_time_zone(server_time, test_timezone = None):
"""
Converts a time from server time to the users time zone, taking ...
0
votes
1
answer
132
views
Datetime Invalid Comparison Error with PYTZ
I keep getting the following error when trying to filter my dataframe on datetime objects: TypeError: Invalid comparison between dtype=datetime64[ns, pytz.FixedOffset(120)] and DatetimeArray. This is ...
0
votes
1
answer
248
views
Difference seen when time is converted between strptime and strftime while using pytz and datetime module
original_value = (datetime.datetime.now(pytz.utc)) + datetime.timedelta(minutes=30)
current_schedule = original_value..strftime("%Y-%m-%dT%H:%M:%S.%fZ")
new_value = datetime.datetime....
3
votes
4
answers
3k
views
Type hint pytz timezone
I have a function that returns a pytz.timezone('...') object. For example for the function below, what should be the type hint for the return?
def myfunc(tz_str: str) -> ????:
return pytz....
2
votes
0
answers
595
views
Python pytz astimezone adding extra 56 minutes when converting New York time to London time [duplicate]
My code of pytz astimezone as below adds extra 56 minutes when converting New York time to London time, when it is not for year 1900.
The other similar questions seem to be converting to or from a ...
0
votes
1
answer
197
views
How to change line to use local timezone (Europe/Ljubljana)? [duplicate]
I'm trying to change:
pytz.timezone('Europe/Ljubljana').localize(datetime.datetime.now().replace(microsecond=0))
to print time in Europe/Ljubljana but it still has offset of 2 hours (uses UTC and not ...
0
votes
1
answer
705
views
'2023-02-07 10:49:00' instead of '2023-02-07 05:49:00'
I am very confused right now. Here is the timestamp 1675766940000. What is the time using this time format %Y-%m-%d %H:%M:%S. On my local machine, the answer is '2023-02-07 05:49:00' and on a docker ...
4
votes
0
answers
4k
views
pytz and ZoneInfo return different times for same functions. What's wrong with my implementation? [duplicate]
I am trying to add a timezone to a time without timezone. However, using 2 libraries gives 2 different results:
from datetime import datetime
import pytz
from zoneinfo import ZoneInfo
cur = datetime....
0
votes
1
answer
73
views
Conflicting localized datetime object for same timezone
I am getting two different time offset using US/Eastern pytz timezone.
>>> from pytz import timezone
import datetime
tz = timezone('US/Eastern')
>>> tz.localize(...
0
votes
1
answer
473
views
The zone attribute is specific to pytz's interface; please migrate to a new time zone provider
I need to filter the lines where the date is today and not more than 2 hours ago according to local time (the code needs to be malleable as I travel to different timezones):
from tzlocal import ...
0
votes
0
answers
246
views
Comparing pytz.timezone instances
I need to compare pytz.timezones for equality, and the behavior I'm observing is quite unintuitive.
I've read a lot about Python time zones, pytz, zoneinfo, LMT, etc., both on SO and generally on the ...
2
votes
0
answers
2k
views
Unable to import pytz module in python 3
I am trying to import pytz module to get timezone.. but the code doesn't seem to be working as expected and it is throwing some ModuleNotFoundError exception which i think are dependent to pytz module ...
3
votes
1
answer
634
views
Localize time zone based on column in pandas
I am trying to assign a timezone to a datetime column, based on another column containing the time zone.
Example data:
DATETIME VALUE TIME_ZONE
0 2021-05-01 00:00:00 1....
1
vote
2
answers
217
views
Check whether timezone is dateutil.tz instance
There are several Python packages that implement the datetime.tzinfo interface, including pytz and dateutil. If someone hands me a timezone object and wants me to apply it to a datetime, the ...
0
votes
1
answer
332
views
How to convert time zone from user input? using python
I need to convert time and time zone from user input to 'America/New_York'
,,,,py
import datetime
import pytz
user_inp_time =input("What is your hour? " )
user_inp_tz = input("Your ...
0
votes
0
answers
97
views
using pytz library, convert a list of utc offsets (e.g. UTC-10:00) to named time zones (e.g. Pacific/Honolulu)
i`m trying to translate this list of utc offsets:
['UTC-12:00','UTC-11:00','UTC-10:00','UTC-09:00','UTC-08:00','UTC-07:00','UTC-06:00','UTC-05:00','UTC-04:00','UTC+10:00','UTC+12:00']
into a list of ...
1
vote
1
answer
647
views
Why is python's datetime conversion wrong in one direction? [duplicate]
I am trying to convert a timezone aware datetime.datetime object to UTC and make it naive. For the conversion, I use the following code:
from datetime import datetime
import pytz
dt: datetime = ...
-1
votes
1
answer
1k
views
List of all timezones listed in pytz.all_timezones
I've been searching around for the contents of pytz.all_timezones, but have found nothing. Just people saying "Use pytz.all_timezones" but that would mean I'd have to copy every single ...
0
votes
1
answer
560
views
Efficiently localize an array of datetimes with pytz
What is the most efficient way of converting an array of naive datetime.datetime objects to an array of timezone-aware datetime objects?
Currently I have them in a numpy array. The answer doesn't ...
3
votes
3
answers
3k
views
Timezone obtained via TimezoneFinder, 'America/Ciudad_Juarez', generates error UnknowTimeZone with pytz
I retrieve timezones from airports of the world, using TimezoneFinder().timezone_at applied on longitude and latitude of airports. And when I want to use these timezones (to compute times of departure ...
0
votes
0
answers
43
views
Timezone converter using python
I have created a timezone converter using python using libraries like pytz and datetime
Is there a way to make it without using any libraries