Exemple #1
0
def getJhmsFromEpoch(epoch, currentOffset=False, tz=None):
	## return a tuple (julain_day, hour, minute, second) from epoch
	offset = (
		getUtcOffsetCurrent(tz) if currentOffset
		else getUtcOffsetByEpoch(epoch, tz)
	)  # FIXME
	days, second = divmod(ifloor(epoch + offset), 24 * 3600)
	return (days + J1970,) + getHmsFromSeconds(second)
Exemple #2
0
def getJhmsFromEpoch(epoch, currentOffset=False, tz=None):
	## return a tuple (julain_day, hour, minute, second) from epoch
	offset = (
		getUtcOffsetCurrent(tz) if currentOffset
		else getUtcOffsetByEpoch(epoch, tz)
	)  # FIXME
	days, second = divmod(ifloor(epoch + offset), 24 * 3600)
	return (days + J1970,) + getHmsFromSeconds(second)
Exemple #3
0
def getYearRangeTickValues(u0, y1, minStepYear):
    data = {}
    step = 10**max(0, ifloor(log10(y1 - u0)) - 1)
    u0 = step * (u0 // step)
    for y in range(u0, y1, step):
        n = 10**getNum10Pow(y)
        if n >= minStepYear:
            data[y] = n
    if u0 <= 0 <= y1:
        data[0] = max(data.values())
    return sorted(data.items())
Exemple #4
0
def jd_to(jd):
    ## hijriAlg==0
    if hijriUseDB:
        #jd = ifloor(jd)
        date = monthDb.getDateFromJd(jd)
        if date:
            return date
    year = ifloor(((30 * (jd - 1 - epoch)) + 10646) // 10631)
    month = min(12, iceil((jd - (29 + to_jd_c(year, 1, 1))) / 29.5) + 1)
    day = jd - to_jd_c(year, month, 1) + 1
    return year, month, day
Exemple #5
0
def getYearRangeTickValues(u0, y1, minStepYear):
    data = {}
    step = 10 ** max(0, ifloor(log10(y1 - u0)) - 1)
    u0 = step * (u0//step)
    for y in range(u0, y1, step):
        n = 10 ** getNum10Pow(y)
        if n >= minStepYear:
            data[y] = n
    if u0 <= 0 <= y1:
        data[0] = max(data.values())
    return sorted(data.items())
Exemple #6
0
def jd_to(jd):
	## hijriAlg==0
	if hijriUseDB:
		#jd = ifloor(jd)
		date = monthDb.getDateFromJd(jd)
		if date:
			return date
	year = ifloor(((30 * (jd - 1 - epoch)) + 10646) // 10631)
	month = min(
		12,
		iceil(
			(jd - (29 + to_jd_c(year, 1, 1))) / 29.5
		) + 1
	)
	day = jd - to_jd_c(year, month, 1) + 1
	return year, month, day
Exemple #7
0
def getUtcOffsetByJd(jd, tz=None):
    y, m, d = jd_to_g(jd)
    return getUtcOffsetByGDate(y, m, d, tz)


getUtcOffsetCurrent = lambda tz=None: getUtcOffsetByEpoch(now(), tz)
# getUtcOffsetCurrent = lambda: -time.altzone if time.daylight and localtime().tm_isdst else -time.timezone

getGtkTimeFromEpoch = lambda epoch: int((epoch - 1.32171528839e9) * 1000 // 1)


getFloatJdFromEpoch = lambda epoch, tz=None: (epoch + getUtcOffsetByEpoch(epoch, tz)) / (24.0 * 3600) + J1970
# getFloatJdFromEpoch = lambda epoch: datetime.fromtimestamp(epoch).toordinal() - 1 + J0001


getJdFromEpoch = lambda epoch, tz=None: ifloor(getFloatJdFromEpoch(epoch, tz))


def getEpochFromJd(jd, tz=None):
    localEpoch = (jd - J1970) * 24 * 3600
    year, month, day = jd_to_g(jd)  ## jd or jd-1? FIXME
    return localEpoch - getUtcOffsetByGDate(year, month, day, tz)


# getEpochFromJd = lambda jd: int(mktime(datetime.fromordinal(int(jd)-J0001+1).timetuple()))

roundEpochToDay = lambda epoch: getEpochFromJd(round(getFloatJdFromEpoch(epoch)))


def getJdListFromEpochRange(startEpoch, endEpoch):
    startJd = getJdFromEpoch(startEpoch)
Exemple #8
0
def getJdFromEpoch(epoch, tz=None):
	return ifloor(getFloatJdFromEpoch(epoch, tz))
Exemple #9
0
def getUtcOffsetByJd(jd, tz=None):
    y, m, d = jd_to_g(jd)
    return getUtcOffsetByGDate(y, m, d, tz)


getUtcOffsetCurrent = lambda tz=None: getUtcOffsetByEpoch(now(), tz)
#getUtcOffsetCurrent = lambda: -time.altzone if time.daylight and localtime().tm_isdst else -time.timezone

getGtkTimeFromEpoch = lambda epoch: int((epoch - 1.32171528839e+9) * 1000 // 1)


getFloatJdFromEpoch = lambda epoch, tz=None: \
    (epoch + getUtcOffsetByEpoch(epoch, tz)) / (24.0*3600) + J1970
#getFloatJdFromEpoch = lambda epoch: datetime.fromtimestamp(epoch).toordinal() - 1 + J0001

getJdFromEpoch = lambda epoch, tz=None: ifloor(getFloatJdFromEpoch(epoch, tz))


def getEpochFromJd(jd, tz=None):
    localEpoch = (jd - J1970) * 24 * 3600
    year, month, day = jd_to_g(jd)  ## jd or jd-1? FIXME
    return localEpoch - getUtcOffsetByGDate(year, month, day, tz)


#getEpochFromJd = lambda jd: int(mktime(datetime.fromordinal(int(jd)-J0001+1).timetuple()))

roundEpochToDay = lambda epoch: getEpochFromJd(
    round(getFloatJdFromEpoch(epoch)))


def getJdListFromEpochRange(startEpoch, endEpoch):
Exemple #10
0
def getJdFromEpoch(epoch, tz=None):
	return ifloor(getFloatJdFromEpoch(epoch, tz))