Return the current date and time formatted for a message header.
189499
def date_time_string(timestamp=None):
    """"""
    global _last_date_time_string
    _last_timestamp, _last_str = _last_date_time_string
    if timestamp is None:
        timestamp = time.time()
    _curr_timestamp = int(timestamp)
    if _curr_timestamp == _last_timestamp:
        return _last_str
    else:
        year, month, day, hh, mm, ss, wd, y, z = time.gmtime(timestamp)
        s = b"%s, %02d %3s %4d %02d:%02d:%02d GMT" % (
                weekdayname[wd],
                day, monthname[month], year,
                hh, mm, ss)
        _last_date_time_string = (_curr_timestamp, s)
        return s
647030
def current_timestamp(self) -> datetime:
        """"""
        timestamp = DB.get_hash_value(self._key, 'current_timestamp')
        return datetime_from_isoformat(timestamp)
1118724
def formatted_time(self, fmt: str = '') -> str:
        
        time_obj = self.time()

        if not fmt:
            fmt = self._data['formats'].get('time')
        return time_obj.strftime(fmt)
677261
def last_edit_time(self):
        
        data = {'_xsrf': self.xsrf, 'offset': '1'}
        res = self._session.post(self.url + 'log', data=data)
        _, content = res.json()['msg']
        soup = BeautifulSoup(content)
        time_string = soup.find_all('time')[0]['datetime']
        return datetime.strptime(time_string, "%Y-%m-%d %H:%M:%S")
822975
def datetime(self):
        
        date_string = '%s %s' % (self._date, self._time.upper())
        date_string = re.sub(r'/.*', '', date_string)
        date_string = re.sub(r' ET', '', date_string)
        date_string += 'M'
        date_string = re.sub(r'PMM', 'PM', date_string, flags=re.IGNORECASE)
        date_string = re.sub(r'AMM', 'AM', date_string, flags=re.IGNORECASE)
        date_string = re.sub(r' PM', 'PM', date_string, flags=re.IGNORECASE)
        date_string = re.sub(r' AM', 'AM', date_string, flags=re.IGNORECASE)
        return datetime.strptime(date_string, '%a, %b %d, %Y %I:%M%p')
241789
def format(
            self,
            record,
            datefmt='%Y:%m:%d %H:%M:%S.%f'):
        

        now = datetime.datetime.now()
        utc_now = datetime.datetime.utcnow()
        asctime = None
        if self.datefmt:
            asctime = now.strftime(
                self.datefmt)
        else:
            asctime = now.strftime(
                datefmt)

        message = {
            'time': record.created,
            'timestamp': utc_now.strftime(
                '%Y-%m-%dT%H:%M:%S.%fZ'),
            'asctime': asctime,
            'path': record.pathname,
            'message': record.getMessage(),
            'exc': None,
            'logger_name': record.name
        }

        if record.exc_info and not message.get('exc'):
            message['exc'] = self.formatException(
                record.exc_info)
        if not message.get(
                'exc') and record.exc_text:
            message['exc'] = record.exc_text

        log_record = {}
        try:
            log_record = OrderedDict()
        except NameError:
            log_record = {}
        # end of try/ex

        message.update(
            self.fields_to_add)
        self.add_fields(
            log_record,
            record,
            message)
        use_log_record = self.process_log_record(
            log_record)
        return '{}{}'.format(
            self.prefix,
            self.jsonify_log_record(
                use_log_record))
290349
def current_time(self, date):
        
        ret = self.command(
            'global.cgi?action=setCurrentTime&time={0}'.format(date)
        )

        if "ok" in ret.content.decode('utf-8').lower():
            return True

        return False
601913
def pretty_date(time=False):
    
    now = datetime.now(PST_TIMEZONE)
    if type(time) is int:
        diff = now - datetime.fromtimestamp(time)
    elif isinstance(time, datetime):
        diff = now - time
    elif not time:
        diff = now - now
    second_diff = diff.seconds
    day_diff = diff.days

    if day_diff < 0:
        return ''

    if day_diff == 0:
        if second_diff < 10:
            return "just now"
        if second_diff < 60:
            return str(second_diff) + " seconds ago"
        if second_diff < 120:
            return "a minute ago"
        if second_diff < 3600:
            return str(int(second_diff / 60)) + " minutes ago"
        if second_diff < 7200:
            return "an hour ago"
        if second_diff < 86400:
            return str(int(second_diff / 3600)) + " hours ago"
    if day_diff == 1:
        return "Yesterday"
    if day_diff < 7:
        return str(day_diff) + " days ago"
    if day_diff < 31:
        return str(int(day_diff / 7)) + " weeks ago"
    if day_diff < 365:
        return str(int(day_diff / 30)) + " months ago"
    return str(int(day_diff / 365)) + " years ago"
635931
def message(self):
        """"""
        return {
            'timestamp': time.mktime(self.timestamp.timetuple())*1e3 + self.timestamp.microsecond/1e3,
            'group': self.group_pk,
            'participant': None if not self.participant else self.participant.code,
            'channel': self.channel,
            'value': self.value
        }
226419
def format_time( sec ):
    ''' 
    '''
    import time
    if sec < 864000:
       # Idea from:   http://stackoverflow.com/a/1384565
       return time.strftime('%H:%M:%S', time.gmtime(sec))
    else:
       days = int(sec / 864000)
       secs = sec % 864000
       return str(days)+'d, '+time.strftime('%H:%M:%S', time.gmtime(secs))
1046486
@Deprecated
    public static Date getDateHeader(HttpMessage message, String name) throws ParseException {
        return getDateHeader(message, (CharSequence) name);
    }
612791
function getFormattedStopTime (stopTime) {
  return (
    <span>
      {stopTime.realtimeState === 'UPDATED'
        ? <Icon type='rss' style={{ color: '#888', fontSize: '0.8em', marginRight: 2 }} />
        : <Icon type='clock-o' style={{ color: '#888', fontSize: '0.8em', marginRight: 2 }} />
      }
      {formatStopTime(stopTime.realtimeDeparture)}
    </span>
  )
}
1204941
def format_messages(self, messages):
        
        mess = ""
        for message in self.message:
            if self.pretty:
                mess = "{}{}".format(mess, self.format_message(message))
            else:
                mess += str(message)
        if self.include_time:
            return ": {} : {}".format(
                datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), mess)
        return stdout_encode(mess)
1343856
def time_to_text(time):
    """"""
    
    if time < 0.001:
        return str(round(time * 1000000)) + " µs"
    elif time < 1:
        return str(round(time * 1000)) + " ms"
    elif time < 60:
        return str(round(time, 1)) + " s"
    else:
        return str(round(time / 60, 1)) + " min"
951164
def what_time_is_it_in(self, message, place):
        """"""
        location = get_location(place)
        if location is not None:
            tz = get_timezone(location.lat, location.long)
            if tz is not None:
                ct = datetime.datetime.now(tz=pytz.timezone(tz))
                self.say("It's %(time)s in %(place)s." % {'time': self.to_natural_day_and_time(ct),
                                                          'place': location.name}, message=message)
            else:
                self.say("I couldn't find timezone for %(place)s." % {'place': location.name}, message=message)
        else:
            self.say("I couldn't find anywhere named %(place)s." % {'place': location.name}, message=message)
1147214
def parse_date(ims):
    
    try:
        ts = email.utils.parsedate_tz(ims)
        return time.mktime(ts[:8] + (0,)) - (ts[9] or 0) - time.timezone
    except (TypeError, ValueError, IndexError):
        return None
975897
def to_header(self):
        """"""
        if self.date is not None:
            return http_date(self.date)
        if self.etag is not None:
            return quote_etag(self.etag)
        return ""