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'):
|
elif hasattr(widget, 'value'):
|
||||||
self.undo_val = widget.value()
|
self.undo_val = widget.value()
|
||||||
if isinstance(val, date):
|
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
|
self.redo_val = val
|
||||||
|
|
||||||
def undo(self):
|
def undo(self):
|
||||||
@ -173,7 +173,7 @@ def make_undoable(spinbox):
|
|||||||
self.undo_stack.clear()
|
self.undo_stack.clear()
|
||||||
if hasattr(self, 'setDateTime'):
|
if hasattr(self, 'setDateTime'):
|
||||||
if isinstance(val, date) and not is_date_undefined(val):
|
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)
|
self.setDateTime(val)
|
||||||
elif hasattr(self, 'setValue'):
|
elif hasattr(self, 'setValue'):
|
||||||
self.setValue(val)
|
self.setValue(val)
|
||||||
|
@ -28,18 +28,18 @@ class SafeLocalTimeZone(tzlocal):
|
|||||||
#
|
#
|
||||||
# The code above yields the following result:
|
# The code above yields the following result:
|
||||||
#
|
#
|
||||||
#>>> import tz, datetime
|
# >>> import tz, datetime
|
||||||
#>>> t = tz.tzlocal()
|
# >>> t = tz.tzlocal()
|
||||||
#>>> datetime.datetime(2003,2,15,23,tzinfo=t).tzname()
|
# >>> datetime.datetime(2003,2,15,23,tzinfo=t).tzname()
|
||||||
#'BRDT'
|
# 'BRDT'
|
||||||
#>>> datetime.datetime(2003,2,16,0,tzinfo=t).tzname()
|
# >>> datetime.datetime(2003,2,16,0,tzinfo=t).tzname()
|
||||||
#'BRST'
|
# 'BRST'
|
||||||
#>>> datetime.datetime(2003,2,15,23,tzinfo=t).tzname()
|
# >>> datetime.datetime(2003,2,15,23,tzinfo=t).tzname()
|
||||||
#'BRST'
|
# 'BRST'
|
||||||
#>>> datetime.datetime(2003,2,15,22,tzinfo=t).tzname()
|
# >>> datetime.datetime(2003,2,15,22,tzinfo=t).tzname()
|
||||||
#'BRDT'
|
# 'BRDT'
|
||||||
#>>> datetime.datetime(2003,2,15,23,tzinfo=t).tzname()
|
# >>> datetime.datetime(2003,2,15,23,tzinfo=t).tzname()
|
||||||
#'BRDT'
|
# 'BRDT'
|
||||||
#
|
#
|
||||||
# Here is a more stable implementation:
|
# Here is a more stable implementation:
|
||||||
#
|
#
|
||||||
@ -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)
|
dt = dt.replace(tzinfo=_utc_tz if assume_utc else _local_tz)
|
||||||
return dt.astimezone(_utc_tz if as_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
|
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
|
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
|
f = utcnow if assume_utc else now
|
||||||
default = f().replace(hour=0, minute=0, second=0, microsecond=0,
|
default = f().replace(hour=0, minute=0, second=0, microsecond=0,
|
||||||
day=15)
|
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)
|
n = ans + timedelta(days=1)
|
||||||
if n.month > ans.month:
|
if n.month > ans.month:
|
||||||
ans = ans.replace(day=ans.day-1)
|
ans = ans.replace(day=ans.day-1)
|
||||||
@ -451,5 +451,3 @@ def replace_months(datestr, clang):
|
|||||||
if tmp != datestr:
|
if tmp != datestr:
|
||||||
break
|
break
|
||||||
return tmp
|
return tmp
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user