Python datetime.fromtimestamp() Examples
The following are 30
code examples of datetime.fromtimestamp().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
datetime
, or try the search function
.
Example #1
Source File: client.py From splunk-elasticsearch with Apache License 2.0 | 6 votes |
def scheduled_times(self, earliest_time='now', latest_time='+1h'): """Returns the times when this search is scheduled to run. By default this method returns the times in the next hour. For different time ranges, set *earliest_time* and *latest_time*. For example, for all times in the last day use "earliest_time=-1d" and "latest_time=now". :param earliest_time: The earliest time. :type earliest_time: ``string`` :param latest_time: The latest time. :type latest_time: ``string`` :return: The list of search times. """ response = self.get("scheduled_times", earliest_time=earliest_time, latest_time=latest_time) data = self._load_atom_entry(response) rec = _parse_atom_entry(data) times = [datetime.fromtimestamp(int(t)) for t in rec.content.scheduled_times] return times
Example #2
Source File: client.py From vscode-extension-splunk with MIT License | 6 votes |
def scheduled_times(self, earliest_time='now', latest_time='+1h'): """Returns the times when this search is scheduled to run. By default this method returns the times in the next hour. For different time ranges, set *earliest_time* and *latest_time*. For example, for all times in the last day use "earliest_time=-1d" and "latest_time=now". :param earliest_time: The earliest time. :type earliest_time: ``string`` :param latest_time: The latest time. :type latest_time: ``string`` :return: The list of search times. """ response = self.get("scheduled_times", earliest_time=earliest_time, latest_time=latest_time) data = self._load_atom_entry(response) rec = _parse_atom_entry(data) times = [datetime.fromtimestamp(int(t)) for t in rec.content.scheduled_times] return times
Example #3
Source File: client.py From SA-ctf_scoreboard with Creative Commons Zero v1.0 Universal | 6 votes |
def scheduled_times(self, earliest_time='now', latest_time='+1h'): """Returns the times when this search is scheduled to run. By default this method returns the times in the next hour. For different time ranges, set *earliest_time* and *latest_time*. For example, for all times in the last day use "earliest_time=-1d" and "latest_time=now". :param earliest_time: The earliest time. :type earliest_time: ``string`` :param latest_time: The latest time. :type latest_time: ``string`` :return: The list of search times. """ response = self.get("scheduled_times", earliest_time=earliest_time, latest_time=latest_time) data = self._load_atom_entry(response) rec = _parse_atom_entry(data) times = [datetime.fromtimestamp(int(t)) for t in rec.content.scheduled_times] return times
Example #4
Source File: client.py From splunk-ref-pas-code with Apache License 2.0 | 6 votes |
def scheduled_times(self, earliest_time='now', latest_time='+1h'): """Returns the times when this search is scheduled to run. By default this method returns the times in the next hour. For different time ranges, set *earliest_time* and *latest_time*. For example, for all times in the last day use "earliest_time=-1d" and "latest_time=now". :param earliest_time: The earliest time. :type earliest_time: ``string`` :param latest_time: The latest time. :type latest_time: ``string`` :return: The list of search times. """ response = self.get("scheduled_times", earliest_time=earliest_time, latest_time=latest_time) data = self._load_atom_entry(response) rec = _parse_atom_entry(data) times = [datetime.fromtimestamp(int(t)) for t in rec.content.scheduled_times] return times
Example #5
Source File: message_types.py From protorpc with Apache License 2.0 | 6 votes |
def value_to_message(self, value): value = super(DateTimeField, self).value_to_message(value) # First, determine the delta from the epoch, so we can fill in # DateTimeMessage's milliseconds field. if value.tzinfo is None: time_zone_offset = 0 local_epoch = datetime.datetime.utcfromtimestamp(0) else: time_zone_offset = util.total_seconds(value.tzinfo.utcoffset(value)) # Determine Jan 1, 1970 local time. local_epoch = datetime.datetime.fromtimestamp(-time_zone_offset, tz=value.tzinfo) delta = value - local_epoch # Create and fill in the DateTimeMessage, including time zone if # one was specified. message = DateTimeMessage() message.milliseconds = int(util.total_seconds(delta) * 1000) if value.tzinfo is not None: utc_offset = value.tzinfo.utcoffset(value) if utc_offset is not None: message.time_zone_offset = int( util.total_seconds(value.tzinfo.utcoffset(value)) / 60) return message
Example #6
Source File: message_types.py From protorpc with Apache License 2.0 | 6 votes |
def value_from_message(self, message): """Convert DateTimeMessage to a datetime. Args: A DateTimeMessage instance. Returns: A datetime instance. """ message = super(DateTimeField, self).value_from_message(message) if message.time_zone_offset is None: return datetime.datetime.utcfromtimestamp(message.milliseconds / 1000.0) # Need to subtract the time zone offset, because when we call # datetime.fromtimestamp, it will add the time zone offset to the # value we pass. milliseconds = (message.milliseconds - 60000 * message.time_zone_offset) timezone = util.TimeZoneOffset(message.time_zone_offset) return datetime.datetime.fromtimestamp(milliseconds / 1000.0, tz=timezone)
Example #7
Source File: client.py From SA-ctf_scoreboard with Creative Commons Zero v1.0 Universal | 6 votes |
def scheduled_times(self, earliest_time='now', latest_time='+1h'): """Returns the times when this search is scheduled to run. By default this method returns the times in the next hour. For different time ranges, set *earliest_time* and *latest_time*. For example, for all times in the last day use "earliest_time=-1d" and "latest_time=now". :param earliest_time: The earliest time. :type earliest_time: ``string`` :param latest_time: The latest time. :type latest_time: ``string`` :return: The list of search times. """ response = self.get("scheduled_times", earliest_time=earliest_time, latest_time=latest_time) data = self._load_atom_entry(response) rec = _parse_atom_entry(data) times = [datetime.fromtimestamp(int(t)) for t in rec.content.scheduled_times] return times
Example #8
Source File: client.py From SA-ctf_scoreboard with Creative Commons Zero v1.0 Universal | 6 votes |
def scheduled_times(self, earliest_time='now', latest_time='+1h'): """Returns the times when this search is scheduled to run. By default this method returns the times in the next hour. For different time ranges, set *earliest_time* and *latest_time*. For example, for all times in the last day use "earliest_time=-1d" and "latest_time=now". :param earliest_time: The earliest time. :type earliest_time: ``string`` :param latest_time: The latest time. :type latest_time: ``string`` :return: The list of search times. """ response = self.get("scheduled_times", earliest_time=earliest_time, latest_time=latest_time) data = self._load_atom_entry(response) rec = _parse_atom_entry(data) times = [datetime.fromtimestamp(int(t)) for t in rec.content.scheduled_times] return times
Example #9
Source File: message_types.py From apitools with Apache License 2.0 | 6 votes |
def value_from_message(self, message): """Convert DateTimeMessage to a datetime. Args: A DateTimeMessage instance. Returns: A datetime instance. """ message = super(DateTimeField, self).value_from_message(message) if message.time_zone_offset is None: return datetime.datetime.utcfromtimestamp( message.milliseconds / 1000.0) # Need to subtract the time zone offset, because when we call # datetime.fromtimestamp, it will add the time zone offset to the # value we pass. milliseconds = (message.milliseconds - 60000 * message.time_zone_offset) timezone = util.TimeZoneOffset(message.time_zone_offset) return datetime.datetime.fromtimestamp(milliseconds / 1000.0, tz=timezone)
Example #10
Source File: client.py From SA-ctf_scoreboard_admin with Creative Commons Zero v1.0 Universal | 6 votes |
def scheduled_times(self, earliest_time='now', latest_time='+1h'): """Returns the times when this search is scheduled to run. By default this method returns the times in the next hour. For different time ranges, set *earliest_time* and *latest_time*. For example, for all times in the last day use "earliest_time=-1d" and "latest_time=now". :param earliest_time: The earliest time. :type earliest_time: ``string`` :param latest_time: The latest time. :type latest_time: ``string`` :return: The list of search times. """ response = self.get("scheduled_times", earliest_time=earliest_time, latest_time=latest_time) data = self._load_atom_entry(response) rec = _parse_atom_entry(data) times = [datetime.fromtimestamp(int(t)) for t in rec.content.scheduled_times] return times
Example #11
Source File: client.py From SplunkAdmins with Apache License 2.0 | 6 votes |
def scheduled_times(self, earliest_time='now', latest_time='+1h'): """Returns the times when this search is scheduled to run. By default this method returns the times in the next hour. For different time ranges, set *earliest_time* and *latest_time*. For example, for all times in the last day use "earliest_time=-1d" and "latest_time=now". :param earliest_time: The earliest time. :type earliest_time: ``string`` :param latest_time: The latest time. :type latest_time: ``string`` :return: The list of search times. """ response = self.get("scheduled_times", earliest_time=earliest_time, latest_time=latest_time) data = self._load_atom_entry(response) rec = _parse_atom_entry(data) times = [datetime.fromtimestamp(int(t)) for t in rec.content.scheduled_times] return times
Example #12
Source File: client.py From SplunkAdmins with Apache License 2.0 | 6 votes |
def scheduled_times(self, earliest_time='now', latest_time='+1h'): """Returns the times when this search is scheduled to run. By default this method returns the times in the next hour. For different time ranges, set *earliest_time* and *latest_time*. For example, for all times in the last day use "earliest_time=-1d" and "latest_time=now". :param earliest_time: The earliest time. :type earliest_time: ``string`` :param latest_time: The latest time. :type latest_time: ``string`` :return: The list of search times. """ response = self.get("scheduled_times", earliest_time=earliest_time, latest_time=latest_time) data = self._load_atom_entry(response) rec = _parse_atom_entry(data) times = [datetime.fromtimestamp(int(t)) for t in rec.content.scheduled_times] return times
Example #13
Source File: test_datetime.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_negative_float_fromtimestamp(self): # The result is tz-dependent; at least test that this doesn't # fail (like it did before bug 1646728 was fixed). self.theclass.fromtimestamp(-1.05)
Example #14
Source File: test_datetime.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_fromtimestamp(self): import time # Try an arbitrary fixed value. year, month, day = 1999, 9, 19 ts = time.mktime((year, month, day, 0, 0, 0, 0, 0, -1)) d = self.theclass.fromtimestamp(ts) self.assertEqual(d.year, year) self.assertEqual(d.month, month) self.assertEqual(d.day, day)
Example #15
Source File: test_datetime.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_tzinfo_fromtimestamp(self): import time meth = self.theclass.fromtimestamp ts = time.time() # Ensure it doesn't require tzinfo (i.e., that this doesn't blow up). base = meth(ts) # Try with and without naming the keyword. off42 = FixedOffset(42, "42") another = meth(ts, off42) again = meth(ts, tz=off42) self.assertTrue(another.tzinfo is again.tzinfo) self.assertEqual(another.utcoffset(), timedelta(minutes=42)) # Bad argument with and w/o naming the keyword. self.assertRaises(TypeError, meth, ts, 16) self.assertRaises(TypeError, meth, ts, tzinfo=16) # Bad keyword name. self.assertRaises(TypeError, meth, ts, tinfo=off42) # Too many args. self.assertRaises(TypeError, meth, ts, off42, off42) # Too few args. self.assertRaises(TypeError, meth) # Try to make sure tz= actually does some conversion. timestamp = 1000000000 utcdatetime = datetime.utcfromtimestamp(timestamp) # In POSIX (epoch 1970), that's 2001-09-09 01:46:40 UTC, give or take. # But on some flavor of Mac, it's nowhere near that. So we can't have # any idea here what time that actually is, we can only test that # relative changes match. utcoffset = timedelta(hours=-15, minutes=39) # arbitrary, but not zero tz = FixedOffset(utcoffset, "tz", 0) expected = utcdatetime + utcoffset got = datetime.fromtimestamp(timestamp, tz) self.assertEqual(expected, got.replace(tzinfo=None))
Example #16
Source File: test_datetime.py From medicare-demo with Apache License 2.0 | 5 votes |
def test_fromtimestamp(self): import time ts = time.time() expected = time.localtime(ts) got = self.theclass.fromtimestamp(ts) self.verify_field_equality(expected, got)
Example #17
Source File: test_datetime.py From medicare-demo with Apache License 2.0 | 5 votes |
def test_insane_fromtimestamp(self): # It's possible that some platform maps time_t to double, # and that this test will fail there. This test should # exempt such platforms (provided they return reasonable # results!). for insane in -1e200, 1e200: self.assertRaises(ValueError, self.theclass.fromtimestamp, insane)
Example #18
Source File: data_loader.py From LDG with Educational Community License v2.0 | 5 votes |
def __getitem__(self, index): tpl = self.all_events[index] u, v, rel, time_cur = tpl # Compute time delta in seconds (t_p - \bar{t}_p_j) that will be fed to W_t time_delta_uv = np.zeros((2, 4)) # two nodes x 4 values # most recent previous time for all nodes time_bar = self.time_bar.copy() assert u != v, (tpl, rel) for c, j in enumerate([u, v]): t = datetime.fromtimestamp(self.time_bar[j], tz=self.TZ) if t.toordinal() >= self.FIRST_DATE.toordinal(): # assume no events before FIRST_DATE td = time_cur - t time_delta_uv[c] = np.array([td.days, # total number of days, still can be a big number td.seconds // 3600, # hours, max 24 (td.seconds // 60) % 60, # minutes, max 60 td.seconds % 60], # seconds, max 60 np.float) # assert time_delta_uv.min() >= 0, (index, tpl, time_delta_uv[c], node_global_time[j]) else: raise ValueError('unexpected result', t, self.FIRST_DATE) self.time_bar[j] = time_cur.timestamp() # last time stamp for nodes u and v k = self.event_types_num[rel] # sanity checks assert np.float64(time_cur.timestamp()) == time_cur.timestamp(), ( np.float64(time_cur.timestamp()), time_cur.timestamp()) time_cur = np.float64(time_cur.timestamp()) time_bar = time_bar.astype(np.float64) time_cur = torch.from_numpy(np.array([time_cur])).double() assert time_bar.max() <= time_cur, (time_bar.max(), time_cur) return u, v, time_delta_uv, k, time_bar, time_cur
Example #19
Source File: test_datetime.py From medicare-demo with Apache License 2.0 | 5 votes |
def test_fromtimestamp(self): import time # Try an arbitrary fixed value. year, month, day = 1999, 9, 19 ts = time.mktime((year, month, day, 0, 0, 0, 0, 0, -1)) d = self.theclass.fromtimestamp(ts) self.assertEqual(d.year, year) self.assertEqual(d.month, month) self.assertEqual(d.day, day)
Example #20
Source File: test_datetime.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_tzinfo_fromtimestamp(self): import time meth = self.theclass.fromtimestamp ts = time.time() # Ensure it doesn't require tzinfo (i.e., that this doesn't blow up). base = meth(ts) # Try with and without naming the keyword. off42 = FixedOffset(42, "42") another = meth(ts, off42) again = meth(ts, tz=off42) self.assertIs(another.tzinfo, again.tzinfo) self.assertEqual(another.utcoffset(), timedelta(minutes=42)) # Bad argument with and w/o naming the keyword. self.assertRaises(TypeError, meth, ts, 16) self.assertRaises(TypeError, meth, ts, tzinfo=16) # Bad keyword name. self.assertRaises(TypeError, meth, ts, tinfo=off42) # Too many args. self.assertRaises(TypeError, meth, ts, off42, off42) # Too few args. self.assertRaises(TypeError, meth) # Try to make sure tz= actually does some conversion. timestamp = 1000000000 utcdatetime = datetime.utcfromtimestamp(timestamp) # In POSIX (epoch 1970), that's 2001-09-09 01:46:40 UTC, give or take. # But on some flavor of Mac, it's nowhere near that. So we can't have # any idea here what time that actually is, we can only test that # relative changes match. utcoffset = timedelta(hours=-15, minutes=39) # arbitrary, but not zero tz = FixedOffset(utcoffset, "tz", 0) expected = utcdatetime + utcoffset got = datetime.fromtimestamp(timestamp, tz) self.assertEqual(expected, got.replace(tzinfo=None))
Example #21
Source File: test_datetime.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_negative_float_fromtimestamp(self): # The result is tz-dependent; at least test that this doesn't # fail (like it did before bug 1646728 was fixed). self.theclass.fromtimestamp(-1.05)
Example #22
Source File: test_datetime.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_insane_fromtimestamp(self): # It's possible that some platform maps time_t to double, # and that this test will fail there. This test should # exempt such platforms (provided they return reasonable # results!). for insane in -1e200, 1e200: self.assertRaises(ValueError, self.theclass.fromtimestamp, insane)
Example #23
Source File: test_datetime.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_fromtimestamp(self): import time ts = time.time() expected = time.localtime(ts) got = self.theclass.fromtimestamp(ts) self.verify_field_equality(expected, got)
Example #24
Source File: test_datetime.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_microsecond_rounding(self): # Test whether fromtimestamp "rounds up" floats that are less # than one microsecond smaller than an integer. self.assertEqual(self.theclass.fromtimestamp(0.9999999), self.theclass.fromtimestamp(1))
Example #25
Source File: test_datetime.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_microsecond_rounding(self): # Test whether fromtimestamp "rounds up" floats that are less # than one microsecond smaller than an integer. self.assertEqual(self.theclass.fromtimestamp(0.9999999), self.theclass.fromtimestamp(1))
Example #26
Source File: test_datetime.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_fromtimestamp(self): import time ts = time.time() expected = time.localtime(ts) got = self.theclass.fromtimestamp(ts) self.verify_field_equality(expected, got)
Example #27
Source File: test_datetime.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_insane_fromtimestamp(self): # It's possible that some platform maps time_t to double, # and that this test will fail there. This test should # exempt such platforms (provided they return reasonable # results!). for insane in -1e200, 1e200: self.assertRaises(ValueError, self.theclass.fromtimestamp, insane)
Example #28
Source File: test_datetime.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_fromtimestamp(self): import time # Try an arbitrary fixed value. year, month, day = 1999, 9, 19 ts = time.mktime((year, month, day, 0, 0, 0, 0, 0, -1)) d = self.theclass.fromtimestamp(ts) self.assertEqual(d.year, year) self.assertEqual(d.month, month) self.assertEqual(d.day, day)
Example #29
Source File: test_datetime.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_negative_float_fromtimestamp(self): # The result is tz-dependent; at least test that this doesn't # fail (like it did before bug 1646728 was fixed). self.theclass.fromtimestamp(-1.05)
Example #30
Source File: test_datetime.py From medicare-demo with Apache License 2.0 | 5 votes |
def test_negative_float_fromtimestamp(self): # Windows doesn't accept negative timestamps if os.name == "nt": return # The result is tz-dependent; at least test that this doesn't # fail (like it did before bug 1646728 was fixed). self.theclass.fromtimestamp(-1.05)