Returns a Time instance on date using self as the time of day
 Optional time_zone will build time in that zone
179234
def on(date, time_zone=Tod::TimeOfDay.time_zone)
      time_zone.local date.year, date.month, date.day, @hour, @minute, @second
    end
308841
def initialize_time_zone
      if configuration.time_zone
        zone_default = Time.__send__(:get_zone, configuration.time_zone)

        unless zone_default
          raise \
            'Value assigned to config.time_zone not recognized.' +
            'Run "rake -D time" for a list of tasks for finding appropriate time zone names.'
        end

        Time.zone_default = zone_default

        if defined?(ActiveRecord)
          ActiveRecord::Base.time_zone_aware_attributes = true
          ActiveRecord::Base.default_timezone = :utc
        end
      end
    end
964387
def now(self):
    ''' 
    '''
    localtime = datetime.datetime.now()
    return localtime + datetime.timedelta(hours = time.timezone/60/60 + self.TimeZone)
615281
def ensure_timezone(dt, tz=None):
    
    if dt.tzinfo is None:
        return dt.replace(tzinfo=tz or tzlocal())
    else:
        return dt
624585
@Deprecated
    public static TimeZone getTimeZone(Date self) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(self);
        return calendar.getTimeZone();
    }
222498
def _convert_value(self, value, model_instance, add):
        

        if not value:
            return value

        # Retrieve the default timezone as the default
        tz = get_default_timezone()

        # If populate_from exists, override the default timezone
        if self.populate_from is not None:
            tz = self._get_populate_from(model_instance)

        if is_naive(value):
            value = make_aware(value=value, timezone=tz)

        # Convert the value to a datetime object in the correct timezone. This
        #   insures that we will have the correct date if we are performing a
        #   time override below.
        value = value.astimezone(tz)

        # Do not convert the time to the time override if auto_now or
        #   auto_now_add is set
        if self.time_override is not None and not (
            self.auto_now or (self.auto_now_add and add)
        ):
            # Retrieve the time override
            time_override = self._get_time_override()

            # Convert the value to the date/time with the appropriate timezone
            value = make_aware(
                value=datetime.combine(
                    date=value.date(),
                    time=time_override
                ),
                timezone=tz
            )

        return value
741648
def _build_time(time, kwargs):
    
    tz = kwargs.pop('tz', 'UTC')
    if time:
        if kwargs:
            raise ValueError('Cannot pass kwargs and a time')
        else:
            return ensure_utc(time, tz)
    elif not kwargs:
        raise ValueError('Must pass a time or kwargs')
    else:
        return datetime.time(**kwargs)
613833
def get_timezone() -> Tuple[datetime.tzinfo, str]:
    """"""
    dt = get_datetime_now().astimezone()
    tzstr = dt.strftime("%z")
    tzstr = tzstr[:-2] + ":" + tzstr[-2:]
    return dt.tzinfo, tzstr
401671
def to_default_timezone_datetime(self, value):
        
        return timezone.localtime(self.to_utc_datetime(value), timezone.get_default_timezone())
678892
def date(self):
    ''' 
    '''
    localtime = datetime.date.today()
    return localtime + datetime.timedelta(hours = time.timezone/60/60 + self.TimeZone)
996980
def datetime_to_timezone(date, tz="UTC"):
    
    if not date.tzinfo:
        date = date.replace(tzinfo=timezone(get_timezone()))
    return date.astimezone(timezone(tz))
1089636
def asStructTime(self, tzinfo=None):
        
        dtime = self.asDatetime(tzinfo)
        if tzinfo is None:
            return dtime.utctimetuple()
        else:
            return dtime.timetuple()
725224
def mktime_tz(data):
    """"""
    if data[9] is None:
        # No zone info, so localtime is better assumption than GMT
        return time.mktime(data[:8] + (-1,))
    else:
        t = calendar.timegm(data)
        return t - data[9]
821212
def ensure_timezone(dateTime,timeZone=None):
    '''
    
    '''

    if is_aware(dateTime) and not getattr(settings,'USE_TZ',False):
        return make_naive(dateTime,timezone=timeZone)
    if is_naive(dateTime) and getattr(settings,'USE_TZ',False):
        return make_aware(dateTime,timezone=timeZone)
    # If neither condition is met, then we can return what was passed
    return dateTime
849792
def built_datetime(self):
        """"""
        from datetime import datetime
        try:
            return datetime.fromtimestamp(self.state.build_done)
        except TypeError:
            # build_done is null
            return None
285862
def at(time_of_day, time_zone=Tod::TimeOfDay.time_zone)
      time_zone.local year, month, day, time_of_day.hour, time_of_day.minute, time_of_day.second
    end
880972
def set_timezone(data, tz=None, from_local=False):
    
    # pandas object?
    if isinstance(data, pd.DataFrame) | isinstance(data, pd.Series):
        try:
            try:
                data.index = data.index.tz_convert(tz)
            except Exception as e:
                if from_local:
                    data.index = data.index.tz_localize(
                        get_timezone()).tz_convert(tz)
                else:
                    data.index = data.index.tz_localize('UTC').tz_convert(tz)
        except Exception as e:
            pass

    # not pandas...
    else:
        if isinstance(data, str):
            data = parse_date(data)
        try:
            try:
                data = data.astimezone(tz)
            except Exception as e:
                data = timezone('UTC').localize(data).astimezone(timezone(tz))
        except Exception as e:
            pass

    return data