Example #1
0
def _to_timestamp(d):
    if isinstance(d, datetime.datetime):
        calendar = GregorianCalendar()
        calendar.set(d.year, d.month - 1, d.day, d.hour, d.minute, d.second)
        ts = Timestamp(calendar.getTimeInMillis())
        ts.setNanos(d.microsecond * 1000)
        return ts
    else:
        return d
    def isDayTime(self, forecastDate, sunrise, sunset):

        # Only check the time, not the date, of the forecast against the
        # sunrise and sunset times.

        cal = GregorianCalendar(TimeZone.getTimeZone("UTC"))
        cal.setTime(forecastDate)

        riseCal = GregorianCalendar(TimeZone.getTimeZone("UTC"))
        riseCal.setTime(sunrise)
        riseCal.set(cal.get(cal.YEAR), cal.get(cal.MONTH), cal.get(cal.DATE))

        setCal = GregorianCalendar(TimeZone.getTimeZone("UTC"))
        setCal.setTime(sunset)
        setCal.set(cal.get(cal.YEAR), cal.get(cal.MONTH), cal.get(cal.DATE))

        if cal.compareTo(riseCal) == -1:
            return False
        elif cal.compareTo(setCal) == 1:
            return False

        return True