Skip to content

Commit

Permalink
Fix calendar year duration in various duration funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
mk-fg committed Dec 17, 2024
1 parent 2fe4611 commit 355a3aa
Show file tree
Hide file tree
Showing 13 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions desktop/alarm
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ get_logger = lambda name: LogStyleAdapter(logging.getLogger(name))


_short_ts_days = dict(
y=365.25, yr=365.25, year=365.25,
y=365.2422, yr=365.2422, year=365.2422,
mo=30.5, month=30.5, w=7, week=7, d=1, day=1 )
_short_ts_s = dict(
h=3600, hr=3600, hour=3600,
Expand Down Expand Up @@ -99,7 +99,7 @@ def parse_timestamp(ts_str):

def naturaltime_diff( ts, ts0=None, ext=None,
_units=dict( h=3600, m=60, s=1,
y=365.25*86400, mo=30.5*86400, w=7*86400, d=1*86400 ) ):
y=365.2422*86400, mo=30.5*86400, w=7*86400, d=1*86400 ) ):
delta = abs(
(ts - (ts0 or datetime.now()))
if not isinstance(ts, timedelta) else ts )
Expand Down
6 changes: 3 additions & 3 deletions desktop/hamster-tally
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class adict(dict):
self.__dict__ = self


_td_days = dict( y=365.25, yr=365.25,
year=365.25, mo=30.5, month=30.5, w=7, week=7, d=1, day=1 )
_td_days = dict( y=365.2422, yr=365.2422,
year=365.2422, mo=30.5, month=30.5, w=7, week=7, d=1, day=1 )
_td_s = dict( h=3600, hr=3600, hour=3600,
m=60, min=60, minute=60, s=1, sec=1, second=1 )
def _td_re():
Expand Down Expand Up @@ -66,7 +66,7 @@ def td_parse(td_str, to_float=True):

def td_repr( ts, ts0=None, units_max=2, units_res=None,
_units=dict( h=3600, m=60, s=1,
y=365.25*86400, mo=30.5*86400, w=7*86400, d=1*86400 ) ):
y=365.2422*86400, mo=30.5*86400, w=7*86400, d=1*86400 ) ):
delta = ts if ts0 is None else (ts - ts0)
if isinstance(delta, dt.timedelta): delta = delta.total_seconds()
res, s, n_last = list(), abs(delta), units_max - 1
Expand Down
2 changes: 1 addition & 1 deletion desktop/media/audio-split-m4b
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class adict(dict):
self.__dict__ = self

def td_repr( ts, ts0=None, units_max=2, units_res=None, printf=None,
_units=dict(h=3600,m=60,s=1,y=365.25*86400,mo=30.5*86400,w=7*86400,d=1*86400) ):
_units=dict(h=3600,m=60,s=1,y=365.2422*86400,mo=30.5*86400,w=7*86400,d=1*86400) ):
if ts0 is None and isinstance(ts, dt.datetime): ts0 = dt.datetime.now()
delta = ts if ts0 is None else (ts - ts0)
if isinstance(delta, dt.timedelta): delta = delta.total_seconds()
Expand Down
2 changes: 1 addition & 1 deletion desktop/media/pick-tracks
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def size_human_parse(size):

def time_diff_str( ts, ts0=None, now='now', ext=None,
_units=dict( h=3600, m=60, s=1,
y=365.25*86400, mo=30.5*86400, w=7*86400, d=1*86400 ) ):
y=365.2422*86400, mo=30.5*86400, w=7*86400, d=1*86400 ) ):
res, s = list(), abs( (ts - ts0) if ts0 is not None
and not getattr(ts, 'total_seconds', False) else ts )
if not isinstance(s, (int, float)): s = s.total_seconds()
Expand Down
2 changes: 1 addition & 1 deletion desktop/media/tomkv
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def sz_repr(size, _units=list(
return f'{size}{u}'

def td_repr(delta, units_max=2, units_res=None, _units=dict(
h=3600, m=60, s=1, y=365.25*86400, mo=30.5*86400, w=7*86400, d=1*86400 )):
h=3600, m=60, s=1, y=365.2422*86400, mo=30.5*86400, w=7*86400, d=1*86400 )):
res, s, n_last = list(), abs(delta), units_max - 1
units = sorted(_units.items(), key=lambda v: v[1], reverse=True)
for unit, unit_s in units:
Expand Down
4 changes: 2 additions & 2 deletions desktop/media/toogg
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ get_logger = lambda name: LogStyleAdapter(logging.getLogger(name))
err_fmt = lambda err: f'[{err.__class__.__name__}] {err}'

_td_days = dict(
y=365.25, yr=365.25, year=365.25,
y=365.2422, yr=365.2422, year=365.2422,
mo=30.5, month=30.5, w=7, week=7, d=1, day=1 )
_td_s = dict( h=3600, hr=3600, hour=3600,
m=60, min=60, minute=60, s=1, sec=1, second=1, ms=1e-3 )
Expand Down Expand Up @@ -56,7 +56,7 @@ def parse_pos_spec(pos):

def td_repr( ts, ts0=None, units_max=2, units_res=None,
_units=dict( h=3600, m=60, s=1,
y=365.25*86400, mo=30.5*86400, w=7*86400, d=1*86400 ) ):
y=365.2422*86400, mo=30.5*86400, w=7*86400, d=1*86400 ) ):
delta = ts if ts0 is None else (ts - ts0)
if isinstance(delta, dt.timedelta): delta = ts.total_seconds()
res, s, n_last = list(), abs(delta), units_max - 1
Expand Down
2 changes: 1 addition & 1 deletion desktop/notifications/aqm-alerts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import zmq # pyzmq
err_fmt = lambda err: f'[{err.__class__.__name__}] {err}'

_tds = dict(
y=365.25 * 86400, yr=365.25 * 86400, year=365.25 * 86400,
y=365.2422 * 86400, yr=365.2422 * 86400, year=365.2422 * 86400,
mo=30.5 * 86400, month=30.5 * 86400,
w=7 * 86400, wk=7 * 86400, week=7 * 86400, d=1 * 86400, day=1 * 86400,
h=3600, hr=3600, hour=3600,
Expand Down
2 changes: 1 addition & 1 deletion desktop/rss-get
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def name_dedup(name, name_set, n=3):

def ts_diff_str( ts, ts0=None, ext=None, sep='',
_units=dict( h=3600, m=60, s=1,
y=365.25*86400, mo=30.5*86400, w=7*86400, d=1*86400 ) ):
y=365.2422*86400, mo=30.5*86400, w=7*86400, d=1*86400 ) ):
delta = abs(
(ts - (ts0 or dt.datetime.now()))
if not isinstance(ts, dt.timedelta) else ts )
Expand Down
2 changes: 1 addition & 1 deletion lsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def mtime_parse(mtimes, err_func):
import datetime as dt
ts_now = dt.datetime.now()
_td_days = dict(
y=365.25, yr=365.25, year=365.25,
y=365.2422, yr=365.2422, year=365.2422,
mo=30.5, month=30.5, w=7, week=7, d=1, day=1 )
_td_s = dict( h=3600, hr=3600, hour=3600,
m=60, min=60, minute=60, s=1, sec=1, second=1 )
Expand Down
4 changes: 2 additions & 2 deletions metrics/rrd-sensors-logger
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ def _data_hash(data, as_bencode=False, as_hex=False):

class TSValueError(Exception): pass

_short_ts_days = dict(y=365.25, yr=365.25, mo=30.5, w=7, d=1)
_short_ts_days = dict(y=365.2422, yr=365.2422, mo=30.5, w=7, d=1)
_short_ts_s = dict(h=3600, hr=3600, m=60, min=60, s=1, sec=1)

def _short_ts_regexp():
Expand Down Expand Up @@ -345,7 +345,7 @@ def ts_diff_parse(spec, t=float, as_td_obj=False):

def ts_diff_repr( ts_or_delta, ts0=None, ext=None, absolute_diff=False,
_units=dict( h=3600, m=60, s=1,
y=365.25*86400, mo=30.5*86400, w=7*86400, d=1*86400 ) ):
y=365.2422*86400, mo=30.5*86400, w=7*86400, d=1*86400 ) ):
if isinstance(ts0, (int, float)): ts0 = dt.datetime.fromtimestamp(ts_or_delta)
assert ts0 is None or isinstance(ts0, (int, float, dt.datetime)), ts0
if isinstance(ts_or_delta, (int, float)):
Expand Down
4 changes: 2 additions & 2 deletions sleepc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import os, sys, re, math, time, datetime as dt


_td_days = dict(
y=365.25, yr=365.25, year=365.25,
y=365.2422, yr=365.2422, year=365.2422,
mo=30.5, month=30.5, w=7, week=7, d=1, day=1 )
_td_s = dict( h=3600, hr=3600, hour=3600,
m=60, min=60, minute=60, s=1, sec=1, second=1 )
Expand Down Expand Up @@ -68,7 +68,7 @@ def ts_parse(ts_str, ts_now=None):

def ts_repr( ts, ts0=None, units_max=2, units_res=None, printf=None,
_units=dict( h=3600, m=60, s=1,
y=365.25*86400, mo=30.5*86400, w=7*86400, d=1*86400 ) ):
y=365.2422*86400, mo=30.5*86400, w=7*86400, d=1*86400 ) ):
if ts0 is None and isinstance(ts, dt.datetime): ts0 = dt.datetime.now()
delta = ts if ts0 is None else (ts - ts0)
if isinstance(delta, dt.timedelta): delta = delta.total_seconds()
Expand Down
2 changes: 1 addition & 1 deletion term-pipe
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def get_dbus_notify_func(**defaults):

def naturaltime_diff( ts, ts0, ext=None,
_units=dict( h=3600, m=60, s=1,
y=365.25*86400, mo=30.5*86400, w=7*86400, d=1*86400 ) ):
y=365.2422*86400, mo=30.5*86400, w=7*86400, d=1*86400 ) ):
delta = abs((ts - ts0) if not getattr(ts, 'total_seconds', False) else ts)

res, s = list(), delta.total_seconds()
Expand Down
2 changes: 1 addition & 1 deletion znc-log-reader
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def chan_name(name):


_td_days = dict(
y=365.25, yr=365.25, year=365.25,
y=365.2422, yr=365.2422, year=365.2422,
mo=30.5, month=30.5, w=7, week=7, d=1, day=1 )
_td_s = dict( h=3600, hr=3600, hour=3600,
m=60, min=60, minute=60, s=1, sec=1, second=1 )
Expand Down

0 comments on commit 355a3aa

Please sign in to comment.