• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

localstack / localstack / 18505123992

14 Oct 2025 05:30PM UTC coverage: 86.888% (-0.01%) from 86.899%
18505123992

push

github

web-flow
S3: fix `aws-global` validation in CreateBucket (#13250)

10 of 10 new or added lines in 4 files covered. (100.0%)

831 existing lines in 40 files now uncovered.

68028 of 78294 relevant lines covered (86.89%)

0.87 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.23
/localstack-core/localstack/utils/time.py
1
import time
1✔
2
from datetime import date, datetime, timezone, tzinfo
1✔
3
from zoneinfo import ZoneInfo
1✔
4

5
TIMESTAMP_FORMAT = "%Y-%m-%dT%H:%M:%S"
1✔
6
TIMESTAMP_FORMAT_TZ = "%Y-%m-%dT%H:%M:%SZ"
1✔
7
TIMESTAMP_FORMAT_MICROS = "%Y-%m-%dT%H:%M:%S.%fZ"
1✔
8
TIMESTAMP_READABLE_FORMAT = "%d/%b/%Y:%H:%M:%S %z"
1✔
9

10

11
def isoformat_milliseconds(t) -> str:
1✔
12
    try:
1✔
13
        return t.isoformat(timespec="milliseconds")
1✔
UNCOV
14
    except TypeError:
×
15
        return t.isoformat()[:-3]
×
16

17

18
def timestamp(time=None, format: str = TIMESTAMP_FORMAT) -> str:
1✔
19
    if not time:
1✔
20
        time = datetime.utcnow()
1✔
21
    if isinstance(time, (int, float)):
1✔
22
        time = datetime.fromtimestamp(time)
1✔
23
    return time.strftime(format)
1✔
24

25

26
def timestamp_millis(time=None) -> str:
1✔
27
    microsecond_time = timestamp(time=time, format=TIMESTAMP_FORMAT_MICROS)
1✔
28
    # truncating microseconds to milliseconds, while leaving the "Z" indicator
29
    return microsecond_time[:-4] + microsecond_time[-1]
1✔
30

31

32
def iso1806_to_epoch(t: str) -> float:
1✔
UNCOV
33
    return datetime.fromisoformat(t).timestamp()
×
34

35

36
def epoch_to_iso1806(ts: int) -> str:
1✔
UNCOV
37
    return datetime.utcfromtimestamp(ts).isoformat()
×
38

39

40
def epoch_timestamp() -> float:
1✔
UNCOV
41
    return time.time()
×
42

43

44
def parse_timestamp(ts_str: str) -> datetime:
1✔
45
    """
46
    Parse the incoming date string into a timezone aware datetime object
47
    :param ts_str:
48
    :return:
49
    """
50
    for ts_format in [
1✔
51
        TIMESTAMP_FORMAT,
52
        TIMESTAMP_FORMAT_TZ,
53
        TIMESTAMP_FORMAT_MICROS,
54
        TIMESTAMP_READABLE_FORMAT,
55
    ]:
56
        try:
1✔
57
            value = datetime.strptime(ts_str, ts_format)
1✔
58
            if value.tzinfo is None:
1✔
59
                value = value.replace(tzinfo=ZoneInfo("UTC"))
1✔
60
            return value
1✔
61
        except ValueError:
1✔
62
            pass
1✔
UNCOV
63
    raise Exception(f"Unable to parse timestamp string with any known formats: {ts_str}")
×
64

65

66
def now(millis: bool = False, tz: tzinfo | None = None) -> int:
1✔
67
    return mktime(datetime.now(tz=tz), millis=millis)
1✔
68

69

70
def now_utc(millis: bool = False) -> int:
1✔
71
    return now(millis, timezone.utc)
1✔
72

73

74
def today_no_time() -> int:
1✔
75
    return mktime(datetime.combine(date.today(), datetime.min.time()))
1✔
76

77

78
def mktime(ts: datetime, millis: bool = False) -> int:
1✔
79
    if millis:
1✔
80
        return int(ts.timestamp() * 1000)
1✔
81
    return int(ts.timestamp())
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc