Exemple #1
0
def local_datetime_to_utc_as_str(target: datetime) -> str:
    """Make datetime string representation in UTC timezone. Use it just for local time!

    Return:
         String representation of without and taking into the account time zone formatted in UTC timezone.
            Do not make changes if already in UTC timezone or does not have any.
    """
    if target.tzinfo is None or not target.utcoffset(
    ) or target.tzinfo == pytz.utc:
        target = target.replace(tzinfo=datetime.timezone.utc)
        return target.isoformat()

    utc_offset_timedelta = datetime.datetime.utcnow() - datetime.datetime.now()
    target = target.replace(tzinfo=datetime.timezone.utc)
    result_utc_datetime = target + utc_offset_timedelta
    return result_utc_datetime.isoformat()
Exemple #2
0
    def create_incident(self, product_id, key, title, resolution_on: datetime, ttd, tte, ttf, url):
        response = requests.post(self.host + "/incidents", json={"productId": product_id,
                                                                 "key": key,
                                                                 "title": title
                                                                 },
                                 verify=False)
        OwlveyGateway.__validate_status_code(response)
        incident_id = response.json()["id"]
        response = requests.put(self.host + "/incidents/{}".format(incident_id),
                                json={"title": title, "ttd": ttd, "tte": tte, "ttf": ttf, "url": url,
                                      "affected": 1,
                                      "end": resolution_on.isoformat()},
                                verify=False)
        OwlveyGateway.__validate_status_code(response)

        return response.json()
Exemple #3
0
def datetime_to_utc_as_str(target: datetime) -> str:
    """Make datetime string representation in UTC timezone.

    Return:
        String representation of without and taking into the account time zone formatted in UTC timezone.
            If no timezone - UTC timezone will be added.
        Examples:
            - 2020-04-03 05:00:07.086149+00:00 -> 2020-04-03 05:00:07.086149+00:00
            - 2020-04-03 05:00:07.086149+02:00 -> 2020-04-03 03:00:07.086149+00:00
    """
    if target.tzinfo is None or not target.utcoffset() or target.tzinfo == pytz.utc:
        target = target.replace(tzinfo=datetime.timezone.utc)
        return target.isoformat()

    # to this part we should get only datetime with particular timezone offset
    res = target.astimezone(pytz.utc).replace(tzinfo=datetime.timezone.utc)
    return res.isoformat()
Exemple #4
0
 def get_stock_listing_xlsx(
     market: Market,
     latest: bool = False,
     day: datetime = datetime.date.today()) -> str:
     listing_folder = Utility.get_data_folder(
         market=market, folder=DataFolder.Stock_Listing)
     if latest:
         # return latest listing file from the listing folder
         files = glob.glob(os.path.join(listing_folder, 'listing_*.xlsx'))
         if not files:
             raise FileExistsError(
                 'Cannot find latest stock listing file in %s' %
                 listing_folder)
         return files[-1]
     else:
         # return file with date stamp as $day
         return os.path.join(listing_folder,
                             'listing_%s.xlsx' % day.isoformat())
Exemple #5
0
def fixUtcDate(my_date: datetime) -> datetime:
    try:
        tmp_dt1 = my_date.isoformat().replace("+00:00", "+04:00")
        return dateutil.parser.parse(tmp_dt1)

    except Exception as e:
        if e.__dict__.__len__() == 0 or "done" not in e.__dict__:
            exception_type, exception_object, exception_traceback = sys.exc_info(
            )
            exception_info = e.__repr__()
            filename = exception_traceback.tb_frame.f_code.co_filename
            funcname = exception_traceback.tb_frame.f_code.co_name
            line_number = exception_traceback.tb_lineno
            e.info = {
                "i": str(exception_info),
                "n": funcname,
                "f": filename,
                "l": line_number,
            }
            e.done = True
        raise e
Exemple #6
0
def gdateformat(date: datetime):
    """Given a date, format it so that Google Cal HTTP API likes it."""
    return date.isoformat() + 'Z'
Exemple #7
0
 def expected_payment_date(self, date: datetime):
     """ Expected payment date """
     self.recurrence["expected_payment_date"] = date.isoformat()
Exemple #8
0
 def date_to_rfc3339(date: datetime) -> str:
     """
     Date as 'yyyy-mm-dd'
     """
     return date.isoformat(sep='T').split('T')[0]
Exemple #9
0
def formatted_time_ago(dt: datetime) -> str:
    ago = timeago.format(dt, datetime.datetime.now(datetime.timezone.utc))
    full = dt.isoformat(timespec="seconds")
    return colored(f"{full} ~ {ago}", attrs=["dark"])
Exemple #10
0
def convert_date_to_str_for_db(dateToBeConverted: datetime):
    date = dateToBeConverted.isoformat("|", "minutes")
    #print("Converted date:")
    #print(date)
    return date