Compare commits
39 commits
c6487774a3
...
9d8d744a36
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9d8d744a36 | ||
|
|
e7abe54821 | ||
| 08e4217636 | |||
| 7b0548071f | |||
| 7137105b18 | |||
| b859900b9b | |||
| 1bf978445e | |||
| 5afa43e2c4 | |||
| 4e3e36b53d | |||
| ad89db7a31 | |||
| 882f9d0635 | |||
| adabec27dd | |||
| 270780ab84 | |||
| 142971bd17 | |||
| 703824ff0e | |||
|
|
92a5afdfd5 | ||
| 19a2a23c21 | |||
|
|
a23e0fbaaf | ||
| c9a0b64195 | |||
| ec68ed225f | |||
| 3fc237f466 | |||
| 497164e84d | |||
| 6b57582d3e | |||
| 33459d3c6b | |||
| 8348db3c92 | |||
| 6de67679a5 | |||
| 66d4b32bf0 | |||
| 4e0d7a9743 | |||
| aae3828270 | |||
| d5c21c07dd | |||
| dc24f55598 | |||
| 6f0765d13d | |||
| 2d574f6d53 | |||
| 16090774ed | |||
| 4d1bfb8002 | |||
| f5314e2a7c | |||
| 77cfe3d79a | |||
|
|
7f2051eaf9 | ||
|
|
636d2d8282 |
17 changed files with 221 additions and 621 deletions
49
.github/workflows/codeql.yml
vendored
49
.github/workflows/codeql.yml
vendored
|
|
@ -1,49 +0,0 @@
|
|||
# SPDX-FileCopyrightText: 2022-2024 Jeff Epler
|
||||
#
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
name: "CodeQL"
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "main" ]
|
||||
pull_request:
|
||||
branches: [ "main" ]
|
||||
schedule:
|
||||
- cron: "53 3 * * 5"
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
name: Analyze
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
actions: read
|
||||
contents: read
|
||||
security-events: write
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
language: [ python ]
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Install Dependencies (python)
|
||||
run: pip3 install -r requirements-dev.txt
|
||||
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v3
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
queries: +security-and-quality
|
||||
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@v3
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v3
|
||||
with:
|
||||
category: "/language:${{ matrix.language }}"
|
||||
36
.github/workflows/test.yml
vendored
36
.github/workflows/test.yml
vendored
|
|
@ -31,6 +31,35 @@ jobs:
|
|||
- name: Build HTML docs
|
||||
run: make html
|
||||
|
||||
typing:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
python-version:
|
||||
- '3.13'
|
||||
os-version:
|
||||
- 'ubuntu-latest'
|
||||
runs-on: ${{ matrix.os-version }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
|
||||
- name: Install deps
|
||||
run: |
|
||||
python -mpip install wheel
|
||||
python -mpip install -r requirements-dev.txt
|
||||
|
||||
- name: Check stubs
|
||||
if: (! startsWith(matrix.python-version, 'pypy-'))
|
||||
run: make mypy PYTHON=python
|
||||
|
||||
|
||||
test:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
|
|
@ -40,7 +69,8 @@ jobs:
|
|||
- '3.10'
|
||||
- '3.11'
|
||||
- '3.12'
|
||||
- '3.13.0-alpha.0 - 3.13'
|
||||
- '3.13'
|
||||
- '3.14.0-alpha.0 - 3.14'
|
||||
os-version:
|
||||
- 'ubuntu-latest'
|
||||
include:
|
||||
|
|
@ -67,10 +97,6 @@ jobs:
|
|||
python -mpip install wheel
|
||||
python -mpip install -r requirements-dev.txt
|
||||
|
||||
- name: Check stubs
|
||||
if: (! startsWith(matrix.python-version, 'pypy-'))
|
||||
run: make mypy PYTHON=python
|
||||
|
||||
- name: Coverage
|
||||
run: make coverage PYTHON=python
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ repos:
|
|||
- id: reuse
|
||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||
# Ruff version.
|
||||
rev: v0.9.1
|
||||
rev: v0.11.13
|
||||
hooks:
|
||||
# Run the linter.
|
||||
- id: ruff
|
||||
|
|
|
|||
17
.readthedocs.yaml
Normal file
17
.readthedocs.yaml
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
# SPDX-FileCopyrightText: 2024 Jeff Epler
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
version: 2
|
||||
|
||||
build:
|
||||
os: ubuntu-lts-latest
|
||||
tools:
|
||||
python: "3"
|
||||
|
||||
sphinx:
|
||||
configuration: doc/conf.py
|
||||
|
||||
python:
|
||||
install:
|
||||
- requirements: requirements-dev.txt
|
||||
|
|
@ -1,73 +0,0 @@
|
|||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
2
Makefile
2
Makefile
|
|
@ -44,7 +44,7 @@ test_venv:
|
|||
|
||||
.PHONY: mypy
|
||||
mypy:
|
||||
$(Q)mypy --strict --no-warn-unused-ignores src
|
||||
$(Q)mypy --strict --no-warn-unused-ignores src test
|
||||
|
||||
.PHONY: update
|
||||
update:
|
||||
|
|
|
|||
12
README.md
12
README.md
|
|
@ -7,13 +7,11 @@ SPDX-License-Identifier: GPL-3.0-only
|
|||
[](https://codecov.io/gh/jepler/wwvbpy)
|
||||
[](https://github.com/jepler/wwvbpy/actions/workflows/cron.yml)
|
||||
[](https://pypi.org/project/wwvb)
|
||||
[](https://github.com/jepler/wwvbpy/actions/workflows/codeql.yml)
|
||||
[](https://results.pre-commit.ci/latest/github/jepler/wwvbpy/main)
|
||||
|
||||
# Purpose
|
||||
|
||||
wwvbpy generates WWVB timecodes for any desired time. These timecodes
|
||||
may be useful in testing WWVB decoder software.
|
||||
Python package and command line programs for interacting with WWVB timecodes.
|
||||
|
||||
Where possible, wwvbpy uses existing facilities for calendar and time
|
||||
manipulation (datetime and dateutil).
|
||||
|
|
@ -39,7 +37,7 @@ The package includes:
|
|||
|
||||
# Development status
|
||||
|
||||
The author (@jepler) occasionally develops and maintains this project, but
|
||||
The author ([@jepler](https://github.com/jepler)) occasionally develops and maintains this project, but
|
||||
issues are not likely to be acted on. They would be interested in adding
|
||||
co-maintainer(s).
|
||||
|
||||
|
|
@ -67,7 +65,7 @@ channel.
|
|||
# Usage
|
||||
|
||||
~~~~
|
||||
Usage: python -m wwvb.gen [OPTIONS] [TIMESPEC]...
|
||||
Usage: wwvbgen [OPTIONS] [TIMESPEC]...
|
||||
|
||||
Generate WWVB timecodes
|
||||
|
||||
|
|
@ -97,7 +95,7 @@ Options:
|
|||
|
||||
For example, to display the leap second that occurred at the end of 1998,
|
||||
~~~~
|
||||
$ python wwvbgen.py -m 7 1998 365 23 56
|
||||
$ wwvbgen -m 7 1998 365 23 56
|
||||
WWVB timecode: year=98 days=365 hour=23 min=56 dst=0 ut1=-300 ly=0 ls=1
|
||||
'98+365 23:56 210100110200100001120011001102010100010200110100121000001002
|
||||
'98+365 23:57 210100111200100001120011001102010100010200110100121000001002
|
||||
|
|
@ -119,7 +117,7 @@ The letters `a` through `u` represent offsets of -1.0s through +1.0s
|
|||
in 0.1s increments; `k` represents 0s. (In practice, only a smaller range
|
||||
of values, typically -0.7s to +0.8s, is seen)
|
||||
|
||||
For 2001 through 2019, NIST has published the actual DUT1 values broadcast,
|
||||
For 2001 through 2024, NIST has published the actual DUT1 values broadcast,
|
||||
and the date of each change, though it in the format of an HTML
|
||||
table and not designed for machine readability:
|
||||
|
||||
|
|
|
|||
|
|
@ -1,416 +0,0 @@
|
|||
# SPDX-FileCopyrightText: 2015-2021 Jukka Lehtosalo and contributors
|
||||
# SPDX-FileCopyrightText: 2021-2024 Jeff Epler
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
# ruff: noqa
|
||||
import sys
|
||||
from time import struct_time
|
||||
from typing import (
|
||||
AnyStr,
|
||||
ClassVar,
|
||||
NamedTuple,
|
||||
Optional,
|
||||
SupportsAbs,
|
||||
Tuple,
|
||||
Type,
|
||||
TypeVar,
|
||||
overload,
|
||||
)
|
||||
|
||||
_S = TypeVar("_S")
|
||||
|
||||
MINYEAR: int
|
||||
MAXYEAR: int
|
||||
|
||||
class tzinfo:
|
||||
def tzname(self, dt: Optional[datetime]) -> Optional[str]: ...
|
||||
def utcoffset(self, dt: Optional[datetime]) -> Optional[timedelta]: ...
|
||||
def dst(self, dt: Optional[datetime]) -> Optional[timedelta]: ...
|
||||
def fromutc(self, dt: datetime) -> datetime: ...
|
||||
|
||||
class timezone(tzinfo):
|
||||
utc: ClassVar[timezone]
|
||||
min: ClassVar[timezone]
|
||||
max: ClassVar[timezone]
|
||||
def __init__(self, offset: timedelta, name: str = ...) -> None: ...
|
||||
def __hash__(self) -> int: ...
|
||||
|
||||
class _IsoCalendarDate(NamedTuple):
|
||||
year: int
|
||||
week: int
|
||||
weekday: int
|
||||
|
||||
_tzinfo = tzinfo
|
||||
|
||||
class date:
|
||||
min: ClassVar[date]
|
||||
max: ClassVar[date]
|
||||
resolution: ClassVar[timedelta]
|
||||
def __new__(cls: Type[_S], year: int, month: int, day: int) -> _S: ...
|
||||
@classmethod
|
||||
def fromtimestamp(cls: Type[_S], __timestamp: float) -> _S: ...
|
||||
@classmethod
|
||||
def today(cls: Type[_S]) -> _S: ...
|
||||
@classmethod
|
||||
def fromordinal(cls: Type[_S], n: int) -> _S: ...
|
||||
if sys.version_info >= (3, 7):
|
||||
@classmethod
|
||||
def fromisoformat(cls: Type[_S], date_string: str) -> _S: ...
|
||||
if sys.version_info >= (3, 8):
|
||||
@classmethod
|
||||
def fromisocalendar(cls: Type[_S], year: int, week: int, day: int) -> _S: ...
|
||||
|
||||
@property
|
||||
def year(self) -> int: ...
|
||||
@property
|
||||
def month(self) -> int: ...
|
||||
@property
|
||||
def day(self) -> int: ...
|
||||
def ctime(self) -> str: ...
|
||||
def strftime(self, fmt: str) -> str: ...
|
||||
if sys.version_info >= (3,):
|
||||
def __format__(self, fmt: str) -> str: ...
|
||||
else:
|
||||
def __format__(self, fmt: AnyStr) -> AnyStr: ...
|
||||
|
||||
def isoformat(self) -> str: ...
|
||||
def timetuple(self) -> struct_time: ...
|
||||
def toordinal(self) -> int: ...
|
||||
def replace(self, year: int = ..., month: int = ..., day: int = ...) -> date: ...
|
||||
def __le__(self, other: date) -> bool: ...
|
||||
def __lt__(self, other: date) -> bool: ...
|
||||
def __ge__(self, other: date) -> bool: ...
|
||||
def __gt__(self, other: date) -> bool: ...
|
||||
if sys.version_info >= (3, 8):
|
||||
def __add__(self: _S, other: timedelta) -> _S: ...
|
||||
def __radd__(self: _S, other: timedelta) -> _S: ...
|
||||
else:
|
||||
def __add__(self, other: timedelta) -> date: ...
|
||||
def __radd__(self, other: timedelta) -> date: ...
|
||||
|
||||
@overload
|
||||
def __sub__(self, other: timedelta) -> date: ...
|
||||
@overload
|
||||
def __sub__(self, other: date) -> timedelta: ...
|
||||
def __hash__(self) -> int: ...
|
||||
def weekday(self) -> int: ...
|
||||
def isoweekday(self) -> int: ...
|
||||
def isocalendar(self) -> _IsoCalendarDate: ...
|
||||
|
||||
class time:
|
||||
min: ClassVar[time]
|
||||
max: ClassVar[time]
|
||||
resolution: ClassVar[timedelta]
|
||||
|
||||
if sys.version_info >= (3, 6):
|
||||
def __init__(
|
||||
self,
|
||||
hour: int = ...,
|
||||
minute: int = ...,
|
||||
second: int = ...,
|
||||
microsecond: int = ...,
|
||||
tzinfo: Optional[_tzinfo] = ...,
|
||||
*,
|
||||
fold: int = ...,
|
||||
) -> None: ...
|
||||
else:
|
||||
def __init__(
|
||||
self,
|
||||
hour: int = ...,
|
||||
minute: int = ...,
|
||||
second: int = ...,
|
||||
microsecond: int = ...,
|
||||
tzinfo: Optional[_tzinfo] = ...,
|
||||
) -> None: ...
|
||||
|
||||
@property
|
||||
def hour(self) -> int: ...
|
||||
@property
|
||||
def minute(self) -> int: ...
|
||||
@property
|
||||
def second(self) -> int: ...
|
||||
@property
|
||||
def microsecond(self) -> int: ...
|
||||
@property
|
||||
def tzinfo(self) -> Optional[_tzinfo]: ...
|
||||
if sys.version_info >= (3, 6):
|
||||
@property
|
||||
def fold(self) -> int: ...
|
||||
|
||||
def __le__(self, other: time) -> bool: ...
|
||||
def __lt__(self, other: time) -> bool: ...
|
||||
def __ge__(self, other: time) -> bool: ...
|
||||
def __gt__(self, other: time) -> bool: ...
|
||||
def __hash__(self) -> int: ...
|
||||
if sys.version_info >= (3, 6):
|
||||
def isoformat(self, timespec: str = ...) -> str: ...
|
||||
else:
|
||||
def isoformat(self) -> str: ...
|
||||
if sys.version_info >= (3, 7):
|
||||
@classmethod
|
||||
def fromisoformat(cls: Type[_S], time_string: str) -> _S: ...
|
||||
|
||||
def strftime(self, fmt: str) -> str: ...
|
||||
if sys.version_info >= (3,):
|
||||
def __format__(self, fmt: str) -> str: ...
|
||||
else:
|
||||
def __format__(self, fmt: AnyStr) -> AnyStr: ...
|
||||
|
||||
def utcoffset(self) -> Optional[timedelta]: ...
|
||||
def tzname(self) -> Optional[str]: ...
|
||||
def dst(self) -> Optional[timedelta]: ...
|
||||
if sys.version_info >= (3, 6):
|
||||
def replace(
|
||||
self,
|
||||
hour: int = ...,
|
||||
minute: int = ...,
|
||||
second: int = ...,
|
||||
microsecond: int = ...,
|
||||
tzinfo: Optional[_tzinfo] = ...,
|
||||
*,
|
||||
fold: int = ...,
|
||||
) -> time: ...
|
||||
else:
|
||||
def replace(
|
||||
self,
|
||||
hour: int = ...,
|
||||
minute: int = ...,
|
||||
second: int = ...,
|
||||
microsecond: int = ...,
|
||||
tzinfo: Optional[_tzinfo] = ...,
|
||||
) -> time: ...
|
||||
|
||||
_date = date
|
||||
_time = time
|
||||
|
||||
class timedelta(SupportsAbs["timedelta"]):
|
||||
min: ClassVar[timedelta]
|
||||
max: ClassVar[timedelta]
|
||||
resolution: ClassVar[timedelta]
|
||||
|
||||
if sys.version_info >= (3, 6):
|
||||
def __init__(
|
||||
self,
|
||||
days: float = ...,
|
||||
seconds: float = ...,
|
||||
microseconds: float = ...,
|
||||
milliseconds: float = ...,
|
||||
minutes: float = ...,
|
||||
hours: float = ...,
|
||||
weeks: float = ...,
|
||||
*,
|
||||
fold: int = ...,
|
||||
) -> None: ...
|
||||
else:
|
||||
def __init__(
|
||||
self,
|
||||
days: float = ...,
|
||||
seconds: float = ...,
|
||||
microseconds: float = ...,
|
||||
milliseconds: float = ...,
|
||||
minutes: float = ...,
|
||||
hours: float = ...,
|
||||
weeks: float = ...,
|
||||
) -> None: ...
|
||||
|
||||
@property
|
||||
def days(self) -> int: ...
|
||||
@property
|
||||
def seconds(self) -> int: ...
|
||||
@property
|
||||
def microseconds(self) -> int: ...
|
||||
def total_seconds(self) -> float: ...
|
||||
def __add__(self, other: timedelta) -> timedelta: ...
|
||||
def __radd__(self, other: timedelta) -> timedelta: ...
|
||||
def __sub__(self, other: timedelta) -> timedelta: ...
|
||||
def __rsub__(self, other: timedelta) -> timedelta: ...
|
||||
def __neg__(self) -> timedelta: ...
|
||||
def __pos__(self) -> timedelta: ...
|
||||
def __abs__(self) -> timedelta: ...
|
||||
def __mul__(self, other: float) -> timedelta: ...
|
||||
def __rmul__(self, other: float) -> timedelta: ...
|
||||
@overload
|
||||
def __floordiv__(self, other: timedelta) -> int: ...
|
||||
@overload
|
||||
def __floordiv__(self, other: int) -> timedelta: ...
|
||||
if sys.version_info >= (3,):
|
||||
@overload
|
||||
def __truediv__(self, other: timedelta) -> float: ...
|
||||
@overload
|
||||
def __truediv__(self, other: float) -> timedelta: ...
|
||||
def __mod__(self, other: timedelta) -> timedelta: ...
|
||||
def __divmod__(self, other: timedelta) -> Tuple[int, timedelta]: ...
|
||||
else:
|
||||
@overload
|
||||
def __div__(self, other: timedelta) -> float: ...
|
||||
@overload
|
||||
def __div__(self, other: float) -> timedelta: ...
|
||||
|
||||
def __le__(self, other: timedelta) -> bool: ...
|
||||
def __lt__(self, other: timedelta) -> bool: ...
|
||||
def __ge__(self, other: timedelta) -> bool: ...
|
||||
def __gt__(self, other: timedelta) -> bool: ...
|
||||
def __hash__(self) -> int: ...
|
||||
|
||||
class datetime(date):
|
||||
min: ClassVar[datetime]
|
||||
max: ClassVar[datetime]
|
||||
resolution: ClassVar[timedelta]
|
||||
|
||||
if sys.version_info >= (3, 6):
|
||||
def __new__(
|
||||
cls: Type[_S],
|
||||
year: int,
|
||||
month: int,
|
||||
day: int,
|
||||
hour: int = ...,
|
||||
minute: int = ...,
|
||||
second: int = ...,
|
||||
microsecond: int = ...,
|
||||
tzinfo: Optional[_tzinfo] = ...,
|
||||
*,
|
||||
fold: int = ...,
|
||||
) -> _S: ...
|
||||
else:
|
||||
def __new__(
|
||||
cls: Type[_S],
|
||||
year: int,
|
||||
month: int,
|
||||
day: int,
|
||||
hour: int = ...,
|
||||
minute: int = ...,
|
||||
second: int = ...,
|
||||
microsecond: int = ...,
|
||||
tzinfo: Optional[_tzinfo] = ...,
|
||||
) -> _S: ...
|
||||
|
||||
@property
|
||||
def year(self) -> int: ...
|
||||
@property
|
||||
def month(self) -> int: ...
|
||||
@property
|
||||
def day(self) -> int: ...
|
||||
@property
|
||||
def hour(self) -> int: ...
|
||||
@property
|
||||
def minute(self) -> int: ...
|
||||
@property
|
||||
def second(self) -> int: ...
|
||||
@property
|
||||
def microsecond(self) -> int: ...
|
||||
@property
|
||||
def tzinfo(self) -> Optional[_tzinfo]: ...
|
||||
if sys.version_info >= (3, 6):
|
||||
@property
|
||||
def fold(self) -> int: ...
|
||||
|
||||
@classmethod
|
||||
def fromtimestamp(cls: Type[_S], t: float, tz: Optional[_tzinfo] = ...) -> _S: ...
|
||||
@classmethod
|
||||
def utcfromtimestamp(cls: Type[_S], t: float) -> _S: ...
|
||||
@classmethod
|
||||
def today(cls: Type[_S]) -> _S: ...
|
||||
@classmethod
|
||||
def fromordinal(cls: Type[_S], n: int) -> _S: ...
|
||||
if sys.version_info >= (3, 8):
|
||||
@classmethod
|
||||
def now(cls: Type[_S], tz: Optional[_tzinfo] = ...) -> _S: ...
|
||||
else:
|
||||
@overload
|
||||
@classmethod
|
||||
def now(cls: Type[_S], tz: None = ...) -> _S: ...
|
||||
@overload
|
||||
@classmethod
|
||||
def now(cls, tz: _tzinfo) -> datetime: ...
|
||||
|
||||
@classmethod
|
||||
def utcnow(cls: Type[_S]) -> _S: ...
|
||||
if sys.version_info >= (3, 6):
|
||||
@classmethod
|
||||
def combine(cls, date: _date, time: _time, tzinfo: Optional[_tzinfo] = ...) -> datetime: ...
|
||||
else:
|
||||
@classmethod
|
||||
def combine(cls, date: _date, time: _time) -> datetime: ...
|
||||
if sys.version_info >= (3, 7):
|
||||
@classmethod
|
||||
def fromisoformat(cls: Type[_S], date_string: str) -> _S: ...
|
||||
|
||||
def strftime(self, fmt: str) -> str: ...
|
||||
if sys.version_info >= (3,):
|
||||
def __format__(self, fmt: str) -> str: ...
|
||||
else:
|
||||
def __format__(self, fmt: AnyStr) -> AnyStr: ...
|
||||
|
||||
def toordinal(self) -> int: ...
|
||||
def timetuple(self) -> struct_time: ...
|
||||
if sys.version_info >= (3, 3):
|
||||
def timestamp(self) -> float: ...
|
||||
|
||||
def utctimetuple(self) -> struct_time: ...
|
||||
def date(self) -> _date: ...
|
||||
def time(self) -> _time: ...
|
||||
def timetz(self) -> _time: ...
|
||||
if sys.version_info >= (3, 6):
|
||||
def replace(
|
||||
self,
|
||||
year: int = ...,
|
||||
month: int = ...,
|
||||
day: int = ...,
|
||||
hour: int = ...,
|
||||
minute: int = ...,
|
||||
second: int = ...,
|
||||
microsecond: int = ...,
|
||||
tzinfo: Optional[_tzinfo] = ...,
|
||||
*,
|
||||
fold: int = ...,
|
||||
) -> datetime: ...
|
||||
else:
|
||||
def replace(
|
||||
self,
|
||||
year: int = ...,
|
||||
month: int = ...,
|
||||
day: int = ...,
|
||||
hour: int = ...,
|
||||
minute: int = ...,
|
||||
second: int = ...,
|
||||
microsecond: int = ...,
|
||||
tzinfo: Optional[_tzinfo] = ...,
|
||||
) -> datetime: ...
|
||||
if sys.version_info >= (3, 8):
|
||||
def astimezone(self: _S, tz: Optional[_tzinfo] = ...) -> _S: ...
|
||||
elif sys.version_info >= (3, 3):
|
||||
def astimezone(self, tz: Optional[_tzinfo] = ...) -> datetime: ...
|
||||
else:
|
||||
def astimezone(self, tz: _tzinfo) -> datetime: ...
|
||||
|
||||
def ctime(self) -> str: ...
|
||||
if sys.version_info >= (3, 6):
|
||||
def isoformat(self, sep: str = ..., timespec: str = ...) -> str: ...
|
||||
else:
|
||||
def isoformat(self, sep: str = ...) -> str: ...
|
||||
|
||||
@classmethod
|
||||
def strptime(cls, date_string: str, format: str) -> datetime: ...
|
||||
def utcoffset(self) -> Optional[timedelta]: ...
|
||||
def tzname(self) -> Optional[str]: ...
|
||||
def dst(self) -> Optional[timedelta]: ...
|
||||
def __le__(self, other: datetime) -> bool: ... # type: ignore
|
||||
def __lt__(self, other: datetime) -> bool: ... # type: ignore
|
||||
def __ge__(self, other: datetime) -> bool: ... # type: ignore
|
||||
def __gt__(self, other: datetime) -> bool: ... # type: ignore
|
||||
if sys.version_info >= (3, 8):
|
||||
def __add__(self: _S, other: timedelta) -> _S: ...
|
||||
def __radd__(self: _S, other: timedelta) -> _S: ...
|
||||
else:
|
||||
def __add__(self, other: timedelta) -> datetime: ...
|
||||
def __radd__(self, other: timedelta) -> datetime: ...
|
||||
|
||||
@overload # type: ignore
|
||||
def __sub__(self, other: datetime) -> timedelta: ...
|
||||
@overload
|
||||
def __sub__(self, other: timedelta) -> datetime: ...
|
||||
def __hash__(self) -> int: ...
|
||||
def weekday(self) -> int: ...
|
||||
def isoweekday(self) -> int: ...
|
||||
def isocalendar(self) -> _IsoCalendarDate: ...
|
||||
|
|
@ -56,6 +56,7 @@ version = release = final_version
|
|||
# ones.
|
||||
extensions = [
|
||||
"sphinx.ext.autodoc",
|
||||
"sphinx_mdinclude",
|
||||
]
|
||||
|
||||
# Add any paths that contain templates here, relative to this directory.
|
||||
|
|
@ -82,6 +83,10 @@ html_static_path = ["_static"]
|
|||
autodoc_typehints = "description"
|
||||
autodoc_class_signature = "separated"
|
||||
|
||||
default_role = "any"
|
||||
|
||||
intersphinx_mapping = {'py': ('https://docs.python.org/3', None)}
|
||||
|
||||
# SPDX-FileCopyrightText: 2021-2024 Jeff Epler
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
|
|
|
|||
|
|
@ -2,17 +2,10 @@
|
|||
..
|
||||
.. SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
wwvbpy
|
||||
======
|
||||
|
||||
.. image:: https://github.com/jepler/wwvbpy/actions/workflows/test.yml/badge.svg
|
||||
:target: https://github.com/jepler/wwvbpy/actions/workflows/test.yml
|
||||
:alt: Test wwvbpy
|
||||
|
||||
.. image:: https://img.shields.io/pypi/v/wwvb
|
||||
:target: https://pypi.org/project/wwvb
|
||||
:alt: PyPI
|
||||
wwvbpy |version|
|
||||
================
|
||||
|
||||
.. mdinclude:: ../README.md
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ dependencies = {file = "requirements.txt"}
|
|||
write_to = "src/wwvb/__version__.py"
|
||||
[tool.ruff.lint]
|
||||
select = ["E", "F", "D", "I", "N", "UP", "YTT", "BLE", "B", "FBT", "A", "COM", "C4", "DTZ", "FA", "ISC", "ICN", "PIE", "PYI", "Q", "RET", "SIM", "TID", "TCH", "ARG", "PTH", "C", "R", "W", "FLY", "RUF", "PL"]
|
||||
ignore = ["D203", "D213", "D400", "D415", "ISC001", "E741", "C901", "PLR0911", "PLR2004", "PLR0913"]
|
||||
ignore = ["D203", "D213", "D400", "D415", "ISC001", "E741", "C901", "PLR0911", "PLR2004", "PLR0913", "COM812"]
|
||||
[tool.ruff]
|
||||
line-length = 120
|
||||
[project]
|
||||
|
|
@ -48,3 +48,6 @@ dut1table = "wwvb.dut1table:main"
|
|||
updateiers = "wwvb.updateiers:main"
|
||||
[project.gui-scripts]
|
||||
wwvbtk = "wwvb.wwvbtk:main"
|
||||
[[tool.mypy.overrides]]
|
||||
module = ["adafruit_datetime"]
|
||||
follow_untyped_imports = true
|
||||
|
|
|
|||
|
|
@ -14,9 +14,10 @@ pre-commit
|
|||
python-dateutil
|
||||
requests; implementation_name=="cpython"
|
||||
setuptools>=68; implementation_name=="cpython"
|
||||
sphinx>=7,<8
|
||||
sphinx
|
||||
sphinx-autodoc-typehints
|
||||
sphinx-rtd-theme
|
||||
sphinx-mdinclude
|
||||
twine; implementation_name=="cpython"
|
||||
types-beautifulsoup4; implementation_name=="cpython"
|
||||
types-python-dateutil; implementation_name=="cpython"
|
||||
|
|
|
|||
|
|
@ -4,7 +4,10 @@
|
|||
|
||||
# ruff: noqa: C405 PYI024 PLR2004 FBT001 FBT002
|
||||
|
||||
"""Implementation of a WWVB state machine & decoder for resource-constrained systems"""
|
||||
"""Implementation of a WWVB state machine & decoder for resource-constrained systems
|
||||
|
||||
This version is intended for use with MicroPython & CircuitPython.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,13 @@
|
|||
#!/usr/bin/python3
|
||||
"""A library for WWVB timecodes"""
|
||||
"""A package and CLI for WWVB timecodes
|
||||
|
||||
This is the full featured library suitable for use on 'real computers'.
|
||||
For a reduced version suitable for use on MicroPython & CircuitPython,
|
||||
see `uwwvb`.
|
||||
|
||||
This package also includes the commandline programs listed above,
|
||||
perhaps most importantly ``wwvbgen`` for generating WWVB timecodes.
|
||||
"""
|
||||
|
||||
# SPDX-FileCopyrightText: 2011-2024 Jeff Epler
|
||||
#
|
||||
|
|
@ -24,12 +32,6 @@ SECOND = datetime.timedelta(seconds=1)
|
|||
T = TypeVar("T")
|
||||
|
||||
|
||||
def _require(x: T | None) -> T:
|
||||
"""Check an Optional item is not None."""
|
||||
assert x is not None
|
||||
return x
|
||||
|
||||
|
||||
def _removeprefix(s: str, p: str) -> str:
|
||||
if s.startswith(p):
|
||||
return s[len(p) :]
|
||||
|
|
@ -323,11 +325,22 @@ _dst_ls_lut = [
|
|||
]
|
||||
|
||||
|
||||
class _WWVBMinute(NamedTuple):
|
||||
"""Uniquely identifies a minute of time in the WWVB system.
|
||||
@enum.unique
|
||||
class DstStatus(enum.IntEnum):
|
||||
"""Constants that describe the DST status of a minute"""
|
||||
|
||||
To use ut1 and ls information from IERS, create a WWVBMinuteIERS value instead.
|
||||
"""
|
||||
DST_NOT_IN_EFFECT = 0b00
|
||||
"""DST not in effect today"""
|
||||
DST_STARTS_TODAY = 0b01
|
||||
"""DST starts today at 0200 local standard time"""
|
||||
DST_ENDS_TODAY = 0b10
|
||||
"""DST ends today at 0200 local standard time"""
|
||||
DST_IN_EFFECT = 0b11
|
||||
"""DST in effect all day today"""
|
||||
|
||||
|
||||
class _WWVBMinute(NamedTuple):
|
||||
"""(implementation detail)"""
|
||||
|
||||
year: int
|
||||
"""2-digit year within the WWVB epoch"""
|
||||
|
|
@ -341,7 +354,7 @@ class _WWVBMinute(NamedTuple):
|
|||
min: int
|
||||
"""Minute of hour"""
|
||||
|
||||
dst: int
|
||||
dst: DstStatus
|
||||
"""2-bit DST code """
|
||||
|
||||
ut1: int
|
||||
|
|
@ -357,7 +370,8 @@ class _WWVBMinute(NamedTuple):
|
|||
class WWVBMinute(_WWVBMinute):
|
||||
"""Uniquely identifies a minute of time in the WWVB system.
|
||||
|
||||
To use ut1 and ls information from IERS, create a WWVBMinuteIERS value instead.
|
||||
To use ``ut1`` and ``ls`` information from IERS, create a `WWVBMinuteIERS`
|
||||
object instead.
|
||||
"""
|
||||
|
||||
epoch: int = 1970
|
||||
|
|
@ -368,16 +382,25 @@ class WWVBMinute(_WWVBMinute):
|
|||
days: int,
|
||||
hour: int,
|
||||
minute: int,
|
||||
dst: int | None = None,
|
||||
dst: DstStatus | int | None = None,
|
||||
ut1: int | None = None,
|
||||
ls: bool | None = None,
|
||||
ly: bool | None = None,
|
||||
) -> WWVBMinute:
|
||||
"""Construct a WWVBMinute"""
|
||||
if dst is None:
|
||||
dst = cls.get_dst(year, days)
|
||||
if dst not in (0, 1, 2, 3):
|
||||
raise ValueError("dst value should be 0..3")
|
||||
"""Construct a WWVBMinute
|
||||
|
||||
:param year: The 2- or 4-digit year. This parameter is converted by the `full_year` method.
|
||||
:param days: 1-based day of year
|
||||
|
||||
:param hour: UTC hour of day
|
||||
|
||||
:param minute: Minute of hour
|
||||
:param dst: 2-bit DST code
|
||||
:param ut1: UT1 offset in units of 100ms, range -900 to +900ms
|
||||
:param ls: Leap second warning flag
|
||||
:param ly: Leap year flag
|
||||
"""
|
||||
dst = cls.get_dst(year, days) if dst is None else DstStatus(dst)
|
||||
if ut1 is None and ls is None:
|
||||
ut1, ls = cls._get_dut1_info(year, days)
|
||||
elif ut1 is None or ls is None:
|
||||
|
|
@ -407,13 +430,13 @@ class WWVBMinute(_WWVBMinute):
|
|||
return year
|
||||
|
||||
@staticmethod
|
||||
def get_dst(year: int, days: int) -> int:
|
||||
def get_dst(year: int, days: int) -> DstStatus:
|
||||
"""Get the 2-bit WWVB DST value for the given day"""
|
||||
d0 = datetime.datetime(year, 1, 1, tzinfo=datetime.timezone.utc) + datetime.timedelta(days - 1)
|
||||
d1 = d0 + datetime.timedelta(1)
|
||||
dst0 = isdst(d0)
|
||||
dst1 = isdst(d1)
|
||||
return dst1 * 2 + dst0
|
||||
return DstStatus(dst1 * 2 + dst0)
|
||||
|
||||
def __str__(self) -> str:
|
||||
"""Implement str()"""
|
||||
|
|
@ -424,7 +447,10 @@ class WWVBMinute(_WWVBMinute):
|
|||
)
|
||||
|
||||
def as_datetime_utc(self) -> datetime.datetime:
|
||||
"""Convert to a UTC datetime"""
|
||||
"""Convert to a UTC datetime
|
||||
|
||||
The returned object has ``tzinfo=datetime.timezone.utc``.
|
||||
"""
|
||||
d = datetime.datetime(self.year, 1, 1, tzinfo=datetime.timezone.utc)
|
||||
d += datetime.timedelta(self.days - 1, self.hour * 3600 + self.min * 60)
|
||||
return d
|
||||
|
|
@ -437,7 +463,18 @@ class WWVBMinute(_WWVBMinute):
|
|||
*,
|
||||
dst_observed: bool = True,
|
||||
) -> datetime.datetime:
|
||||
"""Convert to a local datetime according to the DST bits"""
|
||||
"""Convert to a local datetime according to the DST bits
|
||||
|
||||
The returned object has ``tz=datetime.timezone(computed_offset)``.
|
||||
|
||||
:param standard_time_offset: The UTC offset of local standard time, in seconds west of UTC.
|
||||
The default value, ``7 * 3600``, is for Colorado, the source of the WWVB broadcast.
|
||||
|
||||
:param dst_observed: If ``True`` then the locale observes DST, and a
|
||||
one hour offset is applied according to WWVB rules. If ``False``, then
|
||||
the standard time offset is used at all times.
|
||||
|
||||
"""
|
||||
u = self.as_datetime_utc()
|
||||
offset = datetime.timedelta(seconds=-standard_time_offset)
|
||||
d = u - datetime.timedelta(seconds=standard_time_offset)
|
||||
|
|
@ -682,7 +719,7 @@ class WWVBMinute(_WWVBMinute):
|
|||
return cls(u.tm_year, u.tm_yday, u.tm_hour, u.tm_min, ut1=newut1, ls=newls)
|
||||
|
||||
@classmethod
|
||||
def from_timecode_am(cls, t: WWVBTimecode) -> WWVBMinute | None:
|
||||
def from_timecode_am(cls, t: WWVBTimecode) -> WWVBMinute | None: # noqa: PLR0912
|
||||
"""Construct a WWVBMinute from a WWVBTimecode"""
|
||||
for i in (0, 9, 19, 29, 39, 49, 59):
|
||||
if t.am[i] != AmplitudeModulation.MARK:
|
||||
|
|
@ -697,9 +734,13 @@ class WWVBMinute(_WWVBMinute):
|
|||
minute = t._get_am_bcd(1, 2, 3, 5, 6, 7, 8)
|
||||
if minute is None:
|
||||
return None
|
||||
if minute >= 60:
|
||||
return None
|
||||
hour = t._get_am_bcd(12, 13, 15, 16, 17, 18)
|
||||
if hour is None:
|
||||
return None
|
||||
if hour >= 24:
|
||||
return None
|
||||
days = t._get_am_bcd(22, 23, 25, 26, 27, 28, 30, 31, 32, 33)
|
||||
if days is None:
|
||||
return None
|
||||
|
|
@ -716,7 +757,9 @@ class WWVBMinute(_WWVBMinute):
|
|||
if days > 366 or (not ly and days > 365):
|
||||
return None
|
||||
ls = bool(t.am[56])
|
||||
dst = _require(t._get_am_bcd(57, 58))
|
||||
dst = t._get_am_bcd(57, 58)
|
||||
if dst is None:
|
||||
return None
|
||||
return cls(year, days, hour, minute, dst, ut1, ls, ly)
|
||||
|
||||
|
||||
|
|
@ -729,7 +772,7 @@ class WWVBMinuteIERS(WWVBMinute):
|
|||
return round(get_dut1(d) * 10) * 100, isls(d)
|
||||
|
||||
|
||||
def _bcd_bits(n: int) -> Generator[bool, None, None]:
|
||||
def _bcd_bits(n: int) -> Generator[bool]:
|
||||
"""Return the bcd representation of n, starting with the least significant bit"""
|
||||
while True:
|
||||
d = n % 10
|
||||
|
|
@ -743,9 +786,13 @@ class AmplitudeModulation(enum.IntEnum):
|
|||
"""Constants that describe an Amplitude Modulation value"""
|
||||
|
||||
ZERO = 0
|
||||
"""A zero bit (reduced carrier during the first 200ms of the second)"""
|
||||
ONE = 1
|
||||
"""A one bit (reduced carrier during the first 500ms of the second)"""
|
||||
MARK = 2
|
||||
"""A mark bit (reduced carrier during the first 800ms of the second)"""
|
||||
UNSET = -1
|
||||
"""An unset or unknown amplitude modulation value"""
|
||||
|
||||
|
||||
@enum.unique
|
||||
|
|
@ -753,8 +800,11 @@ class PhaseModulation(enum.IntEnum):
|
|||
"""Constants that describe a Phase Modulation value"""
|
||||
|
||||
ZERO = 0
|
||||
"""A one bit (180° phase shift during the second)"""
|
||||
ONE = 1
|
||||
"""A zero bit (No phase shift during the second)"""
|
||||
UNSET = -1
|
||||
"""An unset or unknown phase modulation value"""
|
||||
|
||||
|
||||
class WWVBTimecode:
|
||||
|
|
@ -777,7 +827,10 @@ class WWVBTimecode:
|
|||
The the bits ``self.am[poslist[i]]`` in MSB order are converted from
|
||||
BCD to integer
|
||||
"""
|
||||
pos = reversed(poslist)
|
||||
pos = list(poslist)[::-1]
|
||||
for p in pos:
|
||||
if self.am[p] not in {AmplitudeModulation.ZERO, AmplitudeModulation.ONE}:
|
||||
return None
|
||||
val = [bool(self.am[p]) for p in pos]
|
||||
result = 0
|
||||
base = 1
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
{"START": "1972-01-01", "OFFSETS_GZ": "H4sIADstxGcC/+2aa3LDMAiEL5uHLTuxnN5/pn/aTmfSSiAWhGy+E2SWZQE58zwiH/1YivB/96vMXiIX2Io8CTyIrDSWGqlMRdrpDa6aJFnr0m4wYZkCE2UmSF0V+13vBveStK6JTfQyW3O86HLJf0RvDgy5u4FCI+WVKTsVoUdHzsrRoWRfYHIItZ5EEgu0Beu58EgEpMpO9zf4/s3iNO4y7/hqEwOZIPu3+PuO2T7Ic5E8GxsnZHvUYOtELxW1WP+0yx/caFxpyAooq6lq06UEr+UkLeXOIDPZ6EBrqb5K8Tvu6/B9CdnZqFQL05s2KauWy/IeF/tJGAisjK9MgGyDuUkRq4G1gRE+VjA30uZNPsdantkgMq58QO4fw+sqzj+A2/16mmvnyy9UzDvMktDgKYlnkFeB2rx+wNANG40aA4OgsY03AWoDCVs/XMmkyQ0+0jWaUqPdwA0m/MRuccGjCwirHToWzbcs8P7U1nZZLSYdHapWu5HqVg1YjK2fPEwvPZPzLPUF848tyid2u7dh8B7h+wVQ923Q+kqxZe3JclSSB+YTM3nnHrjgFth/vzgZzw6cbOMYa4bHFPU/DR3mp/ubKM4cgwMnHZW4GFxFprOVcevAKGva6oExn1MOmyGDJQPm0rpU8bjqdOo993O6Xz9ofToZela5vwrWoTn4l4o5CIIaKejCEgSnJv784VsvF3wCeP33WU5NAAA="}
|
||||
{"START": "1972-01-01", "OFFSETS_GZ": "H4sIAJF3PWgC/+2aa3LDMAiEL5uHLDuxnN5/pn/aTmfSSiAWhGR9J8gsywJylqVHPtqxZuH/7leeI0fKsGd5EngQ2WisJWKegrThDa6aJFnL0u4wYZkCE2UmSF0U+13vCveStC6JTfQyW3O86HLJf0SvDgy5u4FCI+WVKRuy0KMjJeXoULIvMDmEWgeRxAJtwXquPCIBqbLh/gbfv0mcxk3mHV9tYiATZP8W/zgw2wd5LpJnY+WErI8abJ3opaIW6592+YMbjSsNWQFlNVVtuhjhtQzSUh4MEpOdDrSW6qsUv+O+Dt+XkIONSrUwvWmTsmq5LO9xsZ+EgcDK+MIESDaYmxSxGlgbGOFjBXMjbV7lc6zlmQ0i48oH5P4+vK7i/AHc7tfTXDtffqFi3m6WhApPSTyDvArU5vUDhm7YaNQYGASVbbwLUBtI2PrhSiZNbvCRrtGUGu0GbjDhJ3aLCx5dQFjt0LFovmWB96e6tktqMenoULXajVS3asBibP3kYXrpmZxnsS2Yf2xRPrHbvQ2D9wjfL4C6b4PWV4otW0vWUYkeWE5M8M594oLbxP77xcl4NuBkG0dfM3xOUf/T0GF+ur+J5pljcODEUZkXg6vIdLYy7g3oZU3bPNDnc8qwGdJZMmAurUsRj6tOo95zP6fb9YPWp5OuZ5X7q2DrmsG/VCyTyaREnDRhnUxOzfzzh3/NRuYTMxwhU6lNAAA="}
|
||||
|
|
@ -6,9 +6,8 @@
|
|||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
from __future__ import annotations
|
||||
|
||||
import datetime
|
||||
import functools
|
||||
import threading
|
||||
import time
|
||||
from tkinter import Canvas, TclError, Tk
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
|
|
@ -31,7 +30,7 @@ def validate_colors(ctx: Any, param: Any, value: str) -> list[str]: # noqa: ARG
|
|||
app = _app()
|
||||
colors = value.split()
|
||||
if len(colors) not in (2, 3, 4, 6):
|
||||
raise click.BadParameter(f"Give 2, 3, 4 or 6 colors (not {len(colors)}")
|
||||
raise click.BadParameter(f"Give 2, 3, 4 or 6 colors (not {len(colors)})")
|
||||
for c in colors:
|
||||
try:
|
||||
app.winfo_rgb(c)
|
||||
|
|
@ -53,33 +52,36 @@ DEFAULT_COLORS = "#3c3c3c #3c3c3c #3c3c3c #cc3c3c #88883c #3ccc3c"
|
|||
|
||||
|
||||
@click.command
|
||||
@click.option("--colors", callback=validate_colors, default=DEFAULT_COLORS)
|
||||
@click.option("--size", default=48)
|
||||
@click.option("--min-size", default=None)
|
||||
@click.option(
|
||||
"--colors",
|
||||
callback=validate_colors,
|
||||
default=DEFAULT_COLORS,
|
||||
metavar="COLORS",
|
||||
help="2, 3, 4, or 6 Tk color values",
|
||||
)
|
||||
@click.option("--size", default=48, help="initial size in pixels")
|
||||
@click.option("--min-size", default=None, type=int, help="minimum size in pixels (default: same as initial size)")
|
||||
def main(colors: list[str], size: int, min_size: int | None) -> None: # noqa: PLR0915
|
||||
"""Visualize the WWVB signal in realtime"""
|
||||
if min_size is None:
|
||||
min_size = size
|
||||
|
||||
def sleep_deadline(deadline: float) -> None:
|
||||
"""Sleep until a deadline"""
|
||||
now = time.time()
|
||||
if deadline > now:
|
||||
time.sleep(deadline - now)
|
||||
def deadline_ms(deadline: datetime.datetime) -> int:
|
||||
"""Compute the number of ms until a deadline"""
|
||||
now = datetime.datetime.now(datetime.timezone.utc)
|
||||
return int(max(0, (deadline - now).total_seconds()) * 1000)
|
||||
|
||||
def wwvbtick() -> Generator[tuple[float, wwvb.AmplitudeModulation], None, None]:
|
||||
def wwvbtick() -> Generator[tuple[datetime.datetime, wwvb.AmplitudeModulation]]:
|
||||
"""Yield consecutive values of the WWVB amplitude signal, going from minute to minute"""
|
||||
timestamp = time.time() // 60 * 60
|
||||
timestamp = datetime.datetime.now(datetime.timezone.utc).replace(second=0, microsecond=0)
|
||||
|
||||
while True:
|
||||
tt = time.gmtime(timestamp)
|
||||
key = tt.tm_year, tt.tm_yday, tt.tm_hour, tt.tm_min
|
||||
timecode = wwvb.WWVBMinuteIERS(*key).as_timecode()
|
||||
timecode = wwvb.WWVBMinuteIERS.from_datetime(timestamp).as_timecode()
|
||||
for i, code in enumerate(timecode.am):
|
||||
yield timestamp + i, code
|
||||
timestamp = timestamp + 60
|
||||
yield timestamp + datetime.timedelta(seconds=i), code
|
||||
timestamp = timestamp + datetime.timedelta(seconds=60)
|
||||
|
||||
def wwvbsmarttick() -> Generator[tuple[float, wwvb.AmplitudeModulation], None, None]:
|
||||
def wwvbsmarttick() -> Generator[tuple[datetime.datetime, wwvb.AmplitudeModulation]]:
|
||||
"""Yield consecutive values of the WWVB amplitude signal
|
||||
|
||||
.. but deal with time progressing unexpectedly, such as when the
|
||||
|
|
@ -90,10 +92,10 @@ def main(colors: list[str], size: int, min_size: int | None) -> None: # noqa: P
|
|||
"""
|
||||
while True:
|
||||
for stamp, code in wwvbtick():
|
||||
now = time.time()
|
||||
if stamp < now - 60:
|
||||
now = datetime.datetime.now(datetime.timezone.utc)
|
||||
if stamp < now - datetime.timedelta(seconds=60):
|
||||
break
|
||||
if stamp < now - 1:
|
||||
if stamp < now - datetime.timedelta(seconds=1):
|
||||
continue
|
||||
yield stamp, code
|
||||
|
||||
|
|
@ -127,18 +129,23 @@ def main(colors: list[str], size: int, min_size: int | None) -> None: # noqa: P
|
|||
"""Turn the canvas's virtual LED off"""
|
||||
canvas.itemconfigure(circle, fill=colors[i])
|
||||
|
||||
def thread_func() -> None:
|
||||
"""Update the canvas virtual LED"""
|
||||
def controller_func() -> Generator[int]:
|
||||
"""Update the canvas virtual LED, yielding the number of ms until the next change"""
|
||||
for stamp, code in wwvbsmarttick():
|
||||
sleep_deadline(stamp)
|
||||
yield deadline_ms(stamp)
|
||||
led_on(code)
|
||||
app.update()
|
||||
sleep_deadline(stamp + 0.2 + 0.3 * int(code))
|
||||
yield deadline_ms(stamp + datetime.timedelta(seconds=0.2 + 0.3 * int(code)))
|
||||
led_off(code)
|
||||
app.update()
|
||||
|
||||
thread = threading.Thread(target=thread_func, daemon=True)
|
||||
thread.start()
|
||||
controller = controller_func().__next__
|
||||
|
||||
def after_func() -> None:
|
||||
"""Repeatedly run the controller after the desired interval"""
|
||||
app.after(controller(), after_func)
|
||||
|
||||
app.after_idle(after_func)
|
||||
app.mainloop()
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -395,6 +395,38 @@ class WWVBRoundtrip(unittest.TestCase):
|
|||
self.assertEqual(WWVBMinute2k(2070, 1, 1, 0, 0).year, 2070)
|
||||
self.assertEqual(WWVBMinute2k(2099, 1, 1, 0, 0).year, 2099)
|
||||
|
||||
def test_invalid_minute(self) -> None:
|
||||
"""Check that minute 61 is not valid in an AM timecode"""
|
||||
base_minute = wwvb.WWVBMinute(2021, 1, 1, 0, 0)
|
||||
minute = base_minute.as_timecode()
|
||||
minute._put_am_bcd(61, 1, 2, 3, 5, 6, 7, 8) # valid BCD, invalid minute
|
||||
decoded_minute = wwvb.WWVBMinute.from_timecode_am(minute)
|
||||
assert decoded_minute is None
|
||||
|
||||
def test_invalid_hour(self) -> None:
|
||||
"""Check that hour 25 is not valid in an AM timecode"""
|
||||
base_minute = wwvb.WWVBMinute(2021, 1, 1, 0, 0)
|
||||
minute = base_minute.as_timecode()
|
||||
minute._put_am_bcd(29, 12, 13, 15, 16, 17, 18) # valid BCD, invalid hour
|
||||
decoded_minute = wwvb.WWVBMinute.from_timecode_am(minute)
|
||||
assert decoded_minute is None
|
||||
|
||||
def test_invalid_bcd_day(self) -> None:
|
||||
"""Check that invalid BCD is detected in AM timecode"""
|
||||
base_minute = wwvb.WWVBMinute(2021, 1, 1, 0, 0)
|
||||
minute = base_minute.as_timecode()
|
||||
minute.am[30:34] = [wwvb.AmplitudeModulation.ONE] * 4 # invalid BCD 0xf
|
||||
decoded_minute = wwvb.WWVBMinute.from_timecode_am(minute)
|
||||
assert decoded_minute is None
|
||||
|
||||
def test_invalid_mark(self) -> None:
|
||||
"""Check that invalid presence of MARK in a data field is detected"""
|
||||
base_minute = wwvb.WWVBMinute(2021, 1, 1, 0, 0)
|
||||
minute = base_minute.as_timecode()
|
||||
minute.am[57] = wwvb.AmplitudeModulation.MARK
|
||||
decoded_minute = wwvb.WWVBMinute.from_timecode_am(minute)
|
||||
assert decoded_minute is None
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
|||
Loading…
Reference in a new issue