Exemple #1
0
def to_joda_datetime(value):
    """
    Converts any of the supported date types to ``org.joda.time.DateTime``. If
    ``value`` does not have timezone information, the system default will be
    used.

    Examples:
        .. code-block::

            joda_time = to_joda_datetime(items["date_item"])

    Args:
        value: the value to convert

    Returns:
        org.joda.time.DateTime: the converted value

    Raises:
        TypeError: if the type of ``value`` is not suported by this package
    """
    if isinstance(value, DateTime):
        return value

    value_zoneddatetime = to_java_zoneddatetime(value)
    return DateTime(
        value_zoneddatetime.toInstant().toEpochMilli(),
        DateTimeZone.forID(value_zoneddatetime.getZone().getId())
    )
Exemple #2
0
    def _getSunData(time):
        # Constants
        K = 0.017453

        # Change this reflecting your destination
        latitude = 52.347767
        longitude = 13.621287

        # allways +1 Berlin winter time
        local = time.toDateTime(DateTimeZone.forOffsetHours(1))

        day = local.getDayOfYear()
        hour = local.getHourOfDay() + (local.getMinuteOfHour() / 60.0)

        # Source: http://www.jgiesen.de/SME/tk/index.htm
        deklination = -23.45 * math.cos(K * 360 * (day + 10) / 365)
        zeitgleichung = 60.0 * (-0.171 * math.sin(0.0337 * day + 0.465) -
                                0.1299 * math.sin(0.01787 * day - 0.168))
        stundenwinkel = 15.0 * (hour - (15.0 - longitude) / 15.0 - 12.0 +
                                zeitgleichung / 60.0)
        x = math.sin(K * latitude) * math.sin(K * deklination) + math.cos(
            K * latitude) * math.cos(K * deklination) * math.cos(
                K * stundenwinkel)
        y = -(math.sin(K * latitude) * x - math.sin(K * deklination)) / (
            math.cos(K * latitude) * math.sin(math.acos(x)))
        elevation = math.asin(x) / K

        isBreak = hour <= 12.0 + (15.0 -
                                  longitude) / 15.0 - zeitgleichung / 60.0
        if isBreak: azimut = math.acos(y) / K
        else: azimut = 360.0 - math.acos(y) / K

        return elevation, azimut
Exemple #3
0
def to_joda_datetime(value):
    '''Returns org.joda.time.DateTime type (with system timezone if none specified). 
    Accepts any date type used by this module'''
    if isinstance(value, DateTime):
        return value

    value_zoneddatetime = to_java_zoneddatetime(value)
    return DateTime(value_zoneddatetime.toInstant(),
                    DateTimeZone.forID(value_zoneddatetime.getZone().getId()))
Exemple #4
0
def to_joda_datetime(value):
    """Converts any known DateTime type to a ``org.joda.time.DateTime`` type.

    Args:
        value: any known DateTime value.
    
    Returns:
        | An ``org.joda.time.DateTime`` representing ``value``.
        | If ``value`` does not have timezone information, the system default
          will be used.
    
    Raises:
        TypeError: type of ``value`` is not recognized by this package.
    """
    if isinstance(value, DateTime):
        return value

    value_zoneddatetime = to_java_zoneddatetime(value)
    return DateTime(value_zoneddatetime.toInstant(),
                    DateTimeZone.forID(value_zoneddatetime.getZone().getId()))
Exemple #5
0
def to_joda_datetime(value):
    # type: (t.Any) -> JodaDateTime
    """
    Converts any of the supported date types to ``org.joda.time.DateTime``. If
    ``value`` does not have timezone information, the system default will be
    used.

    Examples:
        .. code-block::

            joda_time = to_joda_datetime(items["date_item"])

    Args:
        value: the value to convert

    Returns:
        org.joda.time.DateTime: the converted value
        None: if ``org.joda.time`` is not available

    Raises:
        TypeError: if the type of ``value`` is not suported by this package
    """
    if JodaDateTime is None:
        frame = inspect.stack()[1]
        getLogger("date").warn(
            "'{func}' ({file}:{line}) called 'to_joda_datetime' but Joda is not available"
            .format(file=frame.filename,
                    line=frame.lineno,
                    func=frame.function))
        del frame
        return None

    if isinstance(value, JodaDateTime):
        return value

    value_zoneddatetime = to_java_zoneddatetime(value)
    return JodaDateTime(
        value_zoneddatetime.toInstant().toEpochMilli(),
        JodaDateTimeZone.forTimeZone(
            TimeZone.getTimeZone(value_zoneddatetime.getZone())))
Exemple #6
0
import sys
# Ensure jar is in path.
sys.path.append('./joda-time-2.4/joda-time-2.4.jar')

from org.joda.time import DateTime
from org.joda.time import DateTimeZone
from org.joda.time.chrono import CopticChronology

zone = DateTimeZone.forID("America/Los_Angeles")
coptic = CopticChronology.getInstance(zone)
coptic_today = DateTime(coptic)
print coptic_today.getYear()
print coptic_today.getMonthOfYear()
print coptic_today.toGregorianCalendar()