Skip to content
This repository was archived by the owner on Aug 10, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions eyes_common/applitools/common/config/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from applitools.common.geometry import RectangleSize
from applitools.common.match import ImageMatchSettings, MatchLevel
from applitools.common.server import FailureReports, SessionType
from applitools.common.utils import argument_guard, general_utils
from applitools.common.utils import UTC, argument_guard
from applitools.common.utils.json_utils import JsonInclude

__all__ = ("BatchInfo", "Configuration")
Expand All @@ -30,8 +30,7 @@ class BatchInfo(object):
metadata={JsonInclude.THIS: True},
) # type: Optional[Text]
started_at = attr.ib(
factory=lambda: datetime.now(general_utils.UTC),
metadata={JsonInclude.THIS: True},
factory=lambda: datetime.now(UTC), metadata={JsonInclude.THIS: True}
) # type: Union[datetime, Text]
sequence_name = attr.ib(
init=False,
Expand Down
5 changes: 5 additions & 0 deletions eyes_common/applitools/common/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
urlsplit,
urlunsplit,
)
from .datetime_utils import ( # type: ignore # noqa
UTC,
current_time_in_rfc1123,
to_rfc1123_datetime,
)
from .general_utils import cached_property # noqa

__all__ = compat.__all__ + ("image_utils", "argument_guard") # noqa
63 changes: 63 additions & 0 deletions eyes_common/applitools/common/utils/datetime_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from datetime import datetime, timedelta, tzinfo
from typing import Text

__all__ = ("UTC", "to_rfc1123_datetime", "current_time_in_rfc1123")


class _UtcTz(tzinfo):
"""
A UTC timezone class which is tzinfo compliant.
"""

_ZERO = timedelta(0)

def utcoffset(self, dt):
return _UtcTz._ZERO

def tzname(self, dt):
return "UTC"

def dst(self, dt):
return _UtcTz._ZERO


UTC = _UtcTz()


def to_rfc1123_datetime(dt):
# type: (datetime) -> Text
"""Return a string representation of a date according to RFC 1123
(HTTP/1.1).

The supplied date must be in UTC.

"""
weekday = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"][dt.weekday()]
month = [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec",
][dt.month - 1]
return "%s, %02d %s %04d %02d:%02d:%02d GMT" % (
weekday,
dt.day,
month,
dt.year,
dt.hour,
dt.minute,
dt.second,
)


def current_time_in_rfc1123():
# type: () -> Text
return to_rfc1123_datetime(datetime.now(UTC))
22 changes: 0 additions & 22 deletions eyes_common/applitools/common/utils/general_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import itertools
import time
import typing
from datetime import timedelta, tzinfo

from applitools.common import logger

Expand All @@ -21,27 +20,6 @@
T = typing.TypeVar("T")


class _UtcTz(tzinfo):
"""
A UTC timezone class which is tzinfo compliant.
"""

_ZERO = timedelta(0)

def utcoffset(self, dt):
return _UtcTz._ZERO

def tzname(self, dt):
return "UTC"

def dst(self, dt):
return _UtcTz._ZERO


# Constant representing UTC
UTC = _UtcTz()


def use_default_if_none_factory(default_obj, obj):
def default(attr_name):
val = getattr(obj, attr_name)
Expand Down
Loading