指定日期

            :param datetime time: 欲判斷的日期
            :rtype: bool
            :returns: True 為開市、False 為休市
15954
def d_day(self, time):
        ''' 
        '''
        if type(time) == type(TWTime().now):
            self.twtime = TWTime().now
        elif type(time) == type(TWTime().date):
            self.twtime = TWTime().date
        else:
            pass
        return self.caldata(time)
1314237
def formatdt(date: datetime.date, include_time: bool = True) -> str:
    
    if include_time:
        return date.strftime("%Y-%m-%dT%H:%M")
    else:
        return date.strftime("%Y-%m-%d")
1039649
def _GetDateTime(self, filetime):
    
    if filetime == 0:
      return dfdatetime_semantic_time.SemanticTime('Not set')

    return dfdatetime_filetime.Filetime(timestamp=filetime)
555898
def datetime(self):
        
        date_string = '%s %s %s' % (self._day,
                                    self._date,
                                    self._year)
        return datetime.strptime(date_string, '%a %B %d %Y')
660449
def cleaned_date(day, keep_datetime=False):
    
    if not isinstance(day, (date, datetime)):
        raise UnsupportedDateType(
            "`{}` is of unsupported type ({})".format(day, type(day)))
    if not keep_datetime:
        if hasattr(day, 'date') and callable(day.date):
            day = day.date()
    return day
649792
def date_to_datetime(d):
    
    if not isinstance(d, datetime):
        d = datetime.combine(d, datetime.min.time())
    return d
142812
def start_of_day(dtime_at=None):
    
    dtime_at = datetime_or_now(dtime_at)
    return datetime.datetime(dtime_at.year, dtime_at.month,
        dtime_at.day, tzinfo=tzlocal())
651261
def show_fuzzy_date(self):
        
        date = self.time.replace(tzinfo=None)
        if date <= datetime.now():
            diff = datetime.now() - date
            if diff.days >= 14:
                return False
        else:
            diff = date - datetime.now()
            if diff.days >= 14:
                return False

        return True
393207
def available_on_day(self, day):
        
        if isinstance(day, datetime):
            d = day.date()
        else:
            d = day
        return self.starts_within(d, d)
351134
def str2dt(time: datetime) -> np.ndarray:
    
    if isinstance(time, datetime):
        return time
    elif isinstance(time, str):
        return parse(time)
    elif isinstance(time, np.datetime64):
        return time.astype(datetime)
    else:  # some sort of iterable
        try:
            if isinstance(time[0], datetime):
                return time
            elif isinstance(time[0], np.datetime64):
                return time.astype(datetime)
            elif isinstance(time[0], str):
                return [parse(t) for t in time]
        except (IndexError, TypeError):
            pass

        # last resort--assume pandas/xarray

        return time.values.astype('datetime64[us]').astype(datetime)
11920
def is_same_day(self, dt):
        
        dt = pendulum.instance(dt)

        return self.to_date_string() == dt.to_date_string()
270655
def _build_date_time_time_zone(self, date_time):
        
        timezone = date_time.tzinfo.zone if date_time.tzinfo is not None else None
        return {
            self._cc('dateTime'): date_time.strftime('%Y-%m-%dT%H:%M:%S'),
            self._cc('timeZone'): get_windows_tz(timezone or self.protocol.timezone)
        }
1149233
def _get_date_time_format(dt_string):
    '''
    
    '''
    valid_formats = [
        '%I:%M:%S %p',
        '%I:%M %p',
        '%H:%M:%S',
        '%H:%M',
        '%Y-%m-%d',
        '%m-%d-%y',
        '%m-%d-%Y',
        '%m/%d/%y',
        '%m/%d/%Y',
        '%Y/%m/%d'
    ]
    for dt_format in valid_formats:
        try:
            datetime.strptime(dt_string, dt_format)
            return dt_format
        except ValueError:
            continue
    return False
272804
def datetime_string(time_zone=False):
    
    time = datetime.datetime.now()
    template = u"%04d-%02d-%02dT%02d:%02d:%02d"
    if time_zone:
        template += u"+00:00"
    return template % (
        time.year,
        time.month,
        time.day,
        time.hour,
        time.minute,
        time.second
    )
992666
def getDayStart(self, dateTime):
        '''  '''
        return ensure_localtime(dateTime).replace(hour=0,minute=0,second=0,microsecond=0)
1033079
def is_np_datetime_like(dtype: Union[str, np.dtype]) -> bool:
    
    return (np.issubdtype(dtype, np.datetime64) or
            np.issubdtype(dtype, np.timedelta64))
153456
def is_date(v) -> (bool, date):
        
        if isinstance(v, date):
            return True, v
        try:
            reg = r'^([0-9]{4})(?:-(0[1-9]|1[0-2])(?:-(0[1-9]|[1-2][0-9]|3[0-1])(?:T' \
                  r'([0-5][0-9])(?::([0-5][0-9])(?::([0-5][0-9]))?)?)?)?)?$'
            match = re.match(reg, v)
            if match:
                groups = match.groups()
                patterns = ['%Y', '%m', '%d', '%H', '%M', '%S']
                d = datetime.strptime('-'.join([x for x in groups if x]),
                                      '-'.join([patterns[i] for i in range(len(patterns)) if groups[i]]))
                return True, d
        except:
            pass
        return False, v