Get time from a locally running NTP server
966818
def get_time():
    """"""

    time_request = '\x1b' + 47 * '\0'
    now = struct.unpack("!12I", ntp_service.request(time_request, timeout=5.0).data.read())[10]
    return time.ctime(now - EPOCH_START)
1097151
def access_time(self):
    """"""
    if self._stat_info is None:
      return None

    timestamp = int(self._stat_info.st_atime)
    return dfdatetime_posix_time.PosixTime(timestamp=timestamp)
1012624
def getTimeSinceLastUpdate(IOType):
    """"""
    global last_update_times
    # assert(IOType in ['net', 'disk', 'process_disk'])
    current_time = time()
    last_time = last_update_times.get(IOType)
    if not last_time:
        time_since_update = 1
    else:
        time_since_update = current_time - last_time
    last_update_times[IOType] = current_time
    return time_since_update
562081
def getTimestampUTC():
    
    utc     = datetime.datetime.utcnow()
    ts_sec  = calendar.timegm( utc.timetuple() )
    ts_usec = utc.microsecond
    return ts_sec, ts_usec
1056524
def get_time(self):
        
        if isinstance(self.path, pathlib.Path):
            thetime = self.path.stat().st_mtime
        else:
            thetime = np.nan
        return thetime
382760
def get_utc_timestamp(self, handle):
        """"""
        fpath = self._fpath_from_handle(handle)
        datetime_obj = datetime.datetime.utcfromtimestamp(
            os.stat(fpath).st_mtime
        )
        return timestamp(datetime_obj)
677847
def _blackbox_time(time_scale, blackbox, system):
        """"""
        blackbox = blackbox.reindex()

        tpm = run_tpm(system, time_scale, blackbox)

        # Universal connectivity, for now.
        n = len(system.node_indices)
        cm = np.ones((n, n))

        return SystemAttrs(tpm, cm, system.node_indices, system.state)
1319043
def getmtime(self, filepath):
        """"""
        if self.is_ssh(filepath):
            self._check_ftp()
            source = self._get_remote(filepath)
            mtime = self.ftp.stat(source).st_mtime
        else:
            mtime = os.path.getmtime(filepath)

        return mtime
222521
def _getFromTime(self, atDate=None):
        
        return getLocalTime(self.date, self.time_from, self.tz)
618090
def update(self):
        """"""
        # Init new stats
        stats = self.get_init_value()

        if self.input_method == 'local':
            # Update stats using the standard system lib
            self.uptime = datetime.now() - datetime.fromtimestamp(psutil.boot_time())

            # Convert uptime to string (because datetime is not JSONifi)
            stats = str(self.uptime).split('.')[0]
        elif self.input_method == 'snmp':
            # Update stats using SNMP
            uptime = self.get_stats_snmp(snmp_oid=snmp_oid)['_uptime']
            try:
                # In hundredths of seconds
                stats = str(timedelta(seconds=int(uptime) / 100))
            except Exception:
                pass

        # Update the stats
        self.stats = stats

        return self.stats
1119982
def get_ntp_stats(self):
        """"""
        ntp_stats = []

        command = "show ntp associations"
        output = self._send_command(command)

        for line in output.splitlines():
            # Skip first two lines and last line of command output
            if line == "" or "address" in line or "sys.peer" in line:
                continue

            if "%NTP is not enabled" in line:
                return []

            elif len(line.split()) == 9:
                address, ref_clock, st, when, poll, reach, delay, offset, disp = (
                    line.split()
                )
                address_regex = re.match(r"(\W*)([0-9.*]*)", address)
            try:
                ntp_stats.append(
                    {
                        "remote": py23_compat.text_type(address_regex.group(2)),
                        "synchronized": ("*" in address_regex.group(1)),
                        "referenceid": py23_compat.text_type(ref_clock),
                        "stratum": int(st),
                        "type": "-",
                        "when": py23_compat.text_type(when),
                        "hostpoll": int(poll),
                        "reachability": int(reach),
                        "delay": float(delay),
                        "offset": float(offset),
                        "jitter": float(disp),
                    }
                )
            except Exception:
                continue

        return ntp_stats
362541
private static function detectSystemTimezone()
    {
        // Mac OS X (and older Linuxes): /etc/localtime is a symlink to the
        // timezone in /usr/share/zoneinfo or /var/db/timezone/zoneinfo.
        if (is_link('/etc/localtime')) {
            $filename = readlink('/etc/localtime');
            $prefixes = [
                '/usr/share/zoneinfo/',
                '/var/db/timezone/zoneinfo/',
            ];
            foreach ($prefixes as $prefix) {
                if (strpos($filename, $prefix) === 0) {
                    return substr($filename, strlen($prefix));
                }
            }
        }

        // Ubuntu and Debian.
        if (file_exists('/etc/timezone')) {
            $data = file_get_contents('/etc/timezone');
            if ($data !== false) {
                return trim($data);
            }
        }

        // RHEL and CentOS.
        if (file_exists('/etc/sysconfig/clock')) {
            $data = parse_ini_file('/etc/sysconfig/clock');
            if (!empty($data['ZONE'])) {
                return trim($data['ZONE']);
            }
        }

        return false;
    }
406580
def request_timestamp(self, lock):
        '''
        '''
        ts = self.requests[hookenv.local_unit()].get(lock, None)
        if ts is not None:
            return datetime.strptime(ts, _timestamp_format)
1021608
def uptime():
    """"""
    from datetime import timedelta

    with open('/proc/uptime', 'r') as f:
        uptime_seconds = float(f.readline().split()[0])
        uptime_string = str(timedelta(seconds=uptime_seconds))

    bob.says(uptime_string)
1247745
def get_packet_time(self, pkt):
        """"""
        if pkt.sent_time:
          t = pkt.sent_time
          sec = int(t)
        else:
          t = pkt.time
          sec = int(t)
        usec = int(round((t-sec)*1000000))
        return (sec,usec)
961547
function getRealUptime (next) {
  fs.readFile('/proc/uptime', 'utf8', function (err, uptime) {
    if (err || uptime === undefined) {
      console.warn("[pidusage] We couldn't find uptime from /proc/uptime, using os.uptime() value")
      return next(null, os.uptime())
    }

    return next(null, parseFloat(uptime.split(' ')[0]))
  })
}
1043712
def ping(self):
        
        start = time.time()
        self._conn.ping()
        return (time.time() - start)