Example #1
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
Example #2
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())
Example #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())
Example #4
0
def jd_to(jd):
    ## hijriAlg==0
    if hijriUseDB:
        #jd = ifloor(jd)
        date = monthDb.getDateFromJd(jd)
        if date:
            return date
    ##jd = ifloor(jd) + 0.5
    year = ifloor(((30 * (jd - epoch)) + 10646) // 10631)
    month = min(
        12,
        iceil(
            (jd - (29 + to_jd(year, 1, 1))) / 29.5
        ) + 1
    )
    day = jd - to_jd(year, month, 1) + 1
    return year, month, day
Example #5
0
def getJhmsFromEpoch(epoch, local=False):## return a tuple (julain_day, hour, minute, second) from epoch
    #if local:
    #    epoch -= getCurrentTimeZone()
    days, second = divmod(ifloor(epoch), 24*3600)
    return (days+J1970,) + getHmsFromSeconds(second)
Example #6
0
# with this program. If not, see <http://www.gnu.org/licenses/gpl.txt>.
# Also avalable in /usr/share/common-licenses/GPL on Debian systems
# or /usr/share/licenses/common/GPL3/license.txt on ArchLinux

from time import time, localtime
#from time import timezone, altzone, daylight
import datetime
import struct

from scal2.cal_types.gregorian import J1970
from scal2.utils import ifloor, iceil

## time() ~~ epoch
## jd == epoch/(24*3600.0) + J1970
## epoch == (jd-J1970)*24*3600
getJdFromEpoch = lambda epoch: ifloor(epoch//(24*3600) + J1970)
getFloatJdFromEpoch = lambda epoch: epoch/(24.0*3600) + J1970

getEpochFromJd = lambda jd: (jd-J1970)*(24*3600)

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

def getJdListFromEpochRange(startEpoch, endEpoch):
    startJd = getJdFromEpoch(startEpoch)
    endJd = getJdFromEpoch(endEpoch-0.01) + 1
    return range(startJd, endJd)

def getHmsFromSeconds(second):
    minute, second = divmod(int(second), 60)
    hour, minute = divmod(minute, 60)
    return hour, minute, second
Example #7
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)
Example #8
0
    y, m, d = jd_to_g(jd)
    return getUtcOffsetByDateSec(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-1) ## FIXME
    return localEpoch - getUtcOffsetByDateSec(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)
    endJd = getJdFromEpoch(endEpoch-0.01) + 1
    return list(range(startJd, endJd))
Example #9
0
def getUtcOffsetByJd(jd, tz=None):
    y, m, d = jd_to_g(jd)
    return getUtcOffsetByDateSec(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: (epoch + getUtcOffsetByEpoch(epoch))/(24.0*3600) + J1970
#getFloatJdFromEpoch = lambda epoch: datetime.fromtimestamp(epoch).toordinal() - 1 + J0001


getJdFromEpoch = lambda epoch: ifloor(getFloatJdFromEpoch(epoch))


def getEpochFromJd(jd, tz=None):
    localEpoch = (jd-J1970) * 24*3600
    year, month, day = jd_to_g(jd-1) ## FIXME
    return localEpoch - getUtcOffsetByDateSec(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)
    endJd = getJdFromEpoch(endEpoch-0.01) + 1
    return list(range(startJd, endJd))
Example #10
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)
Example #11
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):