global: snapshot

This commit is contained in:
nym21
2026-03-01 12:46:07 +01:00
parent e10013fd2c
commit 7bf0220f25
35 changed files with 1450 additions and 2044 deletions

View File

@@ -55,7 +55,7 @@ const _MS_PER_DAY = 86400000;
const _MS_PER_WEEK = 7 * _MS_PER_DAY;
const _EPOCH_MS = 1230768000000;
const _DATE_INDEXES = new Set([
'minute1', 'minute5', 'minute10', 'minute30',
'minute10', 'minute30',
'hour1', 'hour4', 'hour12',
'day1', 'day3', 'week1',
'month1', 'month3', 'month6',
@@ -73,8 +73,6 @@ const _addMonths = (months) => new Date(2009, months, 1);
*/
function indexToDate(index, i) {{
switch (index) {{
case 'minute1': return new Date(_EPOCH_MS + i * 60000);
case 'minute5': return new Date(_EPOCH_MS + i * 300000);
case 'minute10': return new Date(_EPOCH_MS + i * 600000);
case 'minute30': return new Date(_EPOCH_MS + i * 1800000);
case 'hour1': return new Date(_EPOCH_MS + i * 3600000);
@@ -102,8 +100,6 @@ function indexToDate(index, i) {{
function dateToIndex(index, d) {{
const ms = d.getTime();
switch (index) {{
case 'minute1': return Math.floor((ms - _EPOCH_MS) / 60000);
case 'minute5': return Math.floor((ms - _EPOCH_MS) / 300000);
case 'minute10': return Math.floor((ms - _EPOCH_MS) / 600000);
case 'minute30': return Math.floor((ms - _EPOCH_MS) / 1800000);
case 'hour1': return Math.floor((ms - _EPOCH_MS) / 3600000);

View File

@@ -136,7 +136,7 @@ _GENESIS = date(2009, 1, 3) # day1 0, week1 0
_DAY_ONE = date(2009, 1, 9) # day1 1 (6 day gap after genesis)
_EPOCH = datetime(2009, 1, 1, tzinfo=timezone.utc)
_DATE_INDEXES = frozenset([
'minute1', 'minute5', 'minute10', 'minute30',
'minute10', 'minute30',
'hour1', 'hour4', 'hour12',
'day1', 'day3', 'week1',
'month1', 'month3', 'month6',
@@ -145,11 +145,7 @@ _DATE_INDEXES = frozenset([
def _index_to_date(index: str, i: int) -> Union[date, datetime]:
"""Convert an index value to a date/datetime for date-based indexes."""
if index == 'minute1':
return _EPOCH + timedelta(minutes=i)
elif index == 'minute5':
return _EPOCH + timedelta(minutes=i * 5)
elif index == 'minute10':
if index == 'minute10':
return _EPOCH + timedelta(minutes=i * 10)
elif index == 'minute30':
return _EPOCH + timedelta(minutes=i * 30)
@@ -187,13 +183,13 @@ def _date_to_index(index: str, d: Union[date, datetime]) -> int:
Returns the floor index (latest index whose date is <= the given date).
For sub-day indexes (minute*, hour*), a plain date is treated as midnight UTC.
"""
if index in ('minute1', 'minute5', 'minute10', 'minute30', 'hour1', 'hour4', 'hour12'):
if index in ('minute10', 'minute30', 'hour1', 'hour4', 'hour12'):
if isinstance(d, datetime):
dt = d if d.tzinfo else d.replace(tzinfo=timezone.utc)
else:
dt = datetime(d.year, d.month, d.day, tzinfo=timezone.utc)
secs = int((dt - _EPOCH).total_seconds())
div = {{'minute1': 60, 'minute5': 300, 'minute10': 600, 'minute30': 1800,
div = {{'minute10': 600, 'minute30': 1800,
'hour1': 3600, 'hour4': 14400, 'hour12': 43200}}
return secs // div[index]
dd = d.date() if isinstance(d, datetime) else d