JDManipulator.py 2.15 KB
import datetime
import time
from decimal import *

JD_VALUE = 86400
TIMESTAMP_JD = 2440587.500000
DAILY_SECOND = 1 / 86400

def JulianSeconds(value):
    return (Decimal(value * DAILY_SECOND))

def getPreciseCurrentTime():
    return (Decimal(getCurrentTime()))

def getPreciseNightStart():
    return (Decimal(getNightStart()))

def getPreciseNightEnd():
    return (Decimal(getNightEnd()))

def secondsToJulianDate(time_seconds):
    return (time_seconds / 86400 + TIMESTAMP_JD)

def julianDateToSeconds(time_julian):
    return ((time_julian - TIMESTAMP_JD) * 86400)

def getCurrentTime():
    current_time = datetime.datetime.now()
    return (time.mktime(current_time.timetuple()))

def getNextDefaultNightStart():
    current_time = datetime.datetime.now()
    if (current_time.hour >= 18):
        current_time += datetime.timedelta(days=1)
    current_time = current_time.replace(hour=18, minute=0, second=0, microsecond=0)
    return (time.mktime(current_time.timetuple()))

def getNextDefaultNightEnd():
    current_time = datetime.datetime.now()
    if (current_time.hour >= 18):
        current_time += datetime.timedelta(days=2)
    else:
        current_time += datetime.timedelta(days=1)
    current_time = current_time.replace(hour=6, minute=0, second=0, microsecond=0)
    return (time.mktime(current_time.timetuple()))

def getDefaultNightStart():
    current_time = datetime.datetime.now()
    current_time = current_time.replace(hour=18, minute=0, second=0, microsecond=0)
    return (time.mktime(current_time.timetuple()))

def getDefaultNightEnd():
    current_time = datetime.datetime.now()
    current_time += datetime.timedelta(days=1)
    current_time = current_time.replace(hour=6, minute=0, second=0, microsecond=0)
    return (time.mktime(current_time.timetuple()))

def datetimeToJulianDate(current_time):
    return (time.mktime(current_time.timetuple()) / JD_VALUE + TIMESTAMP_JD)


''' TODO '''
def getNightStart():
    return (getDefaultNightStart())

''' TODO '''
def getNightEnd():
    return (getDefaultNightEnd())

''' TODO '''
def getNextNightStart():
    return (getNextDefaultNightStart())

''' TODO '''
def getNextNightEnd():
    return (getNextNightEnd())