Setup time functions

    :returns: ``tuple``
976488
def time_stamp():
    

    # Time constants
    fmt = '%Y-%m-%dT%H:%M:%S.%f'
    date = datetime.datetime
    date_delta = datetime.timedelta
    now = datetime.datetime.utcnow()

    return fmt, date, date_delta, now
227614
def timeit(metric, func, *args, **kwargs):
    
    return _client.timeit(metric, func, *args, **kwargs)
400472
def _set_time(self, time):
        
        if len(self.time) == 0 :
            self.time = np.array(time)
            if self.h5 is not None:
                self.h5.create_dataset('time', self.time.shape, dtype=self.time.dtype, data=self.time, compression="gzip", shuffle=True, scaleoffset=3)
        else:
            if(len(time) != len(self.time)):
                raise AssertionError("\nTime or number of frame mismatch in input files.\n Exiting...\n")
1117146
def _timed(_logger=None, level="info"):
    

    def fun_wrapper(f):
        @functools.wraps(f)
        def wraps(*args, **kwargs):
            with _timer(f.__name__, _logger=logger, level=level):
                results = f(*args, **kwargs)
            return results

        return wraps

    return fun_wrapper
1023748
def str_to_time(self):
        

        return datetime(*list(map(int, re.split(r'-|:|T', self.time))))
492915
def _check_holiday_structure(self, times):
        

        if not isinstance(times, list):
            raise TypeError("an list is required")

        for time in times:
            if not isinstance(time, tuple):
                raise TypeError("a tuple is required")
            if len(time) > 5:
                raise TypeError("Target time takes at most 5 arguments"
                                " ('%d' given)" % len(time))
            if len(time) < 5:
                raise TypeError("Required argument '%s' (pos '%d')"
                                " not found" % (TIME_LABEL[len(time)], len(time)))

            self._check_time_format(TIME_LABEL, time)
342177
def timetuple(self):
        ""
        dst = self.dst()
        if dst is None:
            dst = -1
        elif dst:
            dst = 1
        else:
            dst = 0
        return _build_struct_time(self.year, self.month, self.day,
                                  self.hour, self.minute, self.second,
                                  dst)
536810
def timeit(threshold=0):
    

    def inner(func):
        @wraps(func)
        def wrapper(*args, **kwargs):
            start = time.time()
            return_value = func(*args, **kwargs)
            end = time.time()
            duration = float(end-start)
            if duration > threshold:
                logger.info("Execution of '{}{}' took {:2f}s".format(
                    func.__name__, args, duration))
            return return_value
        return wrapper
    return inner
1069388
def writeICCdatetime(t=None):
    

    import time
    if t is None:
        t = time.gmtime()
    return struct.pack('>6H', *t[:6])
950503
def first_setup(self):
        """"""
        if ATTR_FIRST_SETUP not in self.raw:
            return None
        return datetime.utcfromtimestamp(self.raw[ATTR_FIRST_SETUP])
1210996
def setup(self):
        """"""
        if self.mlogfilter.is_stdin:
            # assume this year (we have no other info)
            now = datetime.now()
            self.startDateTime = datetime(now.year, 1, 1, tzinfo=tzutc())
            self.endDateTime = datetime(MAXYEAR, 12, 31, tzinfo=tzutc())

        else:
            logfiles = self.mlogfilter.args['logfile']
            self.startDateTime = min([lf.start +
                                      timedelta(hours=self
                                                .mlogfilter
                                                .args['timezone'][i])
                                      for i, lf in enumerate(logfiles)])
            self.endDateTime = max([lf.end +
                                    timedelta(hours=self
                                              .mlogfilter.args['timezone'][i])
                                    for i, lf in enumerate(logfiles)])

        # now parse for further changes to from and to datetimes
        dtbound = DateTimeBoundaries(self.startDateTime, self.endDateTime)
        self.fromDateTime, self.toDateTime = dtbound(self.mlogfilter
                                                     .args['from'] or None,
                                                     self.mlogfilter
                                                     .args['to'] or None)

        # define start_limit for mlogfilter's fast_forward method
        self.start_limit = self.fromDateTime

        # for single logfile, get file seek position of `to` datetime
        if (len(self.mlogfilter.args['logfile']) == 1 and not
                self.mlogfilter.is_stdin):

            if self.mlogfilter.args['to'] != "end":
                # fast forward, get seek value, then reset file
                logfile = self.mlogfilter.args['logfile'][0]
                logfile.fast_forward(self.toDateTime)
                self.seek_to = logfile.filehandle.tell()
                logfile.filehandle.seek(0)
            else:
                self.seek_to = -1
        else:
            self.seek_to = False
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)
1113331
def cmd_time(self, args):
        ''''''
        tusec = self.master.field('SYSTEM_TIME', 'time_unix_usec', 0)
        if tusec == 0:
            print("No SYSTEM_TIME time available")
            return
        print("%s (%s)\n" % (time.ctime(tusec * 1.0e-6), time.ctime()))
296430
def settime(self, time):
        
        if isinstance(time, datetime) or isinstance(time,
                                                             datetime.date):
            seconds = int(time.strftime("%s"))
        elif isinstance(time, int):
            seconds = time
        else:
            raise TypeError("datetime.date, datetime.datetime or integer " +
                            "is required as time argument")
        raise NotImplementedError
640193
def _generate_time_values(self):
        
        # Populate time values
        log('writing times', 'INFO')
        d1970 = datetime(1970, 1, 1, tzinfo=utc)
        time_array = [[int((self.start_datetime - d1970).total_seconds())]]

        datetime_nc_start_simulation = self.start_datetime
        for raw_nc_index, raw_nc in enumerate(self.raw_nc_list):
            raw_nc_time = raw_nc.get_time_array(
                datetime_simulation_start=datetime_nc_start_simulation,
                simulation_time_step_seconds=self.time_step_array[
                    raw_nc_index])

            time_array.append(raw_nc_time)
            datetime_nc_start_simulation = \
                datetime.utcfromtimestamp(raw_nc_time[-1])

        self.cf_nc.variables['time'][:] = np.concatenate(time_array)
        end_date = datetime.utcfromtimestamp(self.cf_nc.variables['time'][-1])
        self.cf_nc.time_coverage_start = self.start_datetime.isoformat() + 'Z'
        self.cf_nc.time_coverage_end = end_date.isoformat() + 'Z'
529241
def hours(self):
        
        if not isinstance(self.duration, tuple):
            return self.duration

        if self.duration[1] is None:
            return 0

        time_start = self.get_start_time()

        # This can happen if the previous entry has a non-tuple duration
        # and the current entry has a tuple duration without a start time
        if time_start is None:
            return 0

        now = datetime.datetime.now()
        time_start = now.replace(
            hour=time_start.hour,
            minute=time_start.minute, second=0
        )
        time_end = now.replace(
            hour=self.duration[1].hour,
            minute=self.duration[1].minute, second=0
        )
        total_time = time_end - time_start
        total_hours = total_time.seconds / 3600.0

        return total_hours
584920
def datetimes(self):
        """"""
        if self.timestep == 1:
            return tuple(dt.add_minute(30) for dt in
                         self.direct_normal_irradiance.datetimes)
        else:
            return self.direct_normal_irradiance.datetimes