???????????????????????????? ??????????????/????????????????? ............/............... .........................../... ????????????????????????????? >>>>>>>>>>>>>/>>>>>>>>>>>>>>>>> ÿØÿà JFIF    ÿÛ „  ( %!1!%)+//.383,7(-.+  -%%-////---/-.+/--+------/------/--0+--/-/-----.-----ÿÀ  ¥2" ÿÄ     ÿÄ J    ! 1AQ"aq2‘#BR‚¡ÁÑ3br’¢±Âð$CSƒ²á4c“%DsÓñÿÄ   ÿÄ *  !1AQa‘"2q3±ð#b¡ÿÚ   ? ¼QxJQaÍuò¸Zö Úü8,ÐÚú "SSn<rçù–´âE—^ªBÖ9À\†¸ÔÁT­ÃÛ5 ëd´³Í#Ý;Þ38œî ¶H£M:wÎ3…³…âpÔF&‚FK¸9„â4àGEõªfÿ ‘ñ(ßw­pŽF|È¥ù®häðÍѶ¹‘[ÒinÙW¶ùñY˜Q{›K"išÒ[Ú8žë\F¹@-?v"ÔU”,ìöžkÿ {I‡£šÍ?e ríV ?> ......................................... ............................................................................. <<<<<<<<<<<<<<<<<<<<<<<<<<<<<< >>>>>>>>>>>>>/>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ???????????????????????????? ??????????????/????????????????? ............/............... .........................../... ????????????????????????????? >>>>>>>>>>>>>/>>>>>>>>>>>>>>>>> ÿØÿà JFIF    ÿÛ „  ( %!1!%)+//.383,7(-.+  -%%-////---/-.+/--+------/------/--0+--/-/-----.-----ÿÀ  ¥2" ÿÄ     ÿÄ J    ! 1AQ"aq2‘#BR‚¡ÁÑ3br’¢±Âð$CSƒ²á4c“%DsÓñÿÄ   ÿÄ *  !1AQa‘"2q3±ð#b¡ÿÚ   ? ¼QxJQaÍuò¸Zö Úü8,ÐÚú "SSn<rçù–´âE—^ªBÖ9À\†¸ÔÁT­ÃÛ5 ëd´³Í#Ý;Þ38œî ¶H£M:wÎ3…³…âpÔF&‚FK¸9„â4àGEõªfÿ ‘ñ(ßw­pŽF|È¥ù®häðÍѶ¹‘[ÒinÙW¶ùñY˜Q{›K"išÒ[Ú8žë\F¹@-?v"ÔU”,ìöžkÿ {I‡£šÍ?e ríV ?> ......................................... ............................................................................. <<<<<<<<<<<<<<<<<<<<<<<<<<<<<< >>>>>>>>>>>>>/>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ Convenience functions for dealing with datetime classes """ import datetime import salt.utils.stringutils from salt.utils.decorators.jinja import jinja_filter try: import timelib HAS_TIMELIB = True except ImportError: HAS_TIMELIB = False def date_cast(date): """ Casts any object into a datetime.datetime object date any datetime, time string representation... """ if date is None: return datetime.datetime.now() elif isinstance(date, datetime.datetime): return date # fuzzy date try: if isinstance(date, str): try: if HAS_TIMELIB: # py3: yes, timelib.strtodatetime wants bytes, not str :/ return timelib.strtodatetime(salt.utils.stringutils.to_bytes(date)) except ValueError: pass # not parsed yet, obviously a timestamp? if date.isdigit(): date = int(date) else: date = float(date) return datetime.datetime.fromtimestamp(date) except Exception: # pylint: disable=broad-except if HAS_TIMELIB: raise ValueError(f"Unable to parse {date}") raise RuntimeError(f"Unable to parse {date}. Consider installing timelib") @jinja_filter("date_format") @jinja_filter("strftime") def strftime(date=None, format="%Y-%m-%d"): """ Converts date into a time-based string date any datetime, time string representation... format :ref:`strftime` format >>> import datetime >>> src = datetime.datetime(2002, 12, 25, 12, 00, 00, 00) >>> strftime(src) '2002-12-25' >>> src = '2002/12/25' >>> strftime(src) '2002-12-25' >>> src = 1040814000 >>> strftime(src) '2002-12-25' >>> src = '1040814000' >>> strftime(src) '2002-12-25' """ return date_cast(date).strftime(format) def total_seconds(td): """ Takes a timedelta and returns the total number of seconds represented by the object. Wrapper for the total_seconds() method which does not exist in versions of Python < 2.7. """ return (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6