def extract_date(cls, data, field_name): if field_name not in data or not data[field_name]: d = None else: # OdiloAPI dates are timestamps in milliseconds d = from_timestamp(float(data[field_name]) / 1000.0) return d
def __init__(self, name_id, attribute_statement, valid_till=None): """Initializes a new instance of Subject class :param name_id: Name ID :type name_id: SAMLNameID :param attribute_statement: Attribute statement :type attribute_statement: SAMLAttributeStatement :param valid_till: Time till which the subject is valid The default value is 30 minutes Please refer to the Shibboleth IdP documentation for more details: - https://wiki.shibboleth.net/confluence/display/IDP30/SessionConfiguration :type valid_till: Optional[Union[datetime.datetime, datetime.timedelta]] """ self._name_id = name_id self._attribute_statement = attribute_statement self._valid_till = valid_till if valid_till is None: self._valid_till = datetime.timedelta(minutes=30) elif isinstance(valid_till, datetime.datetime): self._valid_till = valid_till - utc_now() elif isinstance(valid_till, int): self._valid_till = from_timestamp(valid_till) - utc_now() elif isinstance(valid_till, datetime.timedelta): self._valid_till = valid_till else: raise ValueError("valid_till is not valid")
def _parse_saml_date_time(saml_date_time): """Parse the string containing date & time information in the SAML format into datetime object. :param saml_date_time: String containing date & time information in the SAML format :type saml_date_time: str """ unix_timestamp = OneLogin_Saml2_Utils.parse_SAML_to_time( saml_date_time) parsed_date_time = from_timestamp(unix_timestamp) return parsed_date_time
def test_from_timestamp(self): """`from_timestamp` is a wrapper around `datetime.fromtimestamp` that also includes UTC information. """ ts = 0 datetime_from_ts = datetime.datetime.fromtimestamp(ts, tz=pytz.UTC) util_from_ts = from_timestamp(ts) # The util function returns the right datetime object from a timestamp. assert datetime_from_ts == util_from_ts assert datetime_from_ts.strftime("%Y-%m-%d") == "1970-01-01" assert util_from_ts.strftime("%Y-%m-%d") == "1970-01-01" # The UTC information for this datetime object is the pytz UTC value. assert util_from_ts.tzinfo is not None assert util_from_ts.tzinfo == pytz.UTC
def recent_activity(self, start, end): """Find circulation events from a certain timeframe that affected loans or holds. :param start: A DateTime :yield: A sequence of CirculationData objects. """ epoch = from_timestamp(0) start = int((start - epoch).total_seconds()) end = int((end - epoch).total_seconds()) url = self.base_url + self.item_endpoint args = dict(method="getRecentActivityTime", stime=str(start), etime=str(end)) response = self.request(url, params=args) data = json.loads(response.content) parser = BibliographicParser() for element in data["result"]["recentactivity"]: identifier = IdentifierData(Identifier.ENKI_ID, element["id"]) yield parser.extract_circulation( identifier, element["availability"], None, # The recent activity API does not include format info )