mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Edit metadata dialog: Fix date fields being displayed in the UTC timezone instead of the local timezone, causing the day to be off by one in some timezones. Fixes #1393166 [Wrong date after edit date in bulk edit metadata form](https://bugs.launchpad.net/calibre/+bug/1393166)
This commit is contained in:
parent
dfbb179cce
commit
77504c31a0
@ -121,7 +121,7 @@ def make_undoable(spinbox):
|
||||
elif hasattr(widget, 'value'):
|
||||
self.undo_val = widget.value()
|
||||
if isinstance(val, date):
|
||||
val = parse_only_date(val.isoformat(), assume_utc=False)
|
||||
val = parse_only_date(val.isoformat(), assume_utc=False, as_utc=False)
|
||||
self.redo_val = val
|
||||
|
||||
def undo(self):
|
||||
@ -173,7 +173,7 @@ def make_undoable(spinbox):
|
||||
self.undo_stack.clear()
|
||||
if hasattr(self, 'setDateTime'):
|
||||
if isinstance(val, date) and not is_date_undefined(val):
|
||||
val = parse_only_date(val.isoformat(), assume_utc=False)
|
||||
val = parse_only_date(val.isoformat(), assume_utc=False, as_utc=False)
|
||||
self.setDateTime(val)
|
||||
elif hasattr(self, 'setValue'):
|
||||
self.setValue(val)
|
||||
|
@ -136,7 +136,7 @@ def parse_date(date_string, assume_utc=False, as_utc=True, default=None):
|
||||
dt = dt.replace(tzinfo=_utc_tz if assume_utc else _local_tz)
|
||||
return dt.astimezone(_utc_tz if as_utc else _local_tz)
|
||||
|
||||
def parse_only_date(raw, assume_utc=True):
|
||||
def parse_only_date(raw, assume_utc=True, as_utc=True):
|
||||
'''
|
||||
Parse a date string that contains no time information in a manner that
|
||||
guarantees that the month and year are always correct in all timezones, and
|
||||
@ -145,7 +145,7 @@ def parse_only_date(raw, assume_utc=True):
|
||||
f = utcnow if assume_utc else now
|
||||
default = f().replace(hour=0, minute=0, second=0, microsecond=0,
|
||||
day=15)
|
||||
ans = parse_date(raw, default=default, assume_utc=assume_utc)
|
||||
ans = parse_date(raw, default=default, assume_utc=assume_utc, as_utc=as_utc)
|
||||
n = ans + timedelta(days=1)
|
||||
if n.month > ans.month:
|
||||
ans = ans.replace(day=ans.day-1)
|
||||
@ -451,5 +451,3 @@ def replace_months(datestr, clang):
|
||||
if tmp != datestr:
|
||||
break
|
||||
return tmp
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user