wwvb 4.1.0a0__py3-none-any.whl → 5.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,169 +0,0 @@
1
- # SPDX-FileCopyrightText: 2022 Jeff Epler
2
- #
3
- # SPDX-License-Identifier: GPL-3.0-only
4
-
5
- """Commandline interface to leap second data"""
6
-
7
- from __future__ import annotations
8
-
9
- import datetime
10
- import logging
11
- import typing
12
- from dataclasses import dataclass
13
-
14
- import click
15
-
16
- from . import LeapSecondData, tai
17
-
18
- utc = datetime.timezone.utc
19
-
20
-
21
- def utcnow() -> datetime.datetime:
22
- """Return the current time in UTC, with tzinfo=utc"""
23
- return datetime.datetime.now(utc)
24
-
25
-
26
- class UTCDateTime(click.DateTime):
27
- """Click option class for date time in UTC"""
28
-
29
- def convert(
30
- self,
31
- value: typing.Any,
32
- param: click.Parameter | None,
33
- ctx: click.Context | None,
34
- ) -> typing.Any:
35
- """Convert the value then attach the utc timezone"""
36
- converted = super().convert(value, param, ctx)
37
- if converted is not None:
38
- return converted.replace(tzinfo=utc)
39
- return converted # pragma no cover
40
-
41
-
42
- @dataclass
43
- class State:
44
- """State shared across sub-commands"""
45
-
46
- leap_second_data: LeapSecondData
47
-
48
-
49
- @click.group()
50
- @click.option(
51
- "--url",
52
- type=str,
53
- default=None,
54
- help="URL for leap second data (unspecified to use default source)",
55
- )
56
- @click.option("--debug/--no-debug", type=bool)
57
- @click.pass_context
58
- def cli(ctx: click.Context, *, url: str, debug: bool) -> None:
59
- """Access leap second database information"""
60
- if debug: # pragma no cover
61
- logging.getLogger().setLevel(logging.DEBUG)
62
- if ctx.find_object(LeapSecondData) is None: # pragma no branch
63
- if url is None:
64
- ctx.obj = LeapSecondData.from_standard_source()
65
- else: # pragma no cover
66
- ctx.obj = LeapSecondData.from_url(url)
67
-
68
-
69
- @cli.command()
70
- @click.pass_context
71
- def info(ctx: click.Context) -> None:
72
- """Show information about leap second database"""
73
- leap_second_data = ctx.obj
74
- print(f"Last updated: {leap_second_data.last_updated:%Y-%m-%d}")
75
- print(f"Valid until: {leap_second_data.valid_until:%Y-%m-%d}")
76
- # The first leap_seconds entry
77
- print(f"{len(leap_second_data.leap_seconds)-1} leap seconds")
78
-
79
-
80
- @cli.command()
81
- @click.pass_context
82
- @click.option("--tai/--utc", "is_tai", default=False)
83
- @click.argument("timestamp", type=UTCDateTime(), default=utcnow(), metavar="TIMESTAMP")
84
- def offset(ctx: click.Context, *, is_tai: bool, timestamp: datetime.datetime) -> None:
85
- """Get the UTC offset for a given moment, in seconds"""
86
- leap_second_data = ctx.obj
87
- if is_tai:
88
- timestamp = timestamp.replace(tzinfo=tai)
89
- print(f"{leap_second_data.tai_offset(timestamp).total_seconds():.0f}")
90
-
91
-
92
- @cli.command()
93
- @click.pass_context
94
- @click.option("--to-tai/--to-utc", default=True)
95
- @click.argument("timestamp", type=UTCDateTime(), default=None, required=False, metavar="TIMESTAMP")
96
- def convert(ctx: click.Context, *, to_tai: bool, timestamp: datetime.datetime | None = None) -> None:
97
- """Convert timestamps between TAI and UTC"""
98
- leap_second_data = ctx.obj
99
- if to_tai:
100
- if timestamp is None:
101
- timestamp = utcnow()
102
- when_tai = leap_second_data.to_tai(timestamp)
103
- print(f"{when_tai:%Y-%m-%d %H:%M:%S} TAI")
104
- else:
105
- if timestamp is None: # pragma no cover
106
- raise click.UsageError("--to-utc requires explicit timestamp", ctx)
107
- when_utc = leap_second_data.tai_to_utc(timestamp.replace(tzinfo=tai))
108
- if when_utc.fold:
109
- print(f"{when_utc:%Y-%m-%d %H:%M:60} UTC")
110
- else:
111
- print(f"{when_utc:%Y-%m-%d %H:%M:%S} UTC")
112
-
113
-
114
- @cli.command()
115
- @click.pass_context
116
- @click.argument("timestamp", type=UTCDateTime(), default=utcnow(), metavar="TIMESTAMP")
117
- def next_leapsecond(ctx: click.Context, *, timestamp: datetime.datetime) -> None:
118
- """Get the next leap second after a given UTC timestamp"""
119
- leap_second_data = ctx.obj
120
- ls = min(
121
- (ls for ls in leap_second_data.leap_seconds if ls.start > timestamp),
122
- default=None,
123
- key=lambda x: x.start,
124
- )
125
- if ls is None:
126
- print("None")
127
- else:
128
- print(f"{ls.start:%Y-%m-%d %H:%M:%S} UTC")
129
-
130
-
131
- @cli.command()
132
- @click.pass_context
133
- @click.argument("timestamp", type=UTCDateTime(), default=utcnow(), metavar="TIMESTAMP")
134
- def previous_leapsecond(ctx: click.Context, *, timestamp: datetime.datetime) -> None:
135
- """Get the last leap second before a given UTC timestamp"""
136
- leap_second_data = ctx.obj
137
- ls = max(
138
- (ls for ls in leap_second_data.leap_seconds if ls.start < timestamp),
139
- default=None,
140
- key=lambda x: x.start,
141
- )
142
- if ls is None:
143
- print("None")
144
- else:
145
- print(f"{ls.start:%Y-%m-%d %H:%M:%S} UTC")
146
-
147
-
148
- @cli.command()
149
- @click.argument(
150
- "start",
151
- type=UTCDateTime(),
152
- default=datetime.datetime(1972, 1, 1, tzinfo=utc),
153
- metavar="START-TIMESTAMP",
154
- )
155
- @click.argument("end", type=UTCDateTime(), default=utcnow(), metavar="[END-TIMESTAMP]")
156
- @click.pass_context
157
- def table(ctx: click.Context, *, start: datetime.datetime, end: datetime.datetime) -> None:
158
- """Print information about leap seconds"""
159
- leap_second_data = ctx.obj
160
- for leap_second in leap_second_data.leap_seconds: # pragma no branch
161
- if leap_second.start < start:
162
- continue
163
- if leap_second.start > end:
164
- break
165
- print(f"{leap_second.start:%Y-%m-%d}: {leap_second.tai_offset.total_seconds():.0f}")
166
-
167
-
168
- if __name__ == "__main__": # pragma no cover
169
- cli()
@@ -1,60 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: wwvb
3
- Version: 4.1.0a0
4
- Summary: Use the list of known and scheduled leap seconds
5
- Author-email: Jeff Epler <jepler@gmail.com>
6
- Project-URL: Source, https://github.com/jepler/leapseconddata
7
- Project-URL: Documentation, https://leapseconddata.readthedocs.io/en/latest/
8
- Classifier: Programming Language :: Python :: 3
9
- Classifier: Programming Language :: Python :: 3.9
10
- Classifier: Programming Language :: Python :: 3.10
11
- Classifier: Programming Language :: Python :: 3.11
12
- Classifier: Programming Language :: Python :: Implementation :: PyPy
13
- Classifier: Programming Language :: Python :: Implementation :: CPython
14
- Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
15
- Classifier: Operating System :: OS Independent
16
- Requires-Python: >=3.9
17
- Description-Content-Type: text/markdown
18
- Requires-Dist: click
19
-
20
- <!--
21
- SPDX-FileCopyrightText: 2021 Jeff Epler
22
-
23
- SPDX-License-Identifier: GPL-3.0-only
24
- -->
25
- [![Test leapseconddata](https://github.com/jepler/leapseconddata/actions/workflows/test.yml/badge.svg)](https://github.com/jepler/leapseconddata/actions/workflows/test.yml)
26
- [![PyPI](https://img.shields.io/pypi/v/leapseconddata)](https://pypi.org/project/leapseconddata)
27
- [![Documentation Status](https://readthedocs.org/projects/leapseconddata/badge/?version=latest)](https://leapseconddata.readthedocs.io/en/latest/?badge=latest)
28
-
29
- # Python Leap Second List
30
-
31
- Leap seconds are corrections applied irregularly so that the UTC day stays
32
- fixed to the earth's rotation.
33
-
34
- This module provides a class for parsing and validating the standard
35
- `leap-seconds.list` file. Once parsed, it is possible to retrieve the
36
- full list of leap seconds, or find the TAI-UTC offset for any UTC time.
37
-
38
- # `leapsecond` program
39
-
40
- Access leap second data from the command line.
41
-
42
- ```
43
- Usage: leapsecond [OPTIONS] COMMAND [ARGS]...
44
-
45
- Access leap second database information
46
-
47
- Options:
48
- --url TEXT URL for leap second data (unspecified to use default
49
- source)
50
- --debug / --no-debug
51
- --help Show this message and exit.
52
-
53
- Commands:
54
- convert Convert timestamps between TAI and UTC
55
- info Show information about leap second database
56
- next-leapsecond Get the next leap second after a given UTC timestamp
57
- offset Get the UTC offset for a given moment, in seconds
58
- previous-leapsecond Get the last leap second before a given UTC timestamp
59
- table Print information about leap seconds
60
- ```
@@ -1,9 +0,0 @@
1
- leapseconddata/__init__.py,sha256=UyHCvvcJjbIugNEEQDf45HmhzFiIe77fNVGRMm7eNdg,13017
2
- leapseconddata/__main__.py,sha256=c26T1gFoVwh1goK0_mRCQ3-lAsz8eCFYf8aFi0nESf8,5405
3
- leapseconddata/__version__.py,sha256=XeG8WsGuH3HJ5DBhMc289w1eiYW9-G0-4h58Y3MV650,413
4
- leapseconddata/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
- wwvb-4.1.0a0.dist-info/METADATA,sha256=KmLslzML53yHVtNANGMbfuL4t4Xu5OvevkIC85tnWEw,2496
6
- wwvb-4.1.0a0.dist-info/WHEEL,sha256=Z4pYXqR_rTB7OWNDYFOm1qRk0RX6GFP2o8LgvP453Hk,91
7
- wwvb-4.1.0a0.dist-info/entry_points.txt,sha256=Ca5FvuhALDcLhQrO8H7l91Bg0hjkxkzLEwLU-9qY9dk,59
8
- wwvb-4.1.0a0.dist-info/top_level.txt,sha256=82tQRfAH4hrno1b9AR-UhFUHrbBxENUJ2aUtEH-ctTs,15
9
- wwvb-4.1.0a0.dist-info/RECORD,,
@@ -1,2 +0,0 @@
1
- [console_scripts]
2
- leapsecond = leapseconddata.__main__:cli
@@ -1 +0,0 @@
1
- leapseconddata
File without changes