├── .coveragerc ├── .github └── workflows │ ├── cron.yml │ ├── release.yml │ └── test.yml ├── .gitignore ├── .pre-commit-config.yaml ├── .readthedocs.yaml ├── LICENSES ├── CC0-1.0.txt ├── GPL-3.0-only.txt └── Unlicense.txt ├── Makefile ├── README.md ├── codecov.yml ├── doc ├── _static │ └── .empty ├── conf.py └── index.rst ├── pyproject.toml ├── requirements-dev.txt ├── requirements.txt ├── src ├── uwwvb.py └── wwvb │ ├── __init__.py │ ├── decode.py │ ├── dut1table.py │ ├── gen.py │ ├── iersdata.json │ ├── iersdata.json.license │ ├── iersdata.py │ ├── py.typed │ ├── tz.py │ ├── updateiers.py │ └── wwvbtk.py └── test ├── testcli.py ├── testdaylight.py ├── testls.py ├── testpm.py ├── testuwwvb.py ├── testwwvb.py └── wwvbgen_testcases ├── 1998leapsecond ├── 2012leapsecond ├── all-headers ├── bar ├── both ├── cradek ├── duration ├── enddst-phase ├── enddst-phase-2 ├── endleapyear ├── leapday1 ├── leapday28 ├── leapday29 ├── negleapsecond ├── nextdst ├── nextst ├── nonleapday1 ├── nonleapday28 ├── phase ├── startdst ├── startdst-phase ├── startdst-phase-2 ├── startleapyear ├── startst ├── y2k ├── y2k-1 ├── y2k1 └── y2k1-1 /.coveragerc: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021-2024 Jeff Epler 2 | # 3 | # SPDX-License-Identifier: GPL-3.0-only 4 | [report] 5 | exclude_also = 6 | def __repr__ 7 | if self.debug: 8 | if settings.DEBUG 9 | raise AssertionError 10 | raise NotImplementedError 11 | if 0: 12 | if __name__ == .__main__.: 13 | if TYPE_CHECKING: 14 | class .*\bProtocol\): 15 | @(abc\.)?abstractmethod 16 | -------------------------------------------------------------------------------- /.github/workflows/cron.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021-2024 Jeff Epler 2 | # 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | name: Update DUT1 data 6 | 7 | on: 8 | schedule: 9 | - cron: '0 10 2 * *' 10 | workflow_dispatch: 11 | 12 | jobs: 13 | update-dut1: 14 | runs-on: ubuntu-24.04 15 | if: startswith(github.repository, 'jepler/') 16 | steps: 17 | 18 | - name: Dump GitHub context 19 | env: 20 | GITHUB_CONTEXT: ${{ toJson(github) }} 21 | run: echo "$GITHUB_CONTEXT" 22 | 23 | - uses: actions/checkout@v4 24 | with: 25 | persist-credentials: false 26 | 27 | - name: Set up Python 3.10 28 | uses: actions/setup-python@v5 29 | with: 30 | python-version: "3.10" 31 | 32 | - name: Install dependencies 33 | run: pip install -e . 34 | 35 | - name: Update DUT1 data 36 | run: python -m wwvb.updateiers --dist 37 | 38 | - name: Test 39 | run: python -munittest 40 | 41 | - name: Commit updates 42 | env: 43 | REPO: ${{ github.repository }} 44 | run: | 45 | git config user.name "${GITHUB_ACTOR} (github actions cron)" 46 | git config user.email "${GITHUB_ACTOR}@users.noreply.github.com" 47 | git remote set-url --push origin "https://${GITHUB_ACTOR}:${{ secrets.GITHUB_TOKEN }}@github.com/$REPO" 48 | if git commit -m"update iersdata" src/wwvb/iersdata.json; then git push origin HEAD:main; fi 49 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021-2024 Jeff Epler 2 | # 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | name: Release wwvbgen 6 | 7 | on: 8 | release: 9 | types: [published] 10 | 11 | jobs: 12 | release: 13 | 14 | runs-on: ubuntu-24.04 15 | steps: 16 | - name: Dump GitHub context 17 | env: 18 | GITHUB_CONTEXT: ${{ toJson(github) }} 19 | run: echo "$GITHUB_CONTEXT" 20 | 21 | - uses: actions/checkout@v4 22 | with: 23 | persist-credentials: false 24 | 25 | - name: Set up Python 26 | uses: actions/setup-python@v5 27 | with: 28 | python-version: 3.9 29 | 30 | - name: Install deps 31 | run: | 32 | python -mpip install wheel 33 | python -mpip install -r requirements-dev.txt 34 | 35 | - name: Test 36 | run: make coverage 37 | 38 | - name: Build release 39 | run: python -mbuild 40 | 41 | - name: Upload release 42 | run: twine upload -u "$TWINE_USERNAME" -p "$TWINE_PASSWORD" dist/* 43 | env: 44 | TWINE_USERNAME: __token__ 45 | TWINE_PASSWORD: ${{ secrets.pypi_token }} 46 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021-2024 Jeff Epler 2 | # 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | name: Test wwvbgen 6 | 7 | on: 8 | push: 9 | pull_request: 10 | release: 11 | types: [published] 12 | check_suite: 13 | types: [rerequested] 14 | 15 | jobs: 16 | docs: 17 | runs-on: ubuntu-latest 18 | steps: 19 | - name: Set up Python 20 | uses: actions/setup-python@v5 21 | with: 22 | python-version: '3.12' 23 | 24 | - uses: actions/checkout@v4 25 | with: 26 | persist-credentials: false 27 | 28 | - name: Install deps 29 | run: python -mpip install -r requirements-dev.txt 30 | 31 | - name: Build HTML docs 32 | run: make html 33 | 34 | typing: 35 | strategy: 36 | fail-fast: false 37 | matrix: 38 | python-version: 39 | - '3.13' 40 | os-version: 41 | - 'ubuntu-latest' 42 | runs-on: ${{ matrix.os-version }} 43 | steps: 44 | - uses: actions/checkout@v4 45 | with: 46 | persist-credentials: false 47 | 48 | - name: Set up Python 49 | uses: actions/setup-python@v5 50 | with: 51 | python-version: ${{ matrix.python-version }} 52 | 53 | - name: Install deps 54 | run: | 55 | python -mpip install wheel 56 | python -mpip install -r requirements-dev.txt 57 | 58 | - name: Check stubs 59 | if: (! startsWith(matrix.python-version, 'pypy-')) 60 | run: make mypy PYTHON=python 61 | 62 | 63 | test: 64 | strategy: 65 | fail-fast: false 66 | matrix: 67 | python-version: 68 | - '3.9' 69 | - '3.10' 70 | - '3.11' 71 | - '3.12' 72 | - '3.13' 73 | - '3.14.0-alpha.0 - 3.14' 74 | os-version: 75 | - 'ubuntu-latest' 76 | include: 77 | - os-version: 'macos-latest' 78 | python-version: '3.x' 79 | - os-version: 'windows-latest' 80 | python-version: '3.x' 81 | - os-version: 'ubuntu-latest' 82 | python-version: 'pypy-3.10' 83 | 84 | runs-on: ${{ matrix.os-version }} 85 | steps: 86 | - uses: actions/checkout@v4 87 | with: 88 | persist-credentials: false 89 | 90 | - name: Set up Python 91 | uses: actions/setup-python@v5 92 | with: 93 | python-version: ${{ matrix.python-version }} 94 | 95 | - name: Install deps 96 | run: | 97 | python -mpip install wheel 98 | python -mpip install -r requirements-dev.txt 99 | 100 | - name: Coverage 101 | run: make coverage PYTHON=python 102 | 103 | - name: Test installed version 104 | run: make test_venv PYTHON=python 105 | 106 | - name: Upload Coverage as artifact 107 | if: always() 108 | uses: actions/upload-artifact@v4 109 | with: 110 | name: coverage for ${{ matrix.python-version }} on ${{ matrix.os-version }} 111 | path: coverage.xml 112 | 113 | pre-commit: 114 | runs-on: ubuntu-latest 115 | steps: 116 | - uses: actions/checkout@v4 117 | with: 118 | persist-credentials: false 119 | 120 | - name: Set up Python 121 | uses: actions/setup-python@v5 122 | with: 123 | python-version: '3.x' 124 | 125 | - name: pre-commit 126 | run: pip install pre-commit && pre-commit run --all 127 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021-2024 Jeff Epler 2 | # 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | *,cover 6 | *.egg-info 7 | /.coverage* 8 | /.reuse 9 | /build 10 | /_build 11 | /coverage.xml 12 | /dist 13 | /finals2000A.all.csv 14 | /htmlcov 15 | /src/wwvb/__version__.py 16 | __pycache__ 17 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2020 Diego Elio Pettenò 2 | # SPDX-FileCopyrightText: 2020-2024 Jeff Epler 3 | # 4 | # SPDX-License-Identifier: Unlicense 5 | 6 | default_language_version: 7 | python: python3 8 | 9 | repos: 10 | - repo: https://github.com/pre-commit/pre-commit-hooks 11 | rev: v5.0.0 12 | hooks: 13 | - id: check-yaml 14 | - id: end-of-file-fixer 15 | exclude: src/wwvb/iersdata.json 16 | - id: trailing-whitespace 17 | exclude: test/wwvbgen_testcases 18 | - repo: https://github.com/fsfe/reuse-tool 19 | rev: v5.0.2 20 | hooks: 21 | - id: reuse 22 | - repo: https://github.com/astral-sh/ruff-pre-commit 23 | # Ruff version. 24 | rev: v0.11.7 25 | hooks: 26 | # Run the linter. 27 | - id: ruff 28 | args: [ --fix ] 29 | # Run the formatter. 30 | - id: ruff-format 31 | -------------------------------------------------------------------------------- /.readthedocs.yaml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2024 Jeff Epler 2 | # 3 | # SPDX-License-Identifier: GPL-3.0-only 4 | 5 | version: 2 6 | 7 | build: 8 | os: ubuntu-lts-latest 9 | tools: 10 | python: "3" 11 | 12 | sphinx: 13 | configuration: doc/conf.py 14 | 15 | python: 16 | install: 17 | - requirements: requirements-dev.txt 18 | -------------------------------------------------------------------------------- /LICENSES/CC0-1.0.txt: -------------------------------------------------------------------------------- 1 | Creative Commons Legal Code 2 | 3 | CC0 1.0 Universal 4 | 5 | CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE 6 | LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN 7 | ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS 8 | INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES 9 | REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS 10 | PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM 11 | THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED 12 | HEREUNDER. 13 | 14 | Statement of Purpose 15 | 16 | The laws of most jurisdictions throughout the world automatically confer 17 | exclusive Copyright and Related Rights (defined below) upon the creator 18 | and subsequent owner(s) (each and all, an "owner") of an original work of 19 | authorship and/or a database (each, a "Work"). 20 | 21 | Certain owners wish to permanently relinquish those rights to a Work for 22 | the purpose of contributing to a commons of creative, cultural and 23 | scientific works ("Commons") that the public can reliably and without fear 24 | of later claims of infringement build upon, modify, incorporate in other 25 | works, reuse and redistribute as freely as possible in any form whatsoever 26 | and for any purposes, including without limitation commercial purposes. 27 | These owners may contribute to the Commons to promote the ideal of a free 28 | culture and the further production of creative, cultural and scientific 29 | works, or to gain reputation or greater distribution for their Work in 30 | part through the use and efforts of others. 31 | 32 | For these and/or other purposes and motivations, and without any 33 | expectation of additional consideration or compensation, the person 34 | associating CC0 with a Work (the "Affirmer"), to the extent that he or she 35 | is an owner of Copyright and Related Rights in the Work, voluntarily 36 | elects to apply CC0 to the Work and publicly distribute the Work under its 37 | terms, with knowledge of his or her Copyright and Related Rights in the 38 | Work and the meaning and intended legal effect of CC0 on those rights. 39 | 40 | 1. Copyright and Related Rights. A Work made available under CC0 may be 41 | protected by copyright and related or neighboring rights ("Copyright and 42 | Related Rights"). Copyright and Related Rights include, but are not 43 | limited to, the following: 44 | 45 | i. the right to reproduce, adapt, distribute, perform, display, 46 | communicate, and translate a Work; 47 | ii. moral rights retained by the original author(s) and/or performer(s); 48 | iii. publicity and privacy rights pertaining to a person's image or 49 | likeness depicted in a Work; 50 | iv. rights protecting against unfair competition in regards to a Work, 51 | subject to the limitations in paragraph 4(a), below; 52 | v. rights protecting the extraction, dissemination, use and reuse of data 53 | in a Work; 54 | vi. database rights (such as those arising under Directive 96/9/EC of the 55 | European Parliament and of the Council of 11 March 1996 on the legal 56 | protection of databases, and under any national implementation 57 | thereof, including any amended or successor version of such 58 | directive); and 59 | vii. other similar, equivalent or corresponding rights throughout the 60 | world based on applicable law or treaty, and any national 61 | implementations thereof. 62 | 63 | 2. Waiver. To the greatest extent permitted by, but not in contravention 64 | of, applicable law, Affirmer hereby overtly, fully, permanently, 65 | irrevocably and unconditionally waives, abandons, and surrenders all of 66 | Affirmer's Copyright and Related Rights and associated claims and causes 67 | of action, whether now known or unknown (including existing as well as 68 | future claims and causes of action), in the Work (i) in all territories 69 | worldwide, (ii) for the maximum duration provided by applicable law or 70 | treaty (including future time extensions), (iii) in any current or future 71 | medium and for any number of copies, and (iv) for any purpose whatsoever, 72 | including without limitation commercial, advertising or promotional 73 | purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each 74 | member of the public at large and to the detriment of Affirmer's heirs and 75 | successors, fully intending that such Waiver shall not be subject to 76 | revocation, rescission, cancellation, termination, or any other legal or 77 | equitable action to disrupt the quiet enjoyment of the Work by the public 78 | as contemplated by Affirmer's express Statement of Purpose. 79 | 80 | 3. Public License Fallback. Should any part of the Waiver for any reason 81 | be judged legally invalid or ineffective under applicable law, then the 82 | Waiver shall be preserved to the maximum extent permitted taking into 83 | account Affirmer's express Statement of Purpose. In addition, to the 84 | extent the Waiver is so judged Affirmer hereby grants to each affected 85 | person a royalty-free, non transferable, non sublicensable, non exclusive, 86 | irrevocable and unconditional license to exercise Affirmer's Copyright and 87 | Related Rights in the Work (i) in all territories worldwide, (ii) for the 88 | maximum duration provided by applicable law or treaty (including future 89 | time extensions), (iii) in any current or future medium and for any number 90 | of copies, and (iv) for any purpose whatsoever, including without 91 | limitation commercial, advertising or promotional purposes (the 92 | "License"). The License shall be deemed effective as of the date CC0 was 93 | applied by Affirmer to the Work. Should any part of the License for any 94 | reason be judged legally invalid or ineffective under applicable law, such 95 | partial invalidity or ineffectiveness shall not invalidate the remainder 96 | of the License, and in such case Affirmer hereby affirms that he or she 97 | will not (i) exercise any of his or her remaining Copyright and Related 98 | Rights in the Work or (ii) assert any associated claims and causes of 99 | action with respect to the Work, in either case contrary to Affirmer's 100 | express Statement of Purpose. 101 | 102 | 4. Limitations and Disclaimers. 103 | 104 | a. No trademark or patent rights held by Affirmer are waived, abandoned, 105 | surrendered, licensed or otherwise affected by this document. 106 | b. Affirmer offers the Work as-is and makes no representations or 107 | warranties of any kind concerning the Work, express, implied, 108 | statutory or otherwise, including without limitation warranties of 109 | title, merchantability, fitness for a particular purpose, non 110 | infringement, or the absence of latent or other defects, accuracy, or 111 | the present or absence of errors, whether or not discoverable, all to 112 | the greatest extent permissible under applicable law. 113 | c. Affirmer disclaims responsibility for clearing rights of other persons 114 | that may apply to the Work or any use thereof, including without 115 | limitation any person's Copyright and Related Rights in the Work. 116 | Further, Affirmer disclaims responsibility for obtaining any necessary 117 | consents, permissions or other rights required for any use of the 118 | Work. 119 | d. Affirmer understands and acknowledges that Creative Commons is not a 120 | party to this document and has no duty or obligation with respect to 121 | this CC0 or use of the Work. 122 | -------------------------------------------------------------------------------- /LICENSES/GPL-3.0-only.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright © 2007 Free Software Foundation, Inc. 5 | 6 | Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for software and other kinds of works. 11 | 12 | The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. 13 | 14 | When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. 15 | 16 | To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. 17 | 18 | For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. 19 | 20 | Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. 21 | 22 | For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. 23 | 24 | Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. 25 | 26 | Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. 27 | 28 | The precise terms and conditions for copying, distribution and modification follow. 29 | 30 | TERMS AND CONDITIONS 31 | 32 | 0. Definitions. 33 | 34 | “This License” refers to version 3 of the GNU General Public License. 35 | 36 | “Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. 37 | 38 | “The Program” refers to any copyrightable work licensed under this License. Each licensee is addressed as “you”. “Licensees” and “recipients” may be individuals or organizations. 39 | 40 | To “modify” a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a “modified version” of the earlier work or a work “based on” the earlier work. 41 | 42 | A “covered work” means either the unmodified Program or a work based on the Program. 43 | 44 | To “propagate” a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. 45 | 46 | To “convey” a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. 47 | 48 | An interactive user interface displays “Appropriate Legal Notices” to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 49 | 50 | 1. Source Code. 51 | The “source code” for a work means the preferred form of the work for making modifications to it. “Object code” means any non-source form of a work. 52 | 53 | A “Standard Interface” means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. 54 | 55 | The “System Libraries” of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A “Major Component”, in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. 56 | 57 | The “Corresponding Source” for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. 58 | 59 | The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. 60 | 61 | The Corresponding Source for a work in source code form is that same work. 62 | 63 | 2. Basic Permissions. 64 | All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. 65 | 66 | You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. 67 | 68 | Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 69 | 70 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 71 | No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. 72 | 73 | When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 74 | 75 | 4. Conveying Verbatim Copies. 76 | You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. 77 | 78 | You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 79 | 80 | 5. Conveying Modified Source Versions. 81 | You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: 82 | 83 | a) The work must carry prominent notices stating that you modified it, and giving a relevant date. 84 | 85 | b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to “keep intact all notices”. 86 | 87 | c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. 88 | 89 | d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. 90 | 91 | A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an “aggregate” if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 92 | 93 | 6. Conveying Non-Source Forms. 94 | You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: 95 | 96 | a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. 97 | 98 | b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. 99 | 100 | c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. 101 | 102 | d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. 103 | 104 | e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. 105 | 106 | A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. 107 | 108 | A “User Product” is either (1) a “consumer product”, which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, “normally used” refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. 109 | 110 | “Installation Information” for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. 111 | 112 | If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). 113 | 114 | The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. 115 | 116 | Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 117 | 118 | 7. Additional Terms. 119 | “Additional permissions” are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. 120 | 121 | When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. 122 | 123 | Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: 124 | 125 | a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or 126 | 127 | b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or 128 | 129 | c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or 130 | 131 | d) Limiting the use for publicity purposes of names of licensors or authors of the material; or 132 | 133 | e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or 134 | 135 | f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. 136 | 137 | All other non-permissive additional terms are considered “further restrictions” within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. 138 | 139 | If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. 140 | 141 | Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 142 | 143 | 8. Termination. 144 | You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). 145 | 146 | However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. 147 | 148 | Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. 149 | 150 | Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 151 | 152 | 9. Acceptance Not Required for Having Copies. 153 | You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 154 | 155 | 10. Automatic Licensing of Downstream Recipients. 156 | Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. 157 | 158 | An “entity transaction” is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. 159 | 160 | You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 161 | 162 | 11. Patents. 163 | A “contributor” is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's “contributor version”. 164 | 165 | A contributor's “essential patent claims” are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, “control” includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. 166 | 167 | Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. 168 | 169 | In the following three paragraphs, a “patent license” is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To “grant” such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. 170 | 171 | If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. “Knowingly relying” means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. 172 | 173 | If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. 174 | 175 | A patent license is “discriminatory” if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. 176 | 177 | Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 178 | 179 | 12. No Surrender of Others' Freedom. 180 | If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 181 | 182 | 13. Use with the GNU Affero General Public License. 183 | Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 184 | 185 | 14. Revised Versions of this License. 186 | The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. 187 | 188 | Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. 189 | 190 | If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. 191 | 192 | Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 193 | 194 | 15. Disclaimer of Warranty. 195 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 196 | 197 | 16. Limitation of Liability. 198 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 199 | 200 | 17. Interpretation of Sections 15 and 16. 201 | If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. 202 | 203 | END OF TERMS AND CONDITIONS 204 | 205 | How to Apply These Terms to Your New Programs 206 | 207 | If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. 208 | 209 | To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found. 210 | 211 | 212 | Copyright (C) 213 | 214 | This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. 215 | 216 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 217 | 218 | You should have received a copy of the GNU General Public License along with this program. If not, see . 219 | 220 | Also add information on how to contact you by electronic and paper mail. 221 | 222 | If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: 223 | 224 | Copyright (C) 225 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 226 | This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. 227 | 228 | The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an “about box”. 229 | 230 | You should also get your employer (if you work as a programmer) or school, if any, to sign a “copyright disclaimer” for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . 231 | 232 | The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . 233 | -------------------------------------------------------------------------------- /LICENSES/Unlicense.txt: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or distribute 4 | this software, either in source code form or as a compiled binary, for any 5 | purpose, commercial or non-commercial, and by any means. 6 | 7 | In jurisdictions that recognize copyright laws, the author or authors of this 8 | software dedicate any and all copyright interest in the software to the public 9 | domain. We make this dedication for the benefit of the public at large and 10 | to the detriment of our heirs and 11 | successors. We intend this dedication to be an overt act of relinquishment 12 | in perpetuity of all present and future rights to this software under copyright 13 | law. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 18 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH 20 | THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | For more information, please refer to 23 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | ifeq ("$(origin V)", "command line") 2 | BUILD_VERBOSE=$(V) 3 | endif 4 | ifndef BUILD_VERBOSE 5 | $(info Use make V=1, make V=2 or set BUILD_VERBOSE similarly in your environment to increase build verbosity.) 6 | BUILD_VERBOSE = 0 7 | endif 8 | ifeq ($(BUILD_VERBOSE),0) 9 | Q = @ 10 | STEPECHO = @: 11 | else ifeq ($(BUILD_VERBOSE),1) 12 | Q = @ 13 | STEPECHO = @echo 14 | else 15 | Q = 16 | STEPECHO = @echo 17 | endif 18 | 19 | PYTHON ?= python3 20 | ifeq ($(OS),Windows_NT) 21 | ENVPYTHON ?= _env/Scripts/python.exe 22 | else 23 | ENVPYTHON ?= _env/bin/python3 24 | endif 25 | 26 | .PHONY: default 27 | default: coverage mypy 28 | 29 | COVERAGE_INCLUDE=--include "src/**/*.py" 30 | .PHONY: coverage 31 | coverage: 32 | $(Q)$(PYTHON) -mcoverage erase 33 | $(Q)env PYTHONPATH=src $(PYTHON) -mcoverage run --branch -p -m unittest discover -s test 34 | $(Q)$(PYTHON) -mcoverage combine -q 35 | $(Q)$(PYTHON) -mcoverage html $(COVERAGE_INCLUDE) 36 | $(Q)$(PYTHON) -mcoverage xml $(COVERAGE_INCLUDE) 37 | $(Q)$(PYTHON) -mcoverage report --fail-under=100 $(COVERAGE_INCLUDE) 38 | 39 | .PHONY: test_venv 40 | test_venv: 41 | $(Q)$(PYTHON) -mvenv --clear _env 42 | $(Q)$(ENVPYTHON) -mpip install . 43 | $(Q)$(ENVPYTHON) -m unittest discover -s test 44 | 45 | .PHONY: mypy 46 | mypy: 47 | $(Q)mypy --strict --no-warn-unused-ignores src test 48 | 49 | .PHONY: update 50 | update: 51 | $(Q)env PYTHONPATH=src $(PYTHON) -mwwvb.updateiers --dist 52 | 53 | # Minimal makefile for Sphinx documentation 54 | # 55 | 56 | # You can set these variables from the command line, and also 57 | # from the environment for the first two. 58 | SPHINXOPTS ?= -a -E -j auto 59 | SPHINXBUILD ?= sphinx-build 60 | SOURCEDIR = doc 61 | BUILDDIR = _build 62 | 63 | # Route particular targets to Sphinx using the new 64 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 65 | .PHONY: html 66 | html: 67 | $(Q)$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 68 | 69 | # SPDX-FileCopyrightText: 2024 Jeff Epler 70 | # 71 | # SPDX-License-Identifier: GPL-3.0-only 72 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 6 | [![Test wwvbgen](https://github.com/jepler/wwvbpy/actions/workflows/test.yml/badge.svg)](https://github.com/jepler/wwvbpy/actions/workflows/test.yml) 7 | [![codecov](https://codecov.io/gh/jepler/wwvbpy/branch/main/graph/badge.svg?token=Exx0c3Gp65)](https://codecov.io/gh/jepler/wwvbpy) 8 | [![Update DUT1 data](https://github.com/jepler/wwvbpy/actions/workflows/cron.yml/badge.svg)](https://github.com/jepler/wwvbpy/actions/workflows/cron.yml) 9 | [![PyPI](https://img.shields.io/pypi/v/wwvb)](https://pypi.org/project/wwvb) 10 | [![pre-commit.ci status](https://results.pre-commit.ci/badge/github/jepler/wwvbpy/main.svg)](https://results.pre-commit.ci/latest/github/jepler/wwvbpy/main) 11 | 12 | # Purpose 13 | 14 | Python package and command line programs for interacting with WWVB timecodes. 15 | 16 | Where possible, wwvbpy uses existing facilities for calendar and time 17 | manipulation (datetime and dateutil). 18 | 19 | It uses DUT1/leap second data derived from IERS Bulletin "A" and from NIST's 20 | "Leap second and UT1-UTC information" page. With regular updates to 21 | the "iersdata", wwvbpy should be able to correctly encode the time anywhere 22 | within the 100-year WWVB epoch. (yes, WWVB uses a 2-digit year! In order to 23 | work with historical data, the epoch is arbitrarily assumed to run from 1970 to 24 | 2069.) 25 | 26 | Programs include: 27 | * `wwvbgen`, the main commandline generator program 28 | * `wwvbdecode`, the main commandline decoder program 29 | * `wwvbtk`, visualize the simulated WWVB signal in real-time using Tkinter 30 | * `dut1table`, print the full history of dut1 values, including estimated future values 31 | * `updateiers`, download the latest dut1 data including prospective data from IERS and NIST 32 | 33 | The package includes: 34 | * `wwvb`, for generating WWVB timecodes 35 | * `wwvb.decode`, a generator-based state machine for decoding WWVB timecodes (amplitude modulation only) 36 | * `uwwvb`, a version of the decoder intended for use on constrained environments such as [CircuitPython](https://circuitpython.org). 37 | 38 | # Development status 39 | 40 | The author ([@jepler](https://github.com/jepler)) occasionally develops and maintains this project, but 41 | issues are not likely to be acted on. They would be interested in adding 42 | co-maintainer(s). 43 | 44 | 45 | # WWVB Timecodes 46 | 47 | The National Institute of Standards and Technology operates the WWVB time 48 | signal service near Fort Collins, Colorado. The signal can be received in most 49 | of the continental US. Each minute, the signal transmits the current time, 50 | including information about leap years, daylight saving time, and leap seconds. 51 | The signal is composed of an amplitude channel and a phase modulation channel. 52 | 53 | The amplitude channel can be visualized as a sequence of (usually) 60 symbols, 54 | which by default wwvbgen displays as 0, 1, or 2. The 0s and 1s encode 55 | information like the current day of the year, while the 2s appear in fixed 56 | locations to allow a receiver to determine the start of a minute. 57 | 58 | The phase channel (which is displayed with `--channel=phase` or 59 | `--channel=both`) consists of the same number of symbols per minute. This 60 | channel is substantially more complicated than the phase channel. It encodes 61 | the current time as minute-of-the-century, provides extended DST information, 62 | and includes error-correction information not available in the amplitude 63 | channel. 64 | 65 | # Usage 66 | 67 | ~~~~ 68 | Usage: wwvbgen [OPTIONS] [TIMESPEC]... 69 | 70 | Generate WWVB timecodes 71 | 72 | TIMESPEC: one of "year yday hour minute" or "year month day hour minute", or 73 | else the current minute 74 | 75 | Options: 76 | -i, --iers / -I, --no-iers Whether to use IESR data for DUT1 and LS. 77 | (Default: --iers) 78 | -s, --leap-second Force a positive leap second at the end of 79 | the GMT month (Implies --no-iers) 80 | -n, --negative-leap-second Force a negative leap second at the end of 81 | the GMT month (Implies --no-iers) 82 | -S, --no-leap-second Force no leap second at the end of the month 83 | (Implies --no-iers) 84 | -d, --dut1 INTEGER Force the DUT1 value (Implies --no-iers) 85 | -m, --minutes INTEGER Number of minutes to show (default: 10) 86 | --style [bar|cradek|default|duration|json|sextant] 87 | Style of output 88 | -t, --all-timecodes / -T, --no-all-timecodes 89 | Show the 'WWVB timecode' line before each 90 | minute 91 | --channel [amplitude|phase|both] 92 | Modulation to show (default: amplitude) 93 | --help Show this message and exit. 94 | ~~~~ 95 | 96 | For example, to display the leap second that occurred at the end of 1998, 97 | ~~~~ 98 | $ wwvbgen -m 7 1998 365 23 56 99 | WWVB timecode: year=98 days=365 hour=23 min=56 dst=0 ut1=-300 ly=0 ls=1 100 | '98+365 23:56 210100110200100001120011001102010100010200110100121000001002 101 | '98+365 23:57 210100111200100001120011001102010100010200110100121000001002 102 | '98+365 23:58 210101000200100001120011001102010100010200110100121000001002 103 | '98+365 23:59 2101010012001000011200110011020101000102001101001210000010022 104 | '99+001 00:00 200000000200000000020000000002000100101201110100121001000002 105 | '99+001 00:01 200000001200000000020000000002000100101201110100121001000002 106 | '99+001 00:02 200000010200000000020000000002000100101201110100121001000002 107 | ~~~~ 108 | (the leap second is the extra digit at the end of the 23:59 line; that minute 109 | consists of 61 seconds, instead of the normal 60) 110 | 111 | 112 | # How wwvbpy handles DUT1 data 113 | 114 | wwvbpy stores a compact representation of DUT1 values in `wwvb/iersdata_dist.py` or `wwvb_iersdata.py`. 115 | In this representation, one value is used for one day (0000UTC through 2359UTC). 116 | The letters `a` through `u` represent offsets of -1.0s through +1.0s 117 | in 0.1s increments; `k` represents 0s. (In practice, only a smaller range 118 | of values, typically -0.7s to +0.8s, is seen) 119 | 120 | For 2001 through 2024, NIST has published the actual DUT1 values broadcast, 121 | and the date of each change, though it in the format of an HTML 122 | table and not designed for machine readability: 123 | 124 | https://www.nist.gov/pml/time-and-frequency-division/atomic-standards/leap-second-and-ut1-utc-information 125 | 126 | NIST does not update the value daily and does not seem to follow any 127 | specific rounding rule. Rather, in WWVB "the resolution of the DUT1 128 | correction is 0.1 s, and represents an average value for an extended 129 | range of dates. Therefore, it will not agree exactly with the weekly 130 | UT1-UTC(NIST) values shown in the earlier table, which have 1 ms 131 | resolution and are updated weekly." Like wwvbpy's compact 132 | representation of DUT1 values, the real WWVB does not appear to ever 133 | broadcast DUT1=-0.0. 134 | 135 | For a larger range of dates spanning 1973 through approximately one year from 136 | now, IERS publishes historical and prospective UT1-UTC values to multiple 137 | decimal places, in a machine readable fixed length format. 138 | 139 | wwvbpy merges the WWVB and IERS datasets, favoring the WWVB dataset for dates when it is available. There are some caveats to this, which are mostly commented in the `wwvb/updateiers.py` script. 140 | 141 | `wwvb/iersdata_dist.py` is updated monthly from github actions or with `iersdata --dist` from within the wwvbpy source tree. However, at this time, releases are not regularly made from the updated information. 142 | 143 | A site or user version of the file, `wwvb_iersdata.py` can be created or updated with `iersdata --site` or `iersdata --user`. If the distributed iersdata is out of date, the generator will prompt you to run the update command. 144 | 145 | Leap seconds are inferred from the DUT1 data as follows: If X and Y are the 146 | 1-digit-rounded DUT1 values for consecutive dates, and `X*Y<0`, then there is a 147 | leap second at the end of day X. The direction of the leap second can be 148 | inferred from the sign of X, a 59-second minute if X is positive and a 149 | 61-second minute if it is negative. As long 150 | as DUT1 changes slowly enough during other times that there is at least one day 151 | of DUT1=+0.0, no incorrect (negative) leapsecond will be inferred. (something 152 | that should remain true for the next few centuries, until the length of the day 153 | is 100ms different from 86400 seconds) 154 | 155 | 156 | # The phase modulation channel 157 | 158 | This should be considered more experimental than the AM channel, as the 159 | tests only cover a single reference minute. Further tests could be informed 160 | by the [other implementation I know of](http://www.leapsecond.com/tools/wwvb_pm.c), except that implementation appears incomplete. 161 | 162 | 163 | # Testing wwvbpy 164 | 165 | Run the testsuite, check coverage & type annotations with `gmake`. 166 | 167 | There are several test suites: 168 | * `testwwvb.py`: Check output against expected values. Uses hard coded leap seconds. Tests amplitude and phase data, though the phase testcases are dubious as they were also generated by wwvbpy. 169 | * `testuwwvb.py`: Test the reduced-functionality version against the main version 170 | * `testls.py`: Check the IERS data through 2020-1-1 for expected leap seconds 171 | * `testpm.py`: Check the phase modulation data against a test case from NIST documentation 172 | * `testcli.py`: Check the commandline programs work as expected (limited tests to get 100% coverage) 173 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jepler/wwvbpy/e7abe548210a74ef2117c6ea64b033ef67e72223/codecov.yml -------------------------------------------------------------------------------- /doc/_static/.empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jepler/wwvbpy/e7abe548210a74ef2117c6ea64b033ef67e72223/doc/_static/.empty -------------------------------------------------------------------------------- /doc/conf.py: -------------------------------------------------------------------------------- 1 | # ruff: noqa 2 | # fmt: off 3 | # Configuration file for the Sphinx documentation builder. 4 | # 5 | # This file only contains a selection of the most common options. For a full 6 | # list see the documentation: 7 | # https://www.sphinx-doc.org/en/master/usage/configuration.html 8 | 9 | # -- Path setup -------------------------------------------------------------- 10 | 11 | # If extensions (or modules to document with autodoc) are in another directory, 12 | # add these directories to sys.path here. If the directory is relative to the 13 | # documentation root, use os.path.abspath to make it absolute, like shown here. 14 | # 15 | import os 16 | import re 17 | import subprocess 18 | import sys 19 | import pathlib 20 | 21 | ROOT = pathlib.Path(__file__).absolute().parent.parent 22 | sys.path.insert(0, str(ROOT / "src")) 23 | 24 | 25 | # -- Project information ----------------------------------------------------- 26 | 27 | project = "wwvb" 28 | copyright = "2021, Jeff Epler" 29 | author = "Jeff Epler" 30 | 31 | # The full version, including alpha/beta/rc tags 32 | final_version = "" 33 | git_describe = subprocess.run( 34 | ["git", "describe", "--tags", "--dirty"], 35 | stdout=subprocess.PIPE, 36 | stderr=subprocess.STDOUT, 37 | encoding="utf-8", check=False, 38 | ) 39 | if git_describe.returncode == 0: 40 | git_version = re.search( 41 | r"^\d(?:\.\d){0,2}(?:\-(?:alpha|beta|rc)\.\d+){0,1}", 42 | str(git_describe.stdout), 43 | ) 44 | if git_version: 45 | final_version = git_version[0] 46 | else: 47 | print("Failed to retrieve git version:", git_describe.stdout) 48 | 49 | version = release = final_version 50 | 51 | 52 | # -- General configuration --------------------------------------------------- 53 | 54 | # Add any Sphinx extension module names here, as strings. They can be 55 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 56 | # ones. 57 | extensions = [ 58 | "sphinx.ext.autodoc", 59 | "sphinx_mdinclude", 60 | ] 61 | 62 | # Add any paths that contain templates here, relative to this directory. 63 | templates_path = ["_templates"] 64 | 65 | # List of patterns, relative to source directory, that match files and 66 | # directories to ignore when looking for source files. 67 | # This pattern also affects html_static_path and html_extra_path. 68 | exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] 69 | 70 | 71 | # -- Options for HTML output ------------------------------------------------- 72 | 73 | # The theme to use for HTML and HTML Help pages. See the documentation for 74 | # a list of builtin themes. 75 | # 76 | html_theme = "sphinx_rtd_theme" 77 | 78 | # Add any paths that contain custom static files (such as style sheets) here, 79 | # relative to this directory. They are copied after the builtin static files, 80 | # so a file named "default.css" will overwrite the builtin "default.css". 81 | html_static_path = ["_static"] 82 | 83 | autodoc_typehints = "description" 84 | autodoc_class_signature = "separated" 85 | 86 | default_role = "any" 87 | 88 | intersphinx_mapping = {'py': ('https://docs.python.org/3', None)} 89 | 90 | # SPDX-FileCopyrightText: 2021-2024 Jeff Epler 91 | # 92 | # SPDX-License-Identifier: GPL-3.0-only 93 | -------------------------------------------------------------------------------- /doc/index.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-FileCopyrightText: 2021-2024 Jeff Epler 2 | .. 3 | .. SPDX-License-Identifier: GPL-3.0-only 4 | 5 | wwvbpy |version| 6 | ================ 7 | 8 | .. mdinclude:: ../README.md 9 | 10 | .. toctree:: 11 | :maxdepth: 2 12 | :caption: Contents: 13 | 14 | wwvb module 15 | =========== 16 | 17 | .. automodule:: wwvb 18 | :members: 19 | 20 | uwwvb module 21 | ============ 22 | 23 | .. automodule:: uwwvb 24 | :members: 25 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021-2024 Jeff Epler 2 | # 3 | # SPDX-License-Identifier: GPL-3.0-only 4 | 5 | [build-system] 6 | requires = [ 7 | "setuptools>=68", 8 | "setuptools_scm[toml]>=6.0", 9 | ] 10 | build-backend = "setuptools.build_meta" 11 | [tool.setuptool] 12 | package_dir = {"" = "src"} 13 | include-package-data = true 14 | 15 | [tool.setuptools.dynamic] 16 | readme = {file = ["README.md"], content-type="text/markdown"} 17 | dependencies = {file = "requirements.txt"} 18 | [tool.setuptools_scm] 19 | write_to = "src/wwvb/__version__.py" 20 | [tool.ruff.lint] 21 | 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"] 22 | ignore = ["D203", "D213", "D400", "D415", "ISC001", "E741", "C901", "PLR0911", "PLR2004", "PLR0913", "COM812"] 23 | [tool.ruff] 24 | line-length = 120 25 | [project] 26 | name = "wwvb" 27 | authors = [{name = "Jeff Epler", email = "jepler@gmail.com"}] 28 | description = "Generate WWVB timecodes for any desired time" 29 | dynamic = ["readme","version","dependencies"] 30 | classifiers = [ 31 | "Programming Language :: Python :: 3", 32 | "Programming Language :: Python :: 3.9", 33 | "Programming Language :: Python :: 3.10", 34 | "Programming Language :: Python :: 3.11", 35 | "Programming Language :: Python :: Implementation :: PyPy", 36 | "Programming Language :: Python :: Implementation :: CPython", 37 | "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", 38 | "Operating System :: OS Independent", 39 | ] 40 | requires-python = ">=3.9" 41 | [project.urls] 42 | Source = "https://github.com/jepler/wwvbpy" 43 | Documentation = "https://github.com/jepler/wwvbpy" 44 | [project.scripts] 45 | wwvbgen = "wwvb.gen:main" 46 | wwvbdecode = "wwvb.decode:main" 47 | dut1table = "wwvb.dut1table:main" 48 | updateiers = "wwvb.updateiers:main" 49 | [project.gui-scripts] 50 | wwvbtk = "wwvb.wwvbtk:main" 51 | [[tool.mypy.overrides]] 52 | module = ["adafruit_datetime"] 53 | follow_untyped_imports = true 54 | -------------------------------------------------------------------------------- /requirements-dev.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021-2024 Jeff Epler 2 | # 3 | # SPDX-License-Identifier: GPL-3.0-only 4 | adafruit-circuitpython-datetime 5 | beautifulsoup4 6 | build 7 | click 8 | coverage 9 | mypy; implementation_name=="cpython" 10 | click>=8.1.5; implementation_name=="cpython" 11 | leapseconddata 12 | platformdirs 13 | pre-commit 14 | python-dateutil 15 | requests; implementation_name=="cpython" 16 | setuptools>=68; implementation_name=="cpython" 17 | sphinx 18 | sphinx-autodoc-typehints 19 | sphinx-rtd-theme 20 | sphinx-mdinclude 21 | twine; implementation_name=="cpython" 22 | types-beautifulsoup4; implementation_name=="cpython" 23 | types-python-dateutil; implementation_name=="cpython" 24 | types-requests; implementation_name=="cpython" 25 | tzdata 26 | wheel 27 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021-2024 Jeff Epler 2 | # 3 | # SPDX-License-Identifier: GPL-3.0-only 4 | adafruit-circuitpython-datetime 5 | beautifulsoup4 6 | click 7 | leapseconddata 8 | platformdirs 9 | python-dateutil 10 | requests 11 | tzdata 12 | -------------------------------------------------------------------------------- /src/uwwvb.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021-2024 Jeff Epler 2 | # 3 | # SPDX-License-Identifier: GPL-3.0-only 4 | 5 | # ruff: noqa: C405 PYI024 PLR2004 FBT001 FBT002 6 | 7 | """Implementation of a WWVB state machine & decoder for resource-constrained systems 8 | 9 | This version is intended for use with MicroPython & CircuitPython. 10 | """ 11 | 12 | from __future__ import annotations 13 | 14 | from collections import namedtuple 15 | 16 | import adafruit_datetime as datetime 17 | 18 | ZERO, ONE, MARK = range(3) 19 | 20 | always_mark = set((0, 9, 19, 29, 39, 49, 59)) 21 | always_zero = set((4, 10, 11, 14, 20, 21, 34, 35, 44, 54)) 22 | bcd_weights = (1, 2, 4, 8, 10, 20, 40, 80, 100, 200, 400, 800) 23 | 24 | WWVBMinute = namedtuple("WWVBMinute", ["year", "days", "hour", "minute", "dst", "ut1", "ls", "ly"]) 25 | 26 | 27 | class WWVBDecoder: 28 | """A state machine for receiving WWVB timecodes.""" 29 | 30 | def __init__(self) -> None: 31 | """Construct a WWVBDecoder""" 32 | self.minute: list[int] = [] 33 | self.state = 1 34 | 35 | def update(self, value: int) -> list[int] | None: 36 | """Update the _state machine when a new symbol is received. 37 | 38 | If a possible complete _minute is received, return it; otherwise, return None 39 | """ 40 | result = None 41 | if self.state == 1: 42 | self.minute = [] 43 | if value == MARK: 44 | self.state = 2 45 | 46 | elif self.state == 2: 47 | if value == MARK: 48 | self.state = 3 49 | else: 50 | self.state = 1 51 | 52 | elif self.state == 3: 53 | if value != MARK: 54 | self.minute = [MARK, value] 55 | self.state = 4 56 | 57 | else: # self.state == 4: 58 | idx = len(self.minute) 59 | self.minute.append(value) 60 | if (idx in always_mark) != (value == MARK): 61 | self.state = 3 if self.minute[-2] == MARK else 2 62 | elif idx in always_zero and value != ZERO: 63 | self.state = 1 64 | 65 | elif idx == 59: 66 | result = self.minute 67 | self.minute = [] 68 | self.state = 2 69 | 70 | return result 71 | 72 | def __str__(self) -> str: 73 | """Return a string representation of self""" 74 | return f"" 75 | 76 | 77 | def get_am_bcd(seq: list[int], *poslist: int) -> int | None: 78 | """Convert the bits seq[positions[0]], ... seq[positions[len(positions-1)]] [in MSB order] from BCD to decimal""" 79 | pos = list(poslist)[::-1] 80 | val = [int(seq[p]) for p in pos] 81 | while len(val) % 4 != 0: 82 | val.append(0) 83 | result = 0 84 | base = 1 85 | for i in range(0, len(val), 4): 86 | digit = 0 87 | for j in range(4): 88 | digit += 1 << j if val[i + j] else 0 89 | if digit > 9: 90 | return None 91 | result += digit * base 92 | base *= 10 93 | return result 94 | 95 | 96 | def decode_wwvb( 97 | t: list[int] | None, 98 | ) -> WWVBMinute | None: 99 | """Convert a received minute of wwvb symbols to a WWVBMinute. Returns None if any error is detected.""" 100 | if not t: 101 | return None 102 | if not all(t[i] == MARK for i in always_mark): 103 | return None 104 | if not all(t[i] == ZERO for i in always_zero): 105 | return None 106 | # Checking redundant DUT1 sign bits 107 | if t[36] == t[37]: 108 | return None 109 | if t[36] != t[38]: 110 | return None 111 | minute = get_am_bcd(t, 1, 2, 3, 5, 6, 7, 8) 112 | if minute is None: 113 | return None 114 | 115 | hour = get_am_bcd(t, 12, 13, 15, 16, 17, 18) 116 | if hour is None: 117 | return None 118 | 119 | days = get_am_bcd(t, 22, 23, 25, 26, 27, 28, 30, 31, 32, 33) 120 | if days is None: 121 | return None 122 | 123 | abs_ut1 = get_am_bcd(t, 40, 41, 42, 43) 124 | if abs_ut1 is None: 125 | return None 126 | 127 | abs_ut1 *= 100 128 | ut1_sign = t[38] 129 | ut1 = abs_ut1 if ut1_sign else -abs_ut1 130 | year = get_am_bcd(t, 45, 46, 47, 48, 50, 51, 52, 53) 131 | if year is None: 132 | return None 133 | 134 | is_ly = t[55] 135 | if days > 366 or (not is_ly and days > 365): 136 | return None 137 | ls = t[56] 138 | dst = get_am_bcd(t, 57, 58) 139 | assert dst is not None # No possibility of BCD decode error in 2 bits 140 | 141 | return WWVBMinute(year, days, hour, minute, dst, ut1, ls, is_ly) 142 | 143 | 144 | def as_datetime_utc(decoded_timestamp: WWVBMinute) -> datetime.datetime: 145 | """Convert a WWVBMinute to a UTC datetime""" 146 | d = datetime.datetime(decoded_timestamp.year + 2000, 1, 1) 147 | d += datetime.timedelta( 148 | decoded_timestamp.days - 1, 149 | decoded_timestamp.hour * 3600 + decoded_timestamp.minute * 60, 150 | ) 151 | return d 152 | 153 | 154 | def is_dst( 155 | dt: datetime.datetime, 156 | dst_bits: int, 157 | standard_time_offset: int = 7 * 3600, 158 | dst_observed: bool = True, 159 | ) -> bool: 160 | """Return True iff DST is observed at the given moment""" 161 | d = dt - datetime.timedelta(seconds=standard_time_offset) 162 | if not dst_observed: 163 | return False 164 | if dst_bits == 0b10: 165 | transition_time = dt.replace(hour=2) 166 | return d >= transition_time 167 | if dst_bits == 0b11: 168 | return True 169 | if dst_bits == 0b01: 170 | # DST ends at 2AM *DST* which is 1AM *standard* 171 | transition_time = dt.replace(hour=1) 172 | return d < transition_time 173 | return False 174 | 175 | 176 | def apply_dst( 177 | dt: datetime.datetime, 178 | dst_bits: int, 179 | standard_time_offset: int = 7 * 3600, 180 | dst_observed: bool = True, 181 | ) -> datetime.datetime: 182 | """Apply time zone and DST (if applicable) to the given moment""" 183 | d = dt - datetime.timedelta(seconds=standard_time_offset) 184 | if is_dst(dt, dst_bits, standard_time_offset, dst_observed): 185 | d += datetime.timedelta(seconds=3600) 186 | return d 187 | 188 | 189 | def as_datetime_local( 190 | decoded_timestamp: WWVBMinute, 191 | standard_time_offset: int = 7 * 3600, 192 | dst_observed: bool = True, 193 | ) -> datetime.datetime: 194 | """Convert a WWVBMinute to a local datetime with tzinfo=None""" 195 | dt = as_datetime_utc(decoded_timestamp) 196 | return apply_dst(dt, decoded_timestamp.dst, standard_time_offset, dst_observed) 197 | -------------------------------------------------------------------------------- /src/wwvb/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """A package and CLI for WWVB timecodes 3 | 4 | This is the full featured library suitable for use on 'real computers'. 5 | For a reduced version suitable for use on MicroPython & CircuitPython, 6 | see `uwwvb`. 7 | 8 | This package also includes the commandline programs listed above, 9 | perhaps most importantly ``wwvbgen`` for generating WWVB timecodes. 10 | """ 11 | 12 | # SPDX-FileCopyrightText: 2011-2024 Jeff Epler 13 | # 14 | # SPDX-License-Identifier: GPL-3.0-only 15 | 16 | from __future__ import annotations 17 | 18 | import datetime 19 | import enum 20 | import json 21 | import warnings 22 | from typing import TYPE_CHECKING, Any, NamedTuple, TextIO, TypeVar 23 | 24 | from . import iersdata 25 | from .tz import Mountain 26 | 27 | if TYPE_CHECKING: 28 | from collections.abc import Generator 29 | 30 | HOUR = datetime.timedelta(seconds=3600) 31 | SECOND = datetime.timedelta(seconds=1) 32 | T = TypeVar("T") 33 | 34 | 35 | def _removeprefix(s: str, p: str) -> str: 36 | if s.startswith(p): 37 | return s[len(p) :] 38 | return s 39 | 40 | 41 | def _date(dt: datetime.date) -> datetime.date: 42 | """Return the date object itself, or the date property of a datetime""" 43 | if isinstance(dt, datetime.datetime): 44 | return dt.date() 45 | return dt 46 | 47 | 48 | def _maybe_warn_update(dt: datetime.date, stacklevel: int = 1) -> None: 49 | """Maybe print a notice to run updateiers, if it seems useful to do so.""" 50 | # We already know this date is not covered. 51 | # If the date is less than 300 days after today, there should be (possibly) 52 | # prospective available now. 53 | today = datetime.datetime.now(tz=datetime.timezone.utc).date() 54 | if _date(dt) < today + datetime.timedelta(days=330): 55 | warnings.warn( 56 | "Note: Running `updateiers` may provide better DUT1 and LS information", 57 | stacklevel=stacklevel + 1, 58 | ) 59 | 60 | 61 | def get_dut1(dt: datetime.date, *, warn_outdated: bool = True) -> float: 62 | """Return the DUT1 number for the given timestamp""" 63 | date = _date(dt) 64 | i = (date - iersdata.DUT1_DATA_START).days 65 | if i < 0: 66 | v = iersdata.DUT1_OFFSETS[0] 67 | elif i >= len(iersdata.DUT1_OFFSETS): 68 | if warn_outdated: 69 | _maybe_warn_update(dt, stacklevel=2) 70 | v = iersdata.DUT1_OFFSETS[-1] 71 | else: 72 | v = iersdata.DUT1_OFFSETS[i] 73 | return (ord(v) - ord("k")) / 10.0 74 | 75 | 76 | def isly(year: int) -> bool: 77 | """Return True if the year is a leap year""" 78 | d1 = datetime.date(year, 1, 1) 79 | d2 = d1 + datetime.timedelta(days=365) 80 | return d1.year == d2.year 81 | 82 | 83 | def isls(t: datetime.date) -> bool: 84 | """Return True if a leap second occurs at the end of this month""" 85 | dut1_today = get_dut1(t) 86 | month_today = t.month 87 | while t.month == month_today: 88 | t += datetime.timedelta(1) 89 | dut1_next_month = get_dut1(t) 90 | return dut1_today * dut1_next_month < 0 91 | 92 | 93 | def isdst(t: datetime.date, tz: datetime.tzinfo = Mountain) -> bool: 94 | """Return true if daylight saving time is active at the start of the given UTC day""" 95 | utc_daystart = datetime.datetime(t.year, t.month, t.day, tzinfo=datetime.timezone.utc) 96 | return bool(utc_daystart.astimezone(tz).dst()) 97 | 98 | 99 | def _first_sunday_on_or_after(dt: datetime.date) -> datetime.date: 100 | """Return the first sunday on or after the reference time""" 101 | days_to_go = 6 - dt.weekday() 102 | if days_to_go: 103 | return dt + datetime.timedelta(days_to_go) 104 | return dt 105 | 106 | 107 | def _first_sunday_in_month(y: int, m: int) -> datetime.date: 108 | """Find the first sunday in a given month""" 109 | return _first_sunday_on_or_after(datetime.datetime(y, m, 1, tzinfo=datetime.timezone.utc)) 110 | 111 | 112 | def _is_dst_change_day(t: datetime.date, tz: datetime.tzinfo = Mountain) -> bool: 113 | """Return True if the day is a DST change day""" 114 | return isdst(t, tz) != isdst(t + datetime.timedelta(1), tz) 115 | 116 | 117 | def _get_dst_change_hour(t: datetime.date, tz: datetime.tzinfo = Mountain) -> int | None: 118 | """Return the hour when DST changes""" 119 | lt0 = datetime.datetime(t.year, t.month, t.day, hour=0, tzinfo=tz) 120 | dst0 = lt0.dst() 121 | for i in (1, 2, 3): 122 | lt1 = (lt0.astimezone(datetime.timezone.utc) + HOUR * i).astimezone(tz) 123 | dst1 = lt1.dst() 124 | lt2 = lt1 - SECOND 125 | dst2 = lt2.dst() 126 | if dst0 == dst2 and dst0 != dst1: 127 | return i - 1 128 | return None 129 | 130 | 131 | def _get_dst_change_date_and_row( 132 | d: datetime.date, 133 | tz: datetime.tzinfo = Mountain, 134 | ) -> tuple[datetime.date | None, int | None]: 135 | """Classify DST information for the WWVB phase modulation signal""" 136 | if isdst(d, tz): 137 | n = _first_sunday_in_month(d.year, 11) 138 | for offset in range(-28, 28, 7): 139 | d1 = n + datetime.timedelta(days=offset) 140 | if _is_dst_change_day(d1, tz): 141 | return d1, (offset + 28) // 7 142 | else: 143 | m = _first_sunday_in_month(d.year + (d.month > 3), 3) 144 | for offset in range(0, 52, 7): 145 | d1 = m + datetime.timedelta(days=offset) 146 | if _is_dst_change_day(d1, tz): 147 | return d1, offset // 7 148 | 149 | return None, None 150 | 151 | 152 | # "Table 8", likely with transcrption errors 153 | _dsttable = [ 154 | [ 155 | [ 156 | 0b110001, 157 | 0b100110, 158 | 0b100101, 159 | 0b010101, 160 | 0b111110, 161 | 0b010110, 162 | 0b110111, 163 | 0b111101, 164 | ], 165 | [ 166 | 0b101010, 167 | 0b011011, 168 | 0b001110, 169 | 0b000001, 170 | 0b000010, 171 | 0b001000, 172 | 0b001101, 173 | 0b101001, 174 | ], 175 | [ 176 | 0b000100, 177 | 0b100000, 178 | 0b110100, 179 | 0b101100, 180 | 0b111000, 181 | 0b010000, 182 | 0b110010, 183 | 0b011100, 184 | ], 185 | ], 186 | [ 187 | [ 188 | 0b110111, 189 | 0b010101, 190 | 0b110001, 191 | 0b010110, 192 | 0b100110, 193 | 0b111110, 194 | 0b100101, 195 | 0b111101, 196 | ], 197 | [ 198 | 0b001101, 199 | 0b000001, 200 | 0b101010, 201 | 0b001000, 202 | 0b011011, 203 | 0b000010, 204 | 0b001110, 205 | 0b101001, 206 | ], 207 | [ 208 | 0b110010, 209 | 0b101100, 210 | 0b000100, 211 | 0b010000, 212 | 0b100000, 213 | 0b111000, 214 | 0b110100, 215 | 0b011100, 216 | ], 217 | ], 218 | ] 219 | 220 | 221 | def _lfsr_gen(x: list[int]) -> None: 222 | """Generate the next bit of the 6-minute codes sequence""" 223 | x.append(x[-7] ^ x[-6] ^ x[-5] ^ x[-2]) 224 | 225 | 226 | _lfsr_seq = [1] * 7 227 | while len(_lfsr_seq) < 255: 228 | _lfsr_gen(_lfsr_seq) 229 | 230 | # Table 12 - Fixed 106-bit timing word 231 | _ftw = [ 232 | int(c) 233 | for c in "1101000111" 234 | "0101100101" 235 | "1001101110" 236 | "0011000010" 237 | "1101001110" 238 | "1001010100" 239 | "0010111000" 240 | "1011010110" 241 | "1101111111" 242 | "1000000100" 243 | "100100" 244 | ] 245 | 246 | 247 | def _get_dst_next(d: datetime.date, tz: datetime.tzinfo = Mountain) -> int: 248 | """Find the "dst next" value for the phase modulation signal""" 249 | dst_now = isdst(d, tz) # dst_on[1] 250 | dst_midwinter = isdst(datetime.datetime(d.year, 1, 1, tzinfo=datetime.timezone.utc), tz) 251 | dst_midsummer = isdst(datetime.datetime(d.year, 7, 1, tzinfo=datetime.timezone.utc), tz) 252 | 253 | if dst_midwinter and dst_midsummer: 254 | return 0b101111 255 | if not (dst_midwinter or dst_midsummer): 256 | return 0b000111 257 | 258 | # Southern hemisphere 259 | if dst_midwinter or not dst_midsummer: 260 | return 0b100011 261 | 262 | dst_change_date, dst_next_row = _get_dst_change_date_and_row(d, tz) 263 | if dst_change_date is None: 264 | return 0b100011 265 | assert dst_next_row is not None 266 | 267 | dst_change_hour = _get_dst_change_hour(dst_change_date, tz) 268 | if dst_change_hour is None: 269 | return 0b100011 270 | 271 | return _dsttable[dst_now][dst_change_hour][dst_next_row] 272 | 273 | 274 | _hamming_weight = [ 275 | [23, 21, 20, 17, 16, 15, 14, 13, 9, 8, 6, 5, 4, 2, 0], 276 | [24, 22, 21, 18, 17, 16, 15, 14, 10, 9, 7, 6, 5, 3, 1], 277 | [25, 23, 22, 19, 18, 17, 16, 15, 11, 10, 8, 7, 6, 4, 2], 278 | [24, 21, 19, 18, 15, 14, 13, 12, 11, 7, 6, 4, 3, 2, 0], 279 | [25, 22, 20, 19, 16, 15, 14, 13, 12, 8, 7, 5, 4, 3, 1], 280 | ] 281 | 282 | # Identifies the phase data as a time signal (SYNC_T bits present) 283 | # or a message signal (SYNC_M bits present); No message signals are defined 284 | # by NIST at this time. 285 | SYNC_T = 0x768 286 | SYNC_M = 0x1A3A 287 | 288 | 289 | def _extract_bit(v: int, p: int) -> bool: 290 | """Extract bit 'p' from integer 'v' as a bool""" 291 | return bool((v >> p) & 1) 292 | 293 | 294 | def _hamming_parity(value: int) -> int: 295 | """Compute the "hamming parity" of a 26-bit number, such as the minute-of-century 296 | 297 | For more details, see Enhanced WWVB Broadcast Format 4.3 298 | """ 299 | parity = 0 300 | for i in range(4, -1, -1): 301 | bit = 0 302 | for j in range(15): 303 | bit ^= _extract_bit(value, _hamming_weight[i][j]) 304 | parity = (parity << 1) | bit 305 | return parity 306 | 307 | 308 | _dst_ls_lut = [ 309 | 0b01000, 310 | 0b10101, 311 | 0b10110, 312 | 0b00011, 313 | 0b01000, 314 | 0b10101, 315 | 0b10110, 316 | 0b00011, 317 | 0b00100, 318 | 0b01110, 319 | 0b10000, 320 | 0b01101, 321 | 0b11001, 322 | 0b11100, 323 | 0b11010, 324 | 0b11111, 325 | ] 326 | 327 | 328 | @enum.unique 329 | class DstStatus(enum.IntEnum): 330 | """Constants that describe the DST status of a minute""" 331 | 332 | DST_NOT_IN_EFFECT = 0b00 333 | """DST not in effect today""" 334 | DST_STARTS_TODAY = 0b01 335 | """DST starts today at 0200 local standard time""" 336 | DST_ENDS_TODAY = 0b10 337 | """DST ends today at 0200 local standard time""" 338 | DST_IN_EFFECT = 0b11 339 | """DST in effect all day today""" 340 | 341 | 342 | class _WWVBMinute(NamedTuple): 343 | """(implementation detail)""" 344 | 345 | year: int 346 | """2-digit year within the WWVB epoch""" 347 | 348 | days: int 349 | """1-based day of year""" 350 | 351 | hour: int 352 | """UTC hour of day""" 353 | 354 | min: int 355 | """Minute of hour""" 356 | 357 | dst: DstStatus 358 | """2-bit DST code """ 359 | 360 | ut1: int 361 | """UT1 offset in units of 100ms, range -900 to +900ms""" 362 | 363 | ls: bool 364 | """Leap second warning flag""" 365 | 366 | ly: bool 367 | """Leap year flag""" 368 | 369 | 370 | class WWVBMinute(_WWVBMinute): 371 | """Uniquely identifies a minute of time in the WWVB system. 372 | 373 | To use ``ut1`` and ``ls`` information from IERS, create a `WWVBMinuteIERS` 374 | object instead. 375 | """ 376 | 377 | epoch: int = 1970 378 | 379 | def __new__( # noqa: PYI034 380 | cls, 381 | year: int, 382 | days: int, 383 | hour: int, 384 | minute: int, 385 | dst: DstStatus | int | None = None, 386 | ut1: int | None = None, 387 | ls: bool | None = None, 388 | ly: bool | None = None, 389 | ) -> WWVBMinute: 390 | """Construct a WWVBMinute 391 | 392 | :param year: The 2- or 4-digit year. This parameter is converted by the `full_year` method. 393 | :param days: 1-based day of year 394 | 395 | :param hour: UTC hour of day 396 | 397 | :param minute: Minute of hour 398 | :param dst: 2-bit DST code 399 | :param ut1: UT1 offset in units of 100ms, range -900 to +900ms 400 | :param ls: Leap second warning flag 401 | :param ly: Leap year flag 402 | """ 403 | dst = cls.get_dst(year, days) if dst is None else DstStatus(dst) 404 | if ut1 is None and ls is None: 405 | ut1, ls = cls._get_dut1_info(year, days) 406 | elif ut1 is None or ls is None: 407 | raise ValueError("sepecify both ut1 and ls or neither one") 408 | year = cls.full_year(year) 409 | if ly is None: 410 | ly = isly(year) 411 | return _WWVBMinute.__new__(cls, year, days, hour, minute, dst, ut1, ls, ly) 412 | 413 | @classmethod 414 | def full_year(cls, year: int) -> int: 415 | """Convert a (possibly two-digit) year to a full year. 416 | 417 | If the argument is above 100, it is assumed to be a full year. 418 | Otherwise, the intuitive method is followed: Say the epoch is 1970, 419 | then 70..99 means 1970..99 and 00..69 means 2000..2069. 420 | 421 | To actually use a different epoch, derive a class from WWVBMinute (or 422 | WWVBMinuteIERS) and give it a different epoch property. Then, create 423 | instances of that class instead of WWVBMinute. 424 | """ 425 | century = cls.epoch // 100 * 100 426 | if year < (cls.epoch % 100): 427 | return year + century + 100 428 | if year < 100: 429 | return year + century 430 | return year 431 | 432 | @staticmethod 433 | def get_dst(year: int, days: int) -> DstStatus: 434 | """Get the 2-bit WWVB DST value for the given day""" 435 | d0 = datetime.datetime(year, 1, 1, tzinfo=datetime.timezone.utc) + datetime.timedelta(days - 1) 436 | d1 = d0 + datetime.timedelta(1) 437 | dst0 = isdst(d0) 438 | dst1 = isdst(d1) 439 | return DstStatus(dst1 * 2 + dst0) 440 | 441 | def __str__(self) -> str: 442 | """Implement str()""" 443 | return ( 444 | f"year={self.year:4d} days={self.days:03d} hour={self.hour:02d} " 445 | f"min={self.min:02d} dst={self.dst} ut1={self.ut1} ly={int(self.ly)} " 446 | f"ls={int(self.ls)}" 447 | ) 448 | 449 | def as_datetime_utc(self) -> datetime.datetime: 450 | """Convert to a UTC datetime 451 | 452 | The returned object has ``tzinfo=datetime.timezone.utc``. 453 | """ 454 | d = datetime.datetime(self.year, 1, 1, tzinfo=datetime.timezone.utc) 455 | d += datetime.timedelta(self.days - 1, self.hour * 3600 + self.min * 60) 456 | return d 457 | 458 | as_datetime = as_datetime_utc 459 | 460 | def as_datetime_local( 461 | self, 462 | standard_time_offset: int = 7 * 3600, 463 | *, 464 | dst_observed: bool = True, 465 | ) -> datetime.datetime: 466 | """Convert to a local datetime according to the DST bits 467 | 468 | The returned object has ``tz=datetime.timezone(computed_offset)``. 469 | 470 | :param standard_time_offset: The UTC offset of local standard time, in seconds west of UTC. 471 | The default value, ``7 * 3600``, is for Colorado, the source of the WWVB broadcast. 472 | 473 | :param dst_observed: If ``True`` then the locale observes DST, and a 474 | one hour offset is applied according to WWVB rules. If ``False``, then 475 | the standard time offset is used at all times. 476 | 477 | """ 478 | u = self.as_datetime_utc() 479 | offset = datetime.timedelta(seconds=-standard_time_offset) 480 | d = u - datetime.timedelta(seconds=standard_time_offset) 481 | if not dst_observed: 482 | dst = False 483 | elif self.dst == 0b10: 484 | transition_time = u.replace(hour=2) 485 | dst = d >= transition_time 486 | elif self.dst == 0b11: 487 | dst = True 488 | elif self.dst == 0b01: 489 | transition_time = u.replace(hour=1) 490 | dst = d < transition_time 491 | else: # self.dst == 0b00 492 | dst = False 493 | if dst: 494 | offset += datetime.timedelta(seconds=3600) 495 | return u.astimezone(datetime.timezone(offset)) 496 | 497 | def _is_end_of_month(self) -> bool: 498 | """Return True if minute is the last minute in a month""" 499 | d = self.as_datetime() 500 | e = d + datetime.timedelta(1) 501 | return d.month != e.month 502 | 503 | def minute_length(self) -> int: 504 | """Return the length of the minute, 60, 61, or (theoretically) 59 seconds""" 505 | if not self.ls: 506 | return 60 507 | if not self._is_end_of_month(): 508 | return 60 509 | if self.hour != 23 or self.min != 59: 510 | return 60 511 | if self.ut1 > 0: 512 | return 59 513 | return 61 514 | 515 | def as_timecode(self) -> WWVBTimecode: 516 | """Fill a WWVBTimecode structure representing this minute. Fills both the amplitude and phase codes.""" 517 | t = WWVBTimecode(self.minute_length()) 518 | 519 | self._fill_am_timecode(t) 520 | self._fill_pm_timecode(t) 521 | 522 | return t 523 | 524 | @property 525 | def _leap_sec(self) -> int: 526 | """Return the 2-bit _leap_sec value used by the PM code""" 527 | if not self.ls: 528 | return 0 529 | if self.ut1 < 0: 530 | return 3 531 | return 2 532 | 533 | @property 534 | def minute_of_century(self) -> int: 535 | """Return the minute of the century""" 536 | century = (self.year // 100) * 100 537 | # note: This relies on timedelta seconds never including leapseconds! 538 | return ( 539 | int((self.as_datetime() - datetime.datetime(century, 1, 1, tzinfo=datetime.timezone.utc)).total_seconds()) 540 | // 60 541 | ) 542 | 543 | def _fill_am_timecode(self, t: WWVBTimecode) -> None: 544 | """Fill the amplitude (AM) portion of a timecode object""" 545 | for i in [0, 9, 19, 29, 39, 49]: 546 | t.am[i] = AmplitudeModulation.MARK 547 | if len(t.am) > 59: 548 | t.am[59] = AmplitudeModulation.MARK 549 | if len(t.am) > 60: 550 | t.am[60] = AmplitudeModulation.MARK 551 | for i in [4, 10, 11, 14, 20, 21, 24, 34, 35, 44, 54]: 552 | t.am[i] = AmplitudeModulation.ZERO 553 | t._put_am_bcd(self.min, 1, 2, 3, 5, 6, 7, 8) 554 | t._put_am_bcd(self.hour, 12, 13, 15, 16, 17, 18) 555 | t._put_am_bcd(self.days, 22, 23, 25, 26, 27, 28, 30, 31, 32, 33) 556 | ut1_sign = self.ut1 >= 0 557 | t.am[36] = t.am[38] = AmplitudeModulation(ut1_sign) 558 | t.am[37] = AmplitudeModulation(not ut1_sign) 559 | t._put_am_bcd(abs(self.ut1) // 100, 40, 41, 42, 43) 560 | t._put_am_bcd(self.year, 45, 46, 47, 48, 50, 51, 52, 53) # Implicitly discards all but lowest 2 digits of year 561 | t.am[55] = AmplitudeModulation(self.ly) 562 | t.am[56] = AmplitudeModulation(self.ls) 563 | t._put_am_bcd(self.dst, 57, 58) 564 | 565 | def _fill_pm_timecode_extended(self, t: WWVBTimecode) -> None: 566 | """During minutes 10..15 and 40..45, the amplitude signal holds 'extended information'""" 567 | assert 10 <= self.min < 16 or 40 <= self.min < 46 568 | minno = self.min % 10 569 | assert minno < 6 570 | 571 | dst = self.dst 572 | # Note that these are 1 different than Table 11 573 | # because our LFSR sequence is zero-based 574 | seqno = (self.min // 30) * 2 575 | if dst == 0: 576 | pass 577 | elif dst == 3: 578 | seqno = seqno + 1 579 | elif dst == 2: 580 | if self.hour < 4: 581 | pass 582 | elif self.hour < 11: 583 | seqno = seqno + 90 584 | else: 585 | seqno = seqno + 1 586 | elif self.hour < 4: 587 | seqno = seqno + 1 588 | elif self.hour < 11: 589 | seqno = seqno + 91 590 | 591 | info_seq = _lfsr_seq[seqno : seqno + 127] 592 | full_seq = info_seq + _ftw + info_seq[::-1] 593 | assert len(full_seq) == 360 594 | 595 | offset = minno * 60 596 | for i in range(60): 597 | t._put_pm_bit(i, full_seq[i + offset]) 598 | 599 | def _fill_pm_timecode_regular(self, t: WWVBTimecode) -> None: # noqa: PLR0915 600 | """Except during minutes 10..15 and 40..45, the amplitude signal holds 'regular information'""" 601 | t._put_pm_bin(0, 13, SYNC_T) 602 | 603 | moc = self.minute_of_century 604 | _leap_sec = self._leap_sec 605 | dst_on = self.dst 606 | dst_ls = _dst_ls_lut[dst_on | (_leap_sec << 2)] 607 | dst_next = _get_dst_next(self.as_datetime()) 608 | t._put_pm_bin(13, 5, _hamming_parity(moc)) 609 | t._put_pm_bit(18, _extract_bit(moc, 25)) 610 | t._put_pm_bit(19, _extract_bit(moc, 0)) 611 | t._put_pm_bit(20, _extract_bit(moc, 24)) 612 | t._put_pm_bit(21, _extract_bit(moc, 23)) 613 | t._put_pm_bit(22, _extract_bit(moc, 22)) 614 | t._put_pm_bit(23, _extract_bit(moc, 21)) 615 | t._put_pm_bit(24, _extract_bit(moc, 20)) 616 | t._put_pm_bit(25, _extract_bit(moc, 19)) 617 | t._put_pm_bit(26, _extract_bit(moc, 18)) 618 | t._put_pm_bit(27, _extract_bit(moc, 17)) 619 | t._put_pm_bit(28, _extract_bit(moc, 16)) 620 | t._put_pm_bit(29, False) # noqa: FBT003 # Reserved 621 | t._put_pm_bit(30, _extract_bit(moc, 15)) 622 | t._put_pm_bit(31, _extract_bit(moc, 14)) 623 | t._put_pm_bit(32, _extract_bit(moc, 13)) 624 | t._put_pm_bit(33, _extract_bit(moc, 12)) 625 | t._put_pm_bit(34, _extract_bit(moc, 11)) 626 | t._put_pm_bit(35, _extract_bit(moc, 10)) 627 | t._put_pm_bit(36, _extract_bit(moc, 9)) 628 | t._put_pm_bit(37, _extract_bit(moc, 8)) 629 | t._put_pm_bit(38, _extract_bit(moc, 7)) 630 | t._put_pm_bit(39, True) # noqa: FBT003 # Reserved 631 | t._put_pm_bit(40, _extract_bit(moc, 6)) 632 | t._put_pm_bit(41, _extract_bit(moc, 5)) 633 | t._put_pm_bit(42, _extract_bit(moc, 4)) 634 | t._put_pm_bit(43, _extract_bit(moc, 3)) 635 | t._put_pm_bit(44, _extract_bit(moc, 2)) 636 | t._put_pm_bit(45, _extract_bit(moc, 1)) 637 | t._put_pm_bit(46, _extract_bit(moc, 0)) 638 | t._put_pm_bit(47, _extract_bit(dst_ls, 4)) 639 | t._put_pm_bit(48, _extract_bit(dst_ls, 3)) 640 | t._put_pm_bit(49, True) # noqa: FBT003 # Notice 641 | t._put_pm_bit(50, _extract_bit(dst_ls, 2)) 642 | t._put_pm_bit(51, _extract_bit(dst_ls, 1)) 643 | t._put_pm_bit(52, _extract_bit(dst_ls, 0)) 644 | t._put_pm_bit(53, _extract_bit(dst_next, 5)) 645 | t._put_pm_bit(54, _extract_bit(dst_next, 4)) 646 | t._put_pm_bit(55, _extract_bit(dst_next, 3)) 647 | t._put_pm_bit(56, _extract_bit(dst_next, 2)) 648 | t._put_pm_bit(57, _extract_bit(dst_next, 1)) 649 | t._put_pm_bit(58, _extract_bit(dst_next, 0)) 650 | if len(t.phase) > 59: 651 | t._put_pm_bit(59, PhaseModulation.ZERO) 652 | if len(t.phase) > 60: 653 | t._put_pm_bit(60, PhaseModulation.ZERO) 654 | 655 | def _fill_pm_timecode(self, t: WWVBTimecode) -> None: 656 | """Fill the phase portion of a timecode object""" 657 | if 10 <= self.min < 16 or 40 <= self.min < 46: 658 | self._fill_pm_timecode_extended(t) 659 | else: 660 | self._fill_pm_timecode_regular(t) 661 | 662 | def next_minute(self, newut1: int | None = None, newls: bool | None = None) -> WWVBMinute: 663 | """Return an object representing the next minute""" 664 | d = self.as_datetime() + datetime.timedelta(minutes=1) 665 | return self.from_datetime(d, newut1, newls, self) 666 | 667 | def previous_minute(self, newut1: int | None = None, newls: bool | None = None) -> WWVBMinute: 668 | """Return an object representing the previous minute""" 669 | d = self.as_datetime() - datetime.timedelta(minutes=1) 670 | return self.from_datetime(d, newut1, newls, self) 671 | 672 | @classmethod 673 | def _get_dut1_info(cls: type, year: int, days: int, old_time: WWVBMinute | None = None) -> tuple[int, bool]: # noqa: ARG003 674 | """Return the DUT1 information for a given day, possibly propagating information from a previous timestamp""" 675 | if old_time is not None: 676 | if old_time.minute_length() != 60: 677 | newls = False 678 | newut1 = old_time.ut1 + 1000 if old_time.ut1 < 0 else old_time.ut1 - 1000 679 | else: 680 | newls = old_time.ls 681 | newut1 = old_time.ut1 682 | return newut1, newls 683 | return 0, False 684 | 685 | @classmethod 686 | def fromstring(cls, s: str) -> WWVBMinute: 687 | """Construct a WWVBMinute from a string representation created by print_timecodes""" 688 | s = _removeprefix(s, "WWVB timecode: ") 689 | d: dict[str, int] = {} 690 | for part in s.split(): 691 | k, v = part.split("=") 692 | if k == "min": 693 | k = "minute" 694 | d[k] = int(v) 695 | year = d.pop("year") 696 | days = d.pop("days") 697 | hour = d.pop("hour") 698 | minute = d.pop("minute") 699 | dst: int | None = d.pop("dst", None) 700 | ut1: int | None = d.pop("ut1", None) 701 | ls = d.pop("ls", None) 702 | d.pop("ly", None) 703 | if d: 704 | raise ValueError(f"Invalid options: {d}") 705 | return cls(year, days, hour, minute, dst, ut1, None if ls is None else bool(ls)) 706 | 707 | @classmethod 708 | def from_datetime( 709 | cls, 710 | d: datetime.datetime, 711 | newut1: int | None = None, 712 | newls: bool | None = None, 713 | old_time: WWVBMinute | None = None, 714 | ) -> WWVBMinute: 715 | """Construct a WWVBMinute from a datetime, possibly specifying ut1/ls data or propagating it from an old time""" 716 | u = d.utctimetuple() 717 | if newls is None and newut1 is None: 718 | newut1, newls = cls._get_dut1_info(u.tm_year, u.tm_yday, old_time) 719 | return cls(u.tm_year, u.tm_yday, u.tm_hour, u.tm_min, ut1=newut1, ls=newls) 720 | 721 | @classmethod 722 | def from_timecode_am(cls, t: WWVBTimecode) -> WWVBMinute | None: # noqa: PLR0912 723 | """Construct a WWVBMinute from a WWVBTimecode""" 724 | for i in (0, 9, 19, 29, 39, 49, 59): 725 | if t.am[i] != AmplitudeModulation.MARK: 726 | return None 727 | for i in (4, 10, 11, 14, 20, 21, 24, 34, 35, 44, 54): 728 | if t.am[i] != AmplitudeModulation.ZERO: 729 | return None 730 | if t.am[36] == t.am[37]: 731 | return None 732 | if t.am[36] != t.am[38]: 733 | return None 734 | minute = t._get_am_bcd(1, 2, 3, 5, 6, 7, 8) 735 | if minute is None: 736 | return None 737 | if minute >= 60: 738 | return None 739 | hour = t._get_am_bcd(12, 13, 15, 16, 17, 18) 740 | if hour is None: 741 | return None 742 | if hour >= 24: 743 | return None 744 | days = t._get_am_bcd(22, 23, 25, 26, 27, 28, 30, 31, 32, 33) 745 | if days is None: 746 | return None 747 | abs_ut1 = t._get_am_bcd(40, 41, 42, 43) 748 | if abs_ut1 is None: 749 | return None 750 | abs_ut1 *= 100 751 | ut1_sign = t.am[38] 752 | ut1 = abs_ut1 if ut1_sign else -abs_ut1 753 | year = t._get_am_bcd(45, 46, 47, 48, 50, 51, 52, 53) 754 | if year is None: 755 | return None 756 | ly = bool(t.am[55]) 757 | if days > 366 or (not ly and days > 365): 758 | return None 759 | ls = bool(t.am[56]) 760 | dst = t._get_am_bcd(57, 58) 761 | if dst is None: 762 | return None 763 | return cls(year, days, hour, minute, dst, ut1, ls, ly) 764 | 765 | 766 | class WWVBMinuteIERS(WWVBMinute): 767 | """A WWVBMinute that uses a database of DUT1 information""" 768 | 769 | @classmethod 770 | def _get_dut1_info(cls, year: int, days: int, old_time: WWVBMinute | None = None) -> tuple[int, bool]: # noqa: ARG003 771 | d = datetime.datetime(year, 1, 1, tzinfo=datetime.timezone.utc) + datetime.timedelta(days - 1) 772 | return round(get_dut1(d) * 10) * 100, isls(d) 773 | 774 | 775 | def _bcd_bits(n: int) -> Generator[bool]: 776 | """Return the bcd representation of n, starting with the least significant bit""" 777 | while True: 778 | d = n % 10 779 | n = n // 10 780 | for i in (1, 2, 4, 8): 781 | yield bool(d & i) 782 | 783 | 784 | @enum.unique 785 | class AmplitudeModulation(enum.IntEnum): 786 | """Constants that describe an Amplitude Modulation value""" 787 | 788 | ZERO = 0 789 | """A zero bit (reduced carrier during the first 200ms of the second)""" 790 | ONE = 1 791 | """A one bit (reduced carrier during the first 500ms of the second)""" 792 | MARK = 2 793 | """A mark bit (reduced carrier during the first 800ms of the second)""" 794 | UNSET = -1 795 | """An unset or unknown amplitude modulation value""" 796 | 797 | 798 | @enum.unique 799 | class PhaseModulation(enum.IntEnum): 800 | """Constants that describe a Phase Modulation value""" 801 | 802 | ZERO = 0 803 | """A one bit (180° phase shift during the second)""" 804 | ONE = 1 805 | """A zero bit (No phase shift during the second)""" 806 | UNSET = -1 807 | """An unset or unknown phase modulation value""" 808 | 809 | 810 | class WWVBTimecode: 811 | """Represent the amplitude and/or phase signal, usually over 1 minute""" 812 | 813 | am: list[AmplitudeModulation] 814 | """The amplitude modulation data""" 815 | 816 | phase: list[PhaseModulation] 817 | """The phase modulation data""" 818 | 819 | def __init__(self, sz: int) -> None: 820 | """Construct a WWVB timecode ``sz`` seconds long""" 821 | self.am = [AmplitudeModulation.UNSET] * sz 822 | self.phase = [PhaseModulation.UNSET] * sz 823 | 824 | def _get_am_bcd(self, *poslist: int) -> int | None: 825 | """Convert AM data to BCD 826 | 827 | The the bits ``self.am[poslist[i]]`` in MSB order are converted from 828 | BCD to integer 829 | """ 830 | pos = list(poslist)[::-1] 831 | for p in pos: 832 | if self.am[p] not in {AmplitudeModulation.ZERO, AmplitudeModulation.ONE}: 833 | return None 834 | val = [bool(self.am[p]) for p in pos] 835 | result = 0 836 | base = 1 837 | for i in range(0, len(val), 4): 838 | digit = 0 839 | for j, b in enumerate(val[i : i + 4]): 840 | digit += b << j 841 | if digit > 9: 842 | return None 843 | result += digit * base 844 | base *= 10 845 | return result 846 | 847 | def _put_am_bcd(self, v: int, *poslist: int) -> None: 848 | """Insert BCD coded data into the AM signal 849 | 850 | The bits at ``self.am[poslist[i]]`` in MSB order are filled with 851 | the conversion of `v` to BCD 852 | Treating 'poslist' as a sequence of indices, update the AM signal with the value as a BCD number 853 | """ 854 | pos = list(poslist)[::-1] 855 | for p, b in zip(pos, _bcd_bits(v)): 856 | if b: 857 | self.am[p] = AmplitudeModulation.ONE 858 | else: 859 | self.am[p] = AmplitudeModulation.ZERO 860 | 861 | def _put_pm_bit(self, i: int, v: PhaseModulation | int | bool) -> None: 862 | """Update a bit of the Phase Modulation signal""" 863 | self.phase[i] = PhaseModulation(v) 864 | 865 | def _put_pm_bin(self, st: int, n: int, v: int) -> None: 866 | """Update an n-digit binary number in the Phase Modulation signal""" 867 | for i in range(n): 868 | self._put_pm_bit(st + i, _extract_bit(v, (n - i - 1))) 869 | 870 | def __str__(self) -> str: 871 | """Implement str()""" 872 | undefined = [i for i in range(len(self.am)) if self.am[i] == AmplitudeModulation.UNSET] 873 | if undefined: 874 | warnings.warn(f"am{undefined} is unset", stacklevel=1) 875 | 876 | def convert_one(am: AmplitudeModulation, phase: PhaseModulation) -> str: 877 | if phase is PhaseModulation.UNSET: 878 | return ("0", "1", "2", "?")[am] 879 | if phase: 880 | return ("⁰", "¹", "²", "¿")[am] 881 | return ("₀", "₁", "₂", "⸮")[am] 882 | 883 | return "".join(convert_one(i, j) for i, j in zip(self.am, self.phase)) 884 | 885 | def __repr__(self) -> str: 886 | """Implement repr()""" 887 | return "" 888 | 889 | def to_am_string(self, charset: list[str]) -> str: 890 | """Convert the amplitude signal to a string""" 891 | return "".join(charset[i] for i in self.am) 892 | 893 | to_string = to_am_string 894 | 895 | def to_pm_string(self, charset: list[str]) -> str: 896 | """Convert the phase signal to a string""" 897 | return "".join(charset[i] for i in self.phase) 898 | 899 | def to_both_string(self, charset: list[str]) -> str: 900 | """Convert both channels to a string""" 901 | return "".join(charset[i + j * 3] for i, j in zip(self.am, self.phase)) 902 | 903 | 904 | styles = { 905 | "default": ["0", "1", "2"], 906 | "duration": ["2", "5", "8"], 907 | "cradek": ["0", "1", "-"], 908 | "bar": ["🬍🬎", "🬋🬎", "🬋🬍"], 909 | "sextant": ["🬍🬎", "🬋🬎", "🬋🬍", "🬩🬹", "🬋🬹", "🬋🬩"], 910 | } 911 | 912 | 913 | def print_timecodes( 914 | w: WWVBMinute, 915 | minutes: int, 916 | channel: str, 917 | style: str, 918 | file: TextIO, 919 | *, 920 | all_timecodes: bool = False, 921 | ) -> None: 922 | """Print a range of timecodes with a header. This header is in a format understood by WWVBMinute.fromstring""" 923 | channel_text = "" if channel == "amplitude" else f" --channel={channel}" 924 | style_text = "" if style == "default" else f" --style={style}" 925 | style_chars = styles.get(style, ["0", "1", "2"]) 926 | first = True 927 | for _ in range(minutes): 928 | if not first and channel == "both": 929 | print(file=file) 930 | if first or all_timecodes: 931 | if not first: 932 | print(file=file) 933 | print(f"WWVB timecode: {w!s}{channel_text}{style_text}", file=file) 934 | first = False 935 | pfx = f"{w.year:04d}-{w.days:03d} {w.hour:02d}:{w.min:02d} " 936 | tc = w.as_timecode() 937 | if len(style_chars) == 6: 938 | print(f"{pfx} {tc.to_both_string(style_chars)}", file=file) 939 | print(file=file) 940 | pfx = " " * len(pfx) 941 | else: 942 | if channel in ("amplitude", "both"): 943 | print(f"{pfx} {tc.to_am_string(style_chars)}", file=file) 944 | pfx = " " * len(pfx) 945 | if channel in ("phase", "both"): 946 | print(f"{pfx} {tc.to_pm_string(style_chars)}", file=file) 947 | w = w.next_minute() 948 | 949 | 950 | def print_timecodes_json( 951 | w: WWVBMinute, 952 | minutes: int, 953 | channel: str, 954 | file: TextIO, 955 | ) -> None: 956 | """Print a range of timecodes in JSON format. 957 | 958 | The result is a json array of minute data. Each minute data is an object with the following members: 959 | 960 | * year (int) 961 | * days (int) 962 | * hour (int) 963 | * minute (int) 964 | * amplitude (string; only if channel is amplitude or both) 965 | * phase: (string; only if channel is phase or both) 966 | 967 | The amplitude and phase strings are of length 60 during most minutes, length 61 968 | during a minute that includes a (positive) leap second, and theoretically 969 | length 59 in the case of a negative leap second. 970 | """ 971 | result = [] 972 | for _ in range(minutes): 973 | data: dict[str, Any] = { 974 | "year": w.year, 975 | "days": w.days, 976 | "hour": w.hour, 977 | "minute": w.min, 978 | } 979 | 980 | tc = w.as_timecode() 981 | if channel in ("amplitude", "both"): 982 | data["amplitude"] = tc.to_am_string(["0", "1", "2"]) 983 | if channel in ("phase", "both"): 984 | data["phase"] = tc.to_pm_string(["0", "1"]) 985 | 986 | result.append(data) 987 | w = w.next_minute() 988 | json.dump(result, file) 989 | print(file=file) 990 | -------------------------------------------------------------------------------- /src/wwvb/decode.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Jeff Epler 2 | # 3 | # SPDX-License-Identifier: GPL-3.0-only 4 | """A stateful decoder of WWVB signals""" 5 | 6 | from __future__ import annotations 7 | 8 | import sys 9 | from typing import TYPE_CHECKING 10 | 11 | import wwvb 12 | 13 | if TYPE_CHECKING: 14 | from collections.abc import Generator 15 | 16 | # State 1: Unsync'd 17 | # Marker: State 2 18 | # Other: State 1 19 | # State 2: One marker 20 | # Marker: State 3 21 | # Other: State 1 22 | # State 3: Two markers 23 | # Marker: State 3 24 | # Other: State 4 25 | # State 4: Decoding a minute, starting in second 1 26 | # Second 27 | 28 | always_zero = {4, 10, 11, 14, 20, 21, 34, 35, 44, 54} 29 | 30 | 31 | def wwvbreceive() -> Generator[wwvb.WWVBTimecode | None, wwvb.AmplitudeModulation, None]: 32 | """Decode WWVB signals statefully.""" 33 | minute: list[wwvb.AmplitudeModulation] = [] 34 | state = 1 35 | 36 | value = yield None 37 | while True: 38 | # print(state, value, len(minute), "".join(str(int(i)) for i in minute)) 39 | if state == 1: 40 | minute = [] 41 | if value == wwvb.AmplitudeModulation.MARK: 42 | state = 2 43 | value = yield None 44 | 45 | elif state == 2: 46 | state = 3 if value == wwvb.AmplitudeModulation.MARK else 1 47 | value = yield None 48 | 49 | elif state == 3: 50 | if value != wwvb.AmplitudeModulation.MARK: 51 | state = 4 52 | minute = [wwvb.AmplitudeModulation.MARK, value] 53 | value = yield None 54 | 55 | else: # state == 4: 56 | minute.append(value) 57 | if len(minute) % 10 == 0 and value != wwvb.AmplitudeModulation.MARK: 58 | # print("MISSING MARK", len(minute), "".join(str(int(i)) for i in minute)) 59 | state = 1 60 | elif len(minute) % 10 and value == wwvb.AmplitudeModulation.MARK: 61 | # print("UNEXPECTED MARK") 62 | state = 1 63 | elif len(minute) - 1 in always_zero and value != wwvb.AmplitudeModulation.ZERO: 64 | # print("UNEXPECTED NONZERO") 65 | state = 1 66 | elif len(minute) == 60: 67 | # print("FULL MINUTE") 68 | tc = wwvb.WWVBTimecode(60) 69 | tc.am[:] = minute 70 | minute = [] 71 | state = 2 72 | value = yield tc 73 | else: 74 | value = yield None 75 | 76 | 77 | def main() -> None: 78 | """Read symbols on stdin and print any successfully-decoded minutes""" 79 | decoder = wwvbreceive() 80 | next(decoder) 81 | decoder.send(wwvb.AmplitudeModulation.MARK) 82 | for s in sys.argv[1:]: 83 | for c in s: 84 | decoded = decoder.send(wwvb.AmplitudeModulation(int(c))) 85 | if decoded: 86 | print(decoded) 87 | w = wwvb.WWVBMinute.from_timecode_am(decoded) 88 | if w: 89 | print(w) 90 | 91 | 92 | if __name__ == "__main__": 93 | main() 94 | -------------------------------------------------------------------------------- /src/wwvb/dut1table.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # SPDX-FileCopyrightText: 2021-2024 Jeff Epler 4 | # 5 | # SPDX-License-Identifier: GPL-3.0-only 6 | 7 | """Print the table of historical DUT1 values""" 8 | 9 | from datetime import timedelta 10 | from itertools import groupby 11 | 12 | import wwvb 13 | 14 | from .iersdata import DUT1_DATA_START, DUT1_OFFSETS 15 | 16 | 17 | def main() -> None: 18 | """Print the table of historical DUT1 values""" 19 | date = DUT1_DATA_START 20 | for key, it in groupby(DUT1_OFFSETS): 21 | dut1_ms = (ord(key) - ord("k")) / 10.0 22 | count = len(list(it)) 23 | end = date + timedelta(days=count - 1) 24 | dut1_next = wwvb.get_dut1(date + timedelta(days=count), warn_outdated=False) 25 | ls = f" LS on {end:%F} 23:59:60 UTC" if dut1_ms * dut1_next < 0 else "" 26 | print(f"{date:%F} {dut1_ms: 3.1f} {count:4d}{ls}") 27 | date += timedelta(days=count) 28 | print(date) 29 | 30 | 31 | if __name__ == "__main__": 32 | main() 33 | -------------------------------------------------------------------------------- /src/wwvb/gen.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """A command-line program for generating wwvb timecodes""" 3 | 4 | # SPDX-FileCopyrightText: 2011-2024 Jeff Epler 5 | # 6 | # SPDX-License-Identifier: GPL-3.0-only 7 | 8 | from __future__ import annotations 9 | 10 | import datetime 11 | import sys 12 | from typing import Any 13 | 14 | import click 15 | import dateutil.parser 16 | 17 | from . import WWVBMinute, WWVBMinuteIERS, print_timecodes, print_timecodes_json, styles 18 | 19 | 20 | def parse_timespec(ctx: Any, param: Any, value: list[str]) -> datetime.datetime: # noqa: ARG001 21 | """Parse a time specifier from the commandline""" 22 | try: 23 | if len(value) == 5: 24 | year, month, day, hour, minute = map(int, value) 25 | return datetime.datetime(year, month, day, hour, minute, tzinfo=datetime.timezone.utc) 26 | if len(value) == 4: 27 | year, yday, hour, minute = map(int, value) 28 | return datetime.datetime(year, 1, 1, hour, minute, tzinfo=datetime.timezone.utc) + datetime.timedelta( 29 | days=yday - 1, 30 | ) 31 | if len(value) == 1: 32 | return dateutil.parser.parse(value[0]) 33 | if len(value) == 0: 34 | return datetime.datetime.now(datetime.timezone.utc) 35 | raise ValueError("Unexpected number of arguments") 36 | except ValueError as e: 37 | raise click.UsageError(f"Could not parse timespec: {e}") from e 38 | 39 | 40 | @click.command() 41 | @click.option( 42 | "--iers/--no-iers", 43 | "-i/-I", 44 | default=True, 45 | help="Whether to use IESR data for DUT1 and LS. (Default: --iers)", 46 | ) 47 | @click.option( 48 | "--leap-second", 49 | "-s", 50 | "leap_second", 51 | flag_value=1, 52 | default=None, 53 | help="Force a positive leap second at the end of the GMT month (Implies --no-iers)", 54 | ) 55 | @click.option( 56 | "--negative-leap-second", 57 | "-n", 58 | "leap_second", 59 | flag_value=-1, 60 | help="Force a negative leap second at the end of the GMT month (Implies --no-iers)", 61 | ) 62 | @click.option( 63 | "--no-leap-second", 64 | "-S", 65 | "leap_second", 66 | flag_value=0, 67 | help="Force no leap second at the end of the month (Implies --no-iers)", 68 | ) 69 | @click.option("--dut1", "-d", type=int, help="Force the DUT1 value (Implies --no-iers)") 70 | @click.option("--minutes", "-m", default=10, help="Number of minutes to show (default: 10)") 71 | @click.option( 72 | "--style", 73 | default="default", 74 | type=click.Choice(sorted(["json", *list(styles.keys())])), 75 | help="Style of output", 76 | ) 77 | @click.option( 78 | "--all-timecodes/--no-all-timecodes", 79 | "-t/-T", 80 | default=False, 81 | type=bool, 82 | help="Show the 'WWVB timecode' line before each minute", 83 | ) 84 | @click.option( 85 | "--channel", 86 | type=click.Choice(["amplitude", "phase", "both"]), 87 | default="amplitude", 88 | help="Modulation to show (default: amplitude)", 89 | ) 90 | @click.argument("timespec", type=str, nargs=-1, callback=parse_timespec) 91 | def main( 92 | *, 93 | iers: bool, 94 | leap_second: bool, 95 | dut1: int, 96 | minutes: int, 97 | style: str, 98 | channel: str, 99 | all_timecodes: bool, 100 | timespec: datetime.datetime, 101 | ) -> None: 102 | """Generate WWVB timecodes 103 | 104 | TIMESPEC: one of "year yday hour minute" or "year month day hour minute", or else the current minute 105 | """ 106 | if (leap_second is not None) or (dut1 is not None): 107 | iers = False 108 | 109 | newut1 = None 110 | newls = None 111 | 112 | if iers: 113 | constructor: type[WWVBMinute] = WWVBMinuteIERS 114 | else: 115 | constructor = WWVBMinute 116 | newut1 = -500 * (leap_second or 0) if dut1 is None else dut1 117 | newls = bool(leap_second) 118 | 119 | w = constructor.from_datetime(timespec, newls=newls, newut1=newut1) 120 | if style == "json": 121 | print_timecodes_json(w, minutes, channel, file=sys.stdout) 122 | else: 123 | print_timecodes(w, minutes, channel, style, all_timecodes=all_timecodes, file=sys.stdout) 124 | 125 | 126 | if __name__ == "__main__": 127 | main() 128 | -------------------------------------------------------------------------------- /src/wwvb/iersdata.json: -------------------------------------------------------------------------------- 1 | {"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="} -------------------------------------------------------------------------------- /src/wwvb/iersdata.json.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: Public domain 2 | SPDX-License-Identifier: CC0-1.0 3 | -------------------------------------------------------------------------------- /src/wwvb/iersdata.py: -------------------------------------------------------------------------------- 1 | # -*- python3 -*- 2 | """Retrieve iers data, possibly from user or site data or from the wwvbpy distribution""" 3 | 4 | # SPDX-FileCopyrightText: 2011-2024 Jeff Epler 5 | # 6 | # SPDX-License-Identifier: GPL-3.0-only 7 | 8 | import binascii 9 | import datetime 10 | import gzip 11 | import importlib.resources 12 | import json 13 | 14 | import platformdirs 15 | 16 | __all__ = ["DUT1_DATA_START", "DUT1_OFFSETS", "end", "span", "start"] 17 | 18 | content: dict[str, str] = {"START": "1970-01-01", "OFFSETS_GZ": "H4sIAFNx1mYC/wMAAAAAAAAAAAA="} 19 | 20 | path = importlib.resources.files("wwvb") / "iersdata.json" 21 | content = json.loads(path.read_text(encoding="utf-8")) 22 | 23 | for location in [ # pragma no cover 24 | platformdirs.user_data_path("wwvbpy", "unpythonic.net"), 25 | platformdirs.site_data_path("wwvbpy", "unpythonic.net"), 26 | ]: 27 | path = location / "iersdata.json" 28 | if path.exists(): 29 | content = json.loads(path.read_text(encoding="utf-8")) 30 | break 31 | 32 | DUT1_DATA_START = datetime.date.fromisoformat(content["START"]) 33 | DUT1_OFFSETS = gzip.decompress(binascii.a2b_base64(content["OFFSETS_GZ"])).decode("ascii") 34 | 35 | start = datetime.datetime.combine(DUT1_DATA_START, datetime.time(), tzinfo=datetime.timezone.utc) 36 | span = datetime.timedelta(days=len(DUT1_OFFSETS)) 37 | end = start + span 38 | -------------------------------------------------------------------------------- /src/wwvb/py.typed: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jepler/wwvbpy/e7abe548210a74ef2117c6ea64b033ef67e72223/src/wwvb/py.typed -------------------------------------------------------------------------------- /src/wwvb/tz.py: -------------------------------------------------------------------------------- 1 | # -*- python -*- 2 | """A library for WWVB timecodes""" 3 | 4 | # SPDX-FileCopyrightText: 2021-2024 Jeff Epler 5 | # 6 | # SPDX-License-Identifier: GPL-3.0-only 7 | 8 | from zoneinfo import ZoneInfo 9 | 10 | Mountain = ZoneInfo("America/Denver") 11 | 12 | __all__ = ["Mountain", "ZoneInfo"] 13 | -------------------------------------------------------------------------------- /src/wwvb/updateiers.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | # SPDX-FileCopyrightText: 2021-2024 Jeff Epler 4 | # 5 | # SPDX-License-Identifier: GPL-3.0-only 6 | 7 | """Update the DUT1 and LS data based on online sources""" 8 | 9 | from __future__ import annotations 10 | 11 | import binascii 12 | import csv 13 | import datetime 14 | import gzip 15 | import io 16 | import json 17 | import pathlib 18 | from typing import Callable 19 | 20 | import bs4 21 | import click 22 | import platformdirs 23 | import requests 24 | 25 | DIST_PATH = pathlib.Path(__file__).parent / "iersdata.json" 26 | 27 | IERS_URL = "https://datacenter.iers.org/data/csv/finals2000A.all.csv" 28 | IERS_PATH = pathlib.Path("finals2000A.all.csv") 29 | if IERS_PATH.exists(): 30 | IERS_URL = str(IERS_PATH) 31 | print("using local", IERS_URL) 32 | NIST_URL = "https://www.nist.gov/pml/time-and-frequency-division/atomic-standards/leap-second-and-ut1-utc-information" 33 | 34 | 35 | def _get_text(url: str) -> str: 36 | """Get a local file or a http/https URL""" 37 | if url.startswith("http"): 38 | with requests.get(url, timeout=30) as response: 39 | return response.text 40 | else: 41 | return pathlib.Path(url).read_text(encoding="utf-8") 42 | 43 | 44 | def update_iersdata( # noqa: PLR0915 45 | target_path: pathlib.Path, 46 | ) -> None: 47 | """Update iersdata.py""" 48 | offsets: list[int] = [] 49 | iersdata_text = _get_text(IERS_URL) 50 | for r in csv.DictReader(io.StringIO(iersdata_text), delimiter=";"): 51 | jd = float(r["MJD"]) 52 | offs_str = r["UT1-UTC"] 53 | if not offs_str: 54 | break 55 | offs = round(float(offs_str) * 10) 56 | if not offsets: 57 | table_start = datetime.date(1858, 11, 17) + datetime.timedelta(jd) 58 | 59 | when = min(datetime.date(1972, 1, 1), table_start) 60 | # iers bulletin A doesn't cover 1972, so fake data for those 61 | # leap seconds 62 | while when < datetime.date(1972, 7, 1): 63 | offsets.append(-2) 64 | when = when + datetime.timedelta(days=1) 65 | while when < datetime.date(1972, 11, 1): 66 | offsets.append(8) 67 | when = when + datetime.timedelta(days=1) 68 | while when < datetime.date(1972, 12, 1): 69 | offsets.append(0) 70 | when = when + datetime.timedelta(days=1) 71 | while when < datetime.date(1973, 1, 1): 72 | offsets.append(-2) 73 | when = when + datetime.timedelta(days=1) 74 | while when < table_start: 75 | offsets.append(8) 76 | when = when + datetime.timedelta(days=1) 77 | 78 | table_start = min(datetime.date(1972, 1, 1), table_start) 79 | 80 | offsets.append(offs) 81 | 82 | wwvb_text = _get_text(NIST_URL) 83 | wwvb_data = bs4.BeautifulSoup(wwvb_text, features="html.parser") 84 | wwvb_dut1_table = wwvb_data.findAll("table")[2] 85 | assert wwvb_dut1_table 86 | meta = wwvb_data.find("meta", property="article:modified_time") 87 | assert isinstance(meta, bs4.Tag) 88 | wwvb_data_stamp = datetime.datetime.fromisoformat(meta.attrs["content"]).replace(tzinfo=None).date() 89 | 90 | def patch(patch_start: datetime.date, patch_end: datetime.date, val: int) -> None: 91 | off_start = (patch_start - table_start).days 92 | off_end = (patch_end - table_start).days 93 | offsets[off_start:off_end] = [val] * (off_end - off_start) 94 | 95 | wwvb_dut1: int | None = None 96 | wwvb_start: datetime.date | None = None 97 | for row in wwvb_dut1_table.findAll("tr")[1:][::-1]: 98 | cells = row.findAll("td") 99 | when = datetime.datetime.strptime(cells[0].text + "+0000", "%Y-%m-%d%z").date() 100 | dut1 = cells[2].text.replace("s", "").replace(" ", "") 101 | dut1 = round(float(dut1) * 10) 102 | if wwvb_dut1 is not None: 103 | assert wwvb_start is not None 104 | patch(wwvb_start, when, wwvb_dut1) 105 | wwvb_dut1 = dut1 106 | wwvb_start = when 107 | 108 | # As of 2021-06-14, NIST website incorrectly indicates the offset of -600ms 109 | # persisted through 2009-03-12, causing an incorrect leap second inference. 110 | # Assume instead that NIST started broadcasting +400ms on January 1, 2009, 111 | # causing the leap second to occur on 2008-12-31. 112 | patch(datetime.date(2009, 1, 1), datetime.date(2009, 3, 12), 4) 113 | 114 | # this is the final (most recent) wwvb DUT1 value broadcast. We want to 115 | # extend it some distance into the future, but how far? We will use the 116 | # modified timestamp of the NIST data. 117 | assert wwvb_dut1 is not None 118 | assert wwvb_start is not None 119 | patch(wwvb_start, wwvb_data_stamp + datetime.timedelta(days=1), wwvb_dut1) 120 | 121 | table_end = table_start + datetime.timedelta(len(offsets) - 1) 122 | base = ord("a") + 10 123 | offsets_bin = bytes(base + ch for ch in offsets) 124 | 125 | target_path.write_text( 126 | json.dumps( 127 | { 128 | "START": table_start.isoformat(), 129 | "OFFSETS_GZ": binascii.b2a_base64(gzip.compress(offsets_bin)).decode("ascii").strip(), 130 | }, 131 | ), 132 | ) 133 | 134 | print(f"iersdata covers {table_start} .. {table_end}") 135 | 136 | 137 | def iersdata_path(callback: Callable[[str, str], pathlib.Path]) -> pathlib.Path: 138 | """Find out the path for this directory""" 139 | return callback("wwvbpy", "unpythonic.net") / "iersdata.json" 140 | 141 | 142 | @click.command() 143 | @click.option( 144 | "--user", 145 | "location", 146 | flag_value=iersdata_path(platformdirs.user_data_path), 147 | default=iersdata_path(platformdirs.user_data_path), 148 | type=pathlib.Path, 149 | ) 150 | @click.option("--dist", "location", flag_value=DIST_PATH) 151 | @click.option("--site", "location", flag_value=iersdata_path(platformdirs.site_data_path)) 152 | def main(location: str) -> None: 153 | """Update DUT1 data""" 154 | path = pathlib.Path(location) 155 | print(f"will write to {location!r}") 156 | path.parent.mkdir(parents=True, exist_ok=True) 157 | update_iersdata(path) 158 | 159 | 160 | if __name__ == "__main__": 161 | main() 162 | -------------------------------------------------------------------------------- /src/wwvb/wwvbtk.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Visualize the WWVB signal in realtime""" 3 | 4 | # SPDX-FileCopyrightText: 2021-2024 Jeff Epler 5 | # 6 | # SPDX-License-Identifier: GPL-3.0-only 7 | from __future__ import annotations 8 | 9 | import datetime 10 | import functools 11 | from tkinter import Canvas, TclError, Tk 12 | from typing import TYPE_CHECKING, Any 13 | 14 | import click 15 | 16 | import wwvb 17 | 18 | if TYPE_CHECKING: 19 | from collections.abc import Generator 20 | 21 | 22 | @functools.cache 23 | def _app() -> Tk: 24 | """Create the Tk application object lazily""" 25 | return Tk() 26 | 27 | 28 | def validate_colors(ctx: Any, param: Any, value: str) -> list[str]: # noqa: ARG001 29 | """Check that all colors in a string are valid, splitting it to a list""" 30 | app = _app() 31 | colors = value.split() 32 | if len(colors) not in (2, 3, 4, 6): 33 | raise click.BadParameter(f"Give 2, 3, 4 or 6 colors (not {len(colors)})") 34 | for c in colors: 35 | try: 36 | app.winfo_rgb(c) 37 | except TclError as e: 38 | raise click.BadParameter(f"Invalid color {c}") from e 39 | 40 | if len(colors) == 2: 41 | off, on = colors 42 | return [off, off, off, on, on, on] 43 | if len(colors) == 3: 44 | return colors + colors 45 | if len(colors) == 4: 46 | off, c1, c2, c3 = colors 47 | return [off, off, off, c1, c2, c3] 48 | return colors 49 | 50 | 51 | DEFAULT_COLORS = "#3c3c3c #3c3c3c #3c3c3c #cc3c3c #88883c #3ccc3c" 52 | 53 | 54 | @click.command 55 | @click.option( 56 | "--colors", 57 | callback=validate_colors, 58 | default=DEFAULT_COLORS, 59 | metavar="COLORS", 60 | help="2, 3, 4, or 6 Tk color values", 61 | ) 62 | @click.option("--size", default=48, help="initial size in pixels") 63 | @click.option("--min-size", default=None, type=int, help="minimum size in pixels (default: same as initial size)") 64 | def main(colors: list[str], size: int, min_size: int | None) -> None: # noqa: PLR0915 65 | """Visualize the WWVB signal in realtime""" 66 | if min_size is None: 67 | min_size = size 68 | 69 | def deadline_ms(deadline: datetime.datetime) -> int: 70 | """Compute the number of ms until a deadline""" 71 | now = datetime.datetime.now(datetime.timezone.utc) 72 | return int(max(0, (deadline - now).total_seconds()) * 1000) 73 | 74 | def wwvbtick() -> Generator[tuple[datetime.datetime, wwvb.AmplitudeModulation]]: 75 | """Yield consecutive values of the WWVB amplitude signal, going from minute to minute""" 76 | timestamp = datetime.datetime.now(datetime.timezone.utc).replace(second=0, microsecond=0) 77 | 78 | while True: 79 | timecode = wwvb.WWVBMinuteIERS.from_datetime(timestamp).as_timecode() 80 | for i, code in enumerate(timecode.am): 81 | yield timestamp + datetime.timedelta(seconds=i), code 82 | timestamp = timestamp + datetime.timedelta(seconds=60) 83 | 84 | def wwvbsmarttick() -> Generator[tuple[datetime.datetime, wwvb.AmplitudeModulation]]: 85 | """Yield consecutive values of the WWVB amplitude signal 86 | 87 | .. but deal with time progressing unexpectedly, such as when the 88 | computer is suspended or NTP steps the clock backwards 89 | 90 | When time goes backwards or advances by more than a minute, get a fresh 91 | wwvbtick object; otherwise, discard time signals more than 1s in the past. 92 | """ 93 | while True: 94 | for stamp, code in wwvbtick(): 95 | now = datetime.datetime.now(datetime.timezone.utc) 96 | if stamp < now - datetime.timedelta(seconds=60): 97 | break 98 | if stamp < now - datetime.timedelta(seconds=1): 99 | continue 100 | yield stamp, code 101 | 102 | app = _app() 103 | app.wm_minsize(min_size, min_size) 104 | canvas = Canvas(app, width=size, height=size, highlightthickness=0) 105 | circle = canvas.create_oval(4, 4, 44, 44, outline="black", fill=colors[0]) 106 | canvas.pack(fill="both", expand=True) 107 | app.wm_deiconify() 108 | 109 | def resize_canvas(event: Any) -> None: 110 | """Keep the circle filling the window when it is resized""" 111 | sz = min(event.width, event.height) - 8 112 | if sz < 0: 113 | return 114 | canvas.coords( 115 | circle, 116 | event.width // 2 - sz // 2, 117 | event.height // 2 - sz // 2, 118 | event.width // 2 + sz // 2, 119 | event.height // 2 + sz // 2, 120 | ) 121 | 122 | canvas.bind("", resize_canvas) 123 | 124 | def led_on(i: int) -> None: 125 | """Turn the canvas's virtual LED on""" 126 | canvas.itemconfigure(circle, fill=colors[i + 3]) 127 | 128 | def led_off(i: int) -> None: 129 | """Turn the canvas's virtual LED off""" 130 | canvas.itemconfigure(circle, fill=colors[i]) 131 | 132 | def controller_func() -> Generator[int]: 133 | """Update the canvas virtual LED, yielding the number of ms until the next change""" 134 | for stamp, code in wwvbsmarttick(): 135 | yield deadline_ms(stamp) 136 | led_on(code) 137 | app.update() 138 | yield deadline_ms(stamp + datetime.timedelta(seconds=0.2 + 0.3 * int(code))) 139 | led_off(code) 140 | app.update() 141 | 142 | controller = controller_func().__next__ 143 | 144 | def after_func() -> None: 145 | """Repeatedly run the controller after the desired interval""" 146 | app.after(controller(), after_func) 147 | 148 | app.after_idle(after_func) 149 | app.mainloop() 150 | 151 | 152 | if __name__ == "__main__": 153 | main() 154 | -------------------------------------------------------------------------------- /test/testcli.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Test most wwvblib commandline programs""" 3 | 4 | # ruff: noqa: N802 D102 5 | # SPDX-FileCopyrightText: 2021-2024 Jeff Epler 6 | # 7 | # SPDX-License-Identifier: GPL-3.0-only 8 | 9 | import json 10 | import os 11 | import subprocess 12 | import sys 13 | import unittest 14 | from collections.abc import Sequence 15 | from typing import Any 16 | 17 | coverage_add = ("-m", "coverage", "run", "--branch", "-p") if "COVERAGE_RUN" in os.environ else () 18 | 19 | 20 | class CLITestCase(unittest.TestCase): 21 | """Test various CLI commands within wwvbpy""" 22 | 23 | def programOutput(self, *args: str) -> str: 24 | env = os.environ.copy() 25 | env["PYTHONIOENCODING"] = "utf-8" 26 | return subprocess.check_output(args, stdin=subprocess.DEVNULL, encoding="utf-8", env=env) 27 | 28 | def moduleArgs(self, *args: str) -> Sequence[str]: 29 | return (sys.executable, *coverage_add, "-m", *args) 30 | 31 | def moduleOutput(self, *args: str) -> str: 32 | return self.programOutput(sys.executable, *coverage_add, "-m", *args) 33 | 34 | def assertProgramOutput(self, expected: str, *args: str) -> None: 35 | """Check the output from invoking a program matches the expected""" 36 | actual = self.programOutput(*args) 37 | self.assertMultiLineEqual(expected, actual, f"args={args}") 38 | 39 | def assertProgramOutputStarts(self, expected: str, *args: str) -> None: 40 | """Check the output from invoking a program matches the expected""" 41 | actual = self.programOutput(*args) 42 | self.assertMultiLineEqual(expected, actual[: len(expected)], f"args={args}") 43 | 44 | def assertModuleOutput(self, expected: str, *args: str) -> None: 45 | """Check the output from invoking a `python -m modulename` program matches the expected""" 46 | actual = self.moduleOutput(*args) 47 | self.assertMultiLineEqual(expected, actual, f"args={args}") 48 | 49 | def assertStarts(self, expected: str, actual: str, *args: str) -> None: 50 | self.assertMultiLineEqual(expected, actual[: len(expected)], f"args={args}") 51 | 52 | def assertModuleJson(self, expected: Any, *args: str) -> None: 53 | """Check the output from invoking a `python -m modulename` program matches the expected""" 54 | actual = self.moduleOutput(*args) 55 | self.assertEqual(json.loads(actual), expected) 56 | 57 | def assertModuleOutputStarts(self, expected: str, *args: str) -> None: 58 | """Check the output from invoking a `python -m modulename` program matches the expected""" 59 | actual = self.moduleOutput(*args) 60 | self.assertStarts(expected, actual, *args) 61 | 62 | def assertProgramError(self, *args: str) -> None: 63 | """Check the output from invoking a program fails""" 64 | env = os.environ.copy() 65 | env["PYTHONIOENCODING"] = "utf-8" 66 | with self.assertRaises(subprocess.SubprocessError): 67 | subprocess.check_output( 68 | args, 69 | stdin=subprocess.DEVNULL, 70 | stderr=subprocess.DEVNULL, 71 | encoding="utf-8", 72 | env=env, 73 | ) 74 | 75 | def assertModuleError(self, *args: str) -> None: 76 | """Check the output from invoking a `python -m modulename` program fails""" 77 | self.assertProgramError(*self.moduleArgs(*args)) 78 | 79 | def test_gen(self) -> None: 80 | """Test wwvb.gen""" 81 | self.assertModuleOutput( 82 | """\ 83 | WWVB timecode: year=2020 days=001 hour=12 min=30 dst=0 ut1=-200 ly=1 ls=0 84 | 2020-001 12:30 201100000200010001020000000002000100010200100001020000010002 85 | """, 86 | "wwvb.gen", 87 | "-m", 88 | "1", 89 | "2020-1-1 12:30", 90 | ) 91 | 92 | self.assertModuleOutput( 93 | """\ 94 | WWVB timecode: year=2020 days=001 hour=12 min=30 dst=0 ut1=-200 ly=1 ls=0 95 | 2020-001 12:30 201100000200010001020000000002000100010200100001020000010002 96 | """, 97 | "wwvb.gen", 98 | "-m", 99 | "1", 100 | "2020", 101 | "1", 102 | "12", 103 | "30", 104 | ) 105 | 106 | self.assertModuleOutput( 107 | """\ 108 | WWVB timecode: year=2020 days=001 hour=12 min=30 dst=0 ut1=-200 ly=1 ls=0 109 | 2020-001 12:30 201100000200010001020000000002000100010200100001020000010002 110 | """, 111 | "wwvb.gen", 112 | "-m", 113 | "1", 114 | "2020", 115 | "1", 116 | "1", 117 | "12", 118 | "30", 119 | ) 120 | 121 | self.assertModuleError("wwvb.gen", "-m", "1", "2021", "7") 122 | 123 | # Asserting a leap second 124 | self.assertModuleOutput( 125 | """\ 126 | WWVB timecode: year=2020 days=001 hour=12 min=30 dst=0 ut1=-500 ly=1 ls=1 127 | 2020-001 12:30 201100000200010001020000000002000100010201010001020000011002 128 | """, 129 | "wwvb.gen", 130 | "-m", 131 | "1", 132 | "-s", 133 | "2020-1-1 12:30", 134 | ) 135 | 136 | # Asserting a different ut1 value 137 | self.assertModuleOutput( 138 | """\ 139 | WWVB timecode: year=2020 days=001 hour=12 min=30 dst=0 ut1=-300 ly=1 ls=0 140 | 2020-001 12:30 201100000200010001020000000002000100010200110001020000010002 141 | """, 142 | "wwvb.gen", 143 | "-m", 144 | "1", 145 | "-d", 146 | "-300", 147 | "2020-1-1 12:30", 148 | ) 149 | 150 | def test_dut1table(self) -> None: 151 | """Test the dut1table program""" 152 | self.assertModuleOutputStarts( 153 | """\ 154 | 1972-01-01 -0.2 182 LS on 1972-06-30 23:59:60 UTC 155 | 1972-07-01 0.8 123 156 | 1972-11-01 0.0 30 157 | 1972-12-01 -0.2 31 LS on 1972-12-31 23:59:60 UTC 158 | """, 159 | "wwvb.dut1table", 160 | ) 161 | 162 | def test_json(self) -> None: 163 | """Test the JSON output format""" 164 | self.assertModuleJson( 165 | [ 166 | { 167 | "year": 2021, 168 | "days": 340, 169 | "hour": 3, 170 | "minute": 40, 171 | "amplitude": "210000000200000001120011001002000000010200010001020001000002", 172 | "phase": "111110011011010101000100100110011110001110111010111101001011", 173 | }, 174 | { 175 | "year": 2021, 176 | "days": 340, 177 | "hour": 3, 178 | "minute": 41, 179 | "amplitude": "210000001200000001120011001002000000010200010001020001000002", 180 | "phase": "001010011100100011000101110000100001101000001111101100000010", 181 | }, 182 | ], 183 | "wwvb.gen", 184 | "-m", 185 | "2", 186 | "--style", 187 | "json", 188 | "--channel", 189 | "both", 190 | "2021-12-6 3:40", 191 | ) 192 | self.assertModuleJson( 193 | [ 194 | { 195 | "year": 2021, 196 | "days": 340, 197 | "hour": 3, 198 | "minute": 40, 199 | "amplitude": "210000000200000001120011001002000000010200010001020001000002", 200 | }, 201 | { 202 | "year": 2021, 203 | "days": 340, 204 | "hour": 3, 205 | "minute": 41, 206 | "amplitude": "210000001200000001120011001002000000010200010001020001000002", 207 | }, 208 | ], 209 | "wwvb.gen", 210 | "-m", 211 | "2", 212 | "--style", 213 | "json", 214 | "--channel", 215 | "amplitude", 216 | "2021-12-6 3:40", 217 | ) 218 | self.assertModuleJson( 219 | [ 220 | { 221 | "year": 2021, 222 | "days": 340, 223 | "hour": 3, 224 | "minute": 40, 225 | "phase": "111110011011010101000100100110011110001110111010111101001011", 226 | }, 227 | { 228 | "year": 2021, 229 | "days": 340, 230 | "hour": 3, 231 | "minute": 41, 232 | "phase": "001010011100100011000101110000100001101000001111101100000010", 233 | }, 234 | ], 235 | "wwvb.gen", 236 | "-m", 237 | "2", 238 | "--style", 239 | "json", 240 | "--channel", 241 | "phase", 242 | "2021-12-6 3:40", 243 | ) 244 | 245 | def test_sextant(self) -> None: 246 | """Test the sextant output format""" 247 | self.assertModuleOutput( 248 | """\ 249 | WWVB timecode: year=2021 days=340 hour=03 min=40 dst=0 ut1=-100 ly=0 ls=0 --style=sextant 250 | 2021-340 03:40 \ 251 | 🬋🬩🬋🬹🬩🬹🬩🬹🬩🬹🬍🬎🬍🬎🬩🬹🬩🬹🬋🬍🬩🬹🬩🬹🬍🬎🬩🬹🬍🬎🬩🬹🬍🬎🬋🬹🬋🬎🬋🬍🬍🬎🬩🬹🬋🬎🬋🬎🬩🬹🬍🬎🬋🬎🬩🬹🬩🬹🬋🬍🬍🬎🬩🬹🬩🬹🬩🬹🬩🬹🬍🬎🬍🬎🬋🬎🬩🬹🬋🬩🬩🬹🬍🬎🬩🬹🬋🬹🬩🬹🬍🬎🬩🬹🬋🬎🬩🬹🬋🬩🬩🬹🬩🬹🬍🬎🬋🬹🬍🬎🬍🬎🬩🬹🬍🬎🬩🬹🬋🬩 252 | 253 | 2021-340 03:41 \ 254 | 🬋🬍🬋🬎🬩🬹🬍🬎🬩🬹🬍🬎🬍🬎🬩🬹🬋🬹🬋🬩🬍🬎🬍🬎🬩🬹🬍🬎🬍🬎🬍🬎🬩🬹🬋🬹🬋🬎🬋🬍🬍🬎🬩🬹🬋🬎🬋🬹🬩🬹🬩🬹🬋🬎🬍🬎🬍🬎🬋🬍🬩🬹🬍🬎🬍🬎🬍🬎🬍🬎🬩🬹🬩🬹🬋🬎🬩🬹🬋🬍🬍🬎🬍🬎🬍🬎🬋🬎🬩🬹🬩🬹🬩🬹🬋🬹🬩🬹🬋🬍🬩🬹🬩🬹🬍🬎🬋🬎🬍🬎🬍🬎🬍🬎🬍🬎🬩🬹🬋🬍 255 | 256 | """, 257 | "wwvb.gen", 258 | "-m", 259 | "2", 260 | "--style", 261 | "sextant", 262 | "2021-12-6 3:40", 263 | ) 264 | 265 | def test_now(self) -> None: 266 | """Test outputting timecodes for 'now'""" 267 | self.assertModuleOutputStarts( 268 | "WWVB timecode: year=", 269 | "wwvb.gen", 270 | "-m", 271 | "1", 272 | ) 273 | 274 | def test_decode(self) -> None: 275 | """Test the commandline decoder""" 276 | self.assertModuleOutput( 277 | """\ 278 | 201100000200100001020011001012000000010200010001020001000002 279 | year=2021 days=350 hour=22 min=30 dst=0 ut1=-100 ly=0 ls=0 280 | """, 281 | "wwvb.decode", 282 | "201100000200100001020011001012000000010200010001020001000002", 283 | ) 284 | 285 | self.assertModuleOutput( 286 | """\ 287 | 201101111200100001020011001012000000010200010001020001000002 288 | """, 289 | "wwvb.decode", 290 | "201101111200100001020011001012000000010200010001020001000002", 291 | ) 292 | -------------------------------------------------------------------------------- /test/testdaylight.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Test of daylight saving time calculations""" 3 | 4 | # SPDX-FileCopyrightText: 2021-2024 Jeff Epler 5 | # 6 | # SPDX-License-Identifier: GPL-3.0-only 7 | 8 | import datetime 9 | import unittest 10 | 11 | import wwvb 12 | from wwvb.tz import Mountain 13 | 14 | 15 | class TestDaylight(unittest.TestCase): 16 | """Test of daylight saving time calculations""" 17 | 18 | def test_onset(self) -> None: 19 | """Test that the onset of DST is the same in Mountain and WWVBMinute (which uses ls bits)""" 20 | for h in [8, 9, 10]: 21 | for dm in range(-1441, 1442): 22 | d = datetime.datetime(2021, 3, 14, h, 0, tzinfo=datetime.timezone.utc) + datetime.timedelta(minutes=dm) 23 | m = wwvb.WWVBMinute.from_datetime(d) 24 | self.assertEqual( 25 | m.as_datetime_local().replace(tzinfo=Mountain), 26 | d.astimezone(Mountain), 27 | ) 28 | 29 | def test_end(self) -> None: 30 | """Test that the end of DST is the same in Mountain and WWVBMinute (which uses ls bits)""" 31 | for h in [7, 8, 9]: 32 | for dm in range(-1441, 1442): 33 | d = datetime.datetime(2021, 11, 7, h, 0, tzinfo=datetime.timezone.utc) + datetime.timedelta(minutes=dm) 34 | m = wwvb.WWVBMinute.from_datetime(d) 35 | self.assertEqual( 36 | m.as_datetime_local().replace(tzinfo=Mountain), 37 | d.astimezone(Mountain), 38 | ) 39 | 40 | def test_midsummer(self) -> None: 41 | """Test that middle of DST is the same in Mountain and WWVBMinute (which uses ls bits)""" 42 | for h in [7, 8, 9]: 43 | for dm in (-1, 0, 1): 44 | d = datetime.datetime(2021, 7, 7, h, 0, tzinfo=datetime.timezone.utc) + datetime.timedelta(minutes=dm) 45 | m = wwvb.WWVBMinute.from_datetime(d) 46 | self.assertEqual( 47 | m.as_datetime_local().replace(tzinfo=Mountain), 48 | d.astimezone(Mountain), 49 | ) 50 | 51 | def test_midwinter(self) -> None: 52 | """Test that middle of standard time is the same in Mountain and WWVBMinute (which uses ls bits)""" 53 | for h in [7, 8, 9]: 54 | for dm in (-1, 0, 1): 55 | d = datetime.datetime(2021, 12, 25, h, 0, tzinfo=datetime.timezone.utc) + datetime.timedelta(minutes=dm) 56 | m = wwvb.WWVBMinute.from_datetime(d) 57 | self.assertEqual( 58 | m.as_datetime_local().replace(tzinfo=Mountain), 59 | d.astimezone(Mountain), 60 | ) 61 | -------------------------------------------------------------------------------- /test/testls.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Leap seconds tests""" 3 | 4 | # SPDX-FileCopyrightText: 2021-2024 Jeff Epler 5 | # 6 | # SPDX-License-Identifier: GPL-3.0-only 7 | 8 | import datetime 9 | import unittest 10 | 11 | import leapseconddata 12 | 13 | import wwvb 14 | from wwvb import iersdata 15 | 16 | ONE_DAY = datetime.timedelta(days=1) 17 | 18 | 19 | def next_month(d: datetime.date) -> datetime.date: 20 | """Return the start of the next month after the day 'd'""" 21 | d = d.replace(day=28) 22 | while True: 23 | d0 = d 24 | d = d + ONE_DAY 25 | if d.month != d0.month: 26 | return d 27 | 28 | 29 | class TestLeapSecond(unittest.TestCase): 30 | """Leap second tests""" 31 | 32 | maxDiff = 9999 33 | 34 | def test_leap(self) -> None: 35 | """Tests that the expected leap seconds all occur.""" 36 | ls = leapseconddata.LeapSecondData.from_standard_source() 37 | assert ls.valid_until is not None 38 | 39 | d = iersdata.start 40 | e = min(iersdata.end, ls.valid_until) 41 | bench = [ts.start for ts in ls.leap_seconds[1:]] 42 | bench = [ts for ts in bench if d <= ts < e] 43 | leap = [] 44 | while d < e: 45 | nm = next_month(d) 46 | eom = nm - ONE_DAY 47 | month_ends_dut1 = wwvb.get_dut1(eom) 48 | month_starts_dut1 = wwvb.get_dut1(nm) 49 | our_is_ls = month_ends_dut1 * month_starts_dut1 < 0 50 | if wwvb.isls(eom): 51 | assert our_is_ls 52 | self.assertLess(month_ends_dut1, 0) 53 | self.assertGreater(month_starts_dut1, 0) 54 | leap.append(nm) 55 | else: 56 | assert not our_is_ls 57 | d = datetime.datetime.combine(nm, datetime.time(), tzinfo=datetime.timezone.utc) 58 | self.assertEqual(leap, bench) 59 | 60 | 61 | if __name__ == "__main__": 62 | unittest.main() 63 | -------------------------------------------------------------------------------- /test/testpm.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Test Phase Modulation Signal""" 3 | 4 | # SPDX-FileCopyrightText: 2021-2024 Jeff Epler 5 | # 6 | # SPDX-License-Identifier: GPL-3.0-only 7 | 8 | import unittest 9 | 10 | import wwvb 11 | 12 | 13 | class TestPhaseModulation(unittest.TestCase): 14 | """Test Phase Modulation Signal""" 15 | 16 | def test_pm(self) -> None: 17 | """Compare the generated signal from a reference minute in NIST docs""" 18 | ref_am = "201100000200010011120001010002011000101201000000120010010112" 19 | 20 | ref_pm = "001110110100010010000011001000011000110100110100010110110110" 21 | 22 | ref_minute = wwvb.WWVBMinuteIERS(2012, 186, 17, 30, dst=3) 23 | ref_time = ref_minute.as_timecode() 24 | 25 | test_am = ref_time.to_am_string(["0", "1", "2"]) 26 | test_pm = ref_time.to_pm_string(["0", "1"]) 27 | 28 | self.assertEqual(ref_am, test_am) 29 | self.assertEqual(ref_pm, test_pm) 30 | 31 | 32 | if __name__ == "__main__": 33 | unittest.main() 34 | -------------------------------------------------------------------------------- /test/testuwwvb.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Test of uwwvb.py""" 3 | # SPDX-FileCopyrightText: 2021-2024 Jeff Epler 4 | # 5 | # SPDX-License-Identifier: GPL-3.0-only 6 | 7 | # ruff: noqa: N802 D102 8 | import datetime 9 | import random 10 | import sys 11 | import unittest 12 | import zoneinfo 13 | from typing import Union 14 | 15 | import adafruit_datetime 16 | 17 | import uwwvb 18 | import wwvb 19 | 20 | EitherDatetimeOrNone = Union[None, datetime.datetime, adafruit_datetime.datetime] 21 | 22 | 23 | class WWVBRoundtrip(unittest.TestCase): 24 | """tests of uwwvb.py""" 25 | 26 | def assertDateTimeEqualExceptTzInfo(self, a: EitherDatetimeOrNone, b: EitherDatetimeOrNone) -> None: 27 | """Test two datetime objects for equality 28 | 29 | This equality test excludes tzinfo, and allows adafruit_datetime and core datetime modules to compare equal 30 | """ 31 | assert a 32 | assert b 33 | self.assertEqual( 34 | (a.year, a.month, a.day, a.hour, a.minute, a.second, a.microsecond), 35 | (b.year, b.month, b.day, b.hour, b.minute, b.second, b.microsecond), 36 | ) 37 | 38 | def test_decode(self) -> None: 39 | """Test decoding of some minutes including a leap second. 40 | 41 | Each minute must decode and match the primary decoder. 42 | """ 43 | minute = wwvb.WWVBMinuteIERS.from_datetime(datetime.datetime(2012, 6, 30, 23, 50, tzinfo=datetime.timezone.utc)) 44 | assert minute 45 | decoder = uwwvb.WWVBDecoder() 46 | decoder.update(uwwvb.MARK) 47 | any_leap_second = False 48 | for _ in range(20): 49 | timecode = minute.as_timecode() 50 | decoded = None 51 | if len(timecode.am) == 61: 52 | any_leap_second = True 53 | for code in timecode.am: 54 | decoded = uwwvb.decode_wwvb(decoder.update(int(code))) or decoded 55 | assert decoded 56 | self.assertDateTimeEqualExceptTzInfo( 57 | minute.as_datetime_utc(), 58 | uwwvb.as_datetime_utc(decoded), 59 | ) 60 | minute = minute.next_minute() 61 | self.assertTrue(any_leap_second) 62 | 63 | def test_roundtrip(self) -> None: 64 | """Test that some big range of times all decode the same as the primary decoder""" 65 | dt = datetime.datetime(2002, 1, 1, 0, 0, tzinfo=datetime.timezone.utc) 66 | delta = datetime.timedelta(minutes=7182 if sys.implementation.name == "cpython" else 86400 - 7182) 67 | while dt.year < 2013: 68 | minute = wwvb.WWVBMinuteIERS.from_datetime(dt) 69 | assert minute 70 | decoded = uwwvb.decode_wwvb([int(i) for i in minute.as_timecode().am]) 71 | assert decoded 72 | self.assertDateTimeEqualExceptTzInfo(minute.as_datetime_utc(), uwwvb.as_datetime_utc(decoded)) 73 | dt = dt + delta 74 | 75 | def test_dst(self) -> None: 76 | """Test of DST as handled by the small decoder""" 77 | for dt in ( 78 | datetime.datetime(2021, 3, 14, 8, 59, tzinfo=datetime.timezone.utc), 79 | datetime.datetime(2021, 3, 14, 9, 00, tzinfo=datetime.timezone.utc), 80 | datetime.datetime(2021, 3, 14, 9, 1, tzinfo=datetime.timezone.utc), 81 | datetime.datetime(2021, 3, 15, 8, 59, tzinfo=datetime.timezone.utc), 82 | datetime.datetime(2021, 3, 15, 9, 00, tzinfo=datetime.timezone.utc), 83 | datetime.datetime(2021, 3, 15, 9, 1, tzinfo=datetime.timezone.utc), 84 | datetime.datetime(2021, 11, 7, 8, 59, tzinfo=datetime.timezone.utc), 85 | datetime.datetime(2021, 11, 7, 9, 00, tzinfo=datetime.timezone.utc), 86 | datetime.datetime(2021, 11, 7, 9, 1, tzinfo=datetime.timezone.utc), 87 | datetime.datetime(2021, 11, 8, 8, 59, tzinfo=datetime.timezone.utc), 88 | datetime.datetime(2021, 11, 8, 9, 00, tzinfo=datetime.timezone.utc), 89 | datetime.datetime(2021, 11, 8, 9, 1, tzinfo=datetime.timezone.utc), 90 | datetime.datetime(2021, 7, 7, 9, 1, tzinfo=datetime.timezone.utc), 91 | ): 92 | minute = wwvb.WWVBMinuteIERS.from_datetime(dt) 93 | decoded = uwwvb.decode_wwvb([int(i) for i in minute.as_timecode().am]) 94 | assert decoded 95 | self.assertDateTimeEqualExceptTzInfo(minute.as_datetime_local(), uwwvb.as_datetime_local(decoded)) 96 | 97 | decoded = uwwvb.decode_wwvb([int(i) for i in minute.as_timecode().am]) 98 | assert decoded 99 | self.assertDateTimeEqualExceptTzInfo( 100 | minute.as_datetime_local(dst_observed=False), 101 | uwwvb.as_datetime_local(decoded, dst_observed=False), 102 | ) 103 | 104 | def test_noise(self) -> None: 105 | """Test of the state-machine decoder when faced with pseudorandom noise""" 106 | minute = wwvb.WWVBMinuteIERS.from_datetime( 107 | datetime.datetime(2012, 6, 30, 23, 50, tzinfo=datetime.timezone.utc), 108 | ) 109 | r = random.Random(408) 110 | junk = [ 111 | r.choice( 112 | [ 113 | wwvb.AmplitudeModulation.MARK, 114 | wwvb.AmplitudeModulation.ONE, 115 | wwvb.AmplitudeModulation.ZERO, 116 | ], 117 | ) 118 | for _ in range(480) 119 | ] 120 | timecode = minute.as_timecode() 121 | test_input = [*junk, wwvb.AmplitudeModulation.MARK, *timecode.am] 122 | decoder = uwwvb.WWVBDecoder() 123 | for code in test_input[:-1]: 124 | decoded = decoder.update(code) 125 | self.assertIsNone(decoded) 126 | minute_maybe = decoder.update(wwvb.AmplitudeModulation.MARK) 127 | assert minute_maybe 128 | decoded_minute = uwwvb.decode_wwvb(minute_maybe) 129 | assert decoded_minute 130 | self.assertDateTimeEqualExceptTzInfo( 131 | minute.as_datetime_utc(), 132 | uwwvb.as_datetime_utc(decoded_minute), 133 | ) 134 | self.assertDateTimeEqualExceptTzInfo( 135 | minute.as_datetime_local(), 136 | uwwvb.as_datetime_local(decoded_minute), 137 | ) 138 | 139 | def test_noise2(self) -> None: 140 | """Test of the full minute decoder with targeted errors to get full coverage""" 141 | minute = wwvb.WWVBMinuteIERS.from_datetime( 142 | datetime.datetime(2012, 6, 30, 23, 50, tzinfo=datetime.timezone.utc), 143 | ) 144 | timecode = minute.as_timecode() 145 | decoded = uwwvb.decode_wwvb([int(i) for i in timecode.am]) 146 | self.assertIsNotNone(decoded) 147 | for position in uwwvb.always_mark: 148 | test_input = [int(i) for i in timecode.am] 149 | for noise in (0, 1): 150 | test_input[position] = noise 151 | decoded = uwwvb.decode_wwvb(test_input) 152 | self.assertIsNone(decoded) 153 | for position in uwwvb.always_zero: 154 | test_input = [int(i) for i in timecode.am] 155 | for noise in (1, 2): 156 | test_input[position] = noise 157 | decoded = uwwvb.decode_wwvb(test_input) 158 | self.assertIsNone(decoded) 159 | for i in range(8): 160 | if i in (0b101, 0b010): # Test the 6 impossible bit-combos 161 | continue 162 | test_input = [int(i) for i in timecode.am] 163 | test_input[36] = i & 1 164 | test_input[37] = (i >> 1) & 1 165 | test_input[38] = (i >> 2) & 1 166 | decoded = uwwvb.decode_wwvb(test_input) 167 | self.assertIsNone(decoded) 168 | # Invalid year-day 169 | test_input = [int(i) for i in timecode.am] 170 | test_input[22] = 1 171 | test_input[23] = 1 172 | test_input[25] = 1 173 | decoded = uwwvb.decode_wwvb(test_input) 174 | self.assertIsNone(decoded) 175 | 176 | def test_noise3(self) -> None: 177 | """Test impossible BCD values""" 178 | minute = wwvb.WWVBMinuteIERS.from_datetime( 179 | datetime.datetime(2012, 6, 30, 23, 50, tzinfo=datetime.timezone.utc), 180 | ) 181 | timecode = minute.as_timecode() 182 | 183 | for poslist in [ 184 | [1, 2, 3, 4], # tens minutes 185 | [5, 6, 7, 8], # ones minutes 186 | [15, 16, 17, 18], # tens hours 187 | [25, 26, 27, 28], # tens days 188 | [30, 31, 32, 33], # ones days 189 | [40, 41, 42, 43], # tens years 190 | [45, 46, 47, 48], # ones years 191 | [50, 51, 52, 53], # ones dut1 192 | ]: 193 | with self.subTest(test=poslist): 194 | test_input = [int(i) for i in timecode.am] 195 | for pi in poslist: 196 | test_input[pi] = 1 197 | decoded = uwwvb.decode_wwvb(test_input) 198 | self.assertIsNone(decoded) 199 | 200 | def test_str(self) -> None: 201 | """Test the str() of a WWVBDecoder""" 202 | self.assertEqual(str(uwwvb.WWVBDecoder()), "") 203 | 204 | def test_near_year_bug(self) -> None: 205 | """Test for a bug seen in another WWVB implementaiton 206 | 207 | .. in which the hours after UTC midnight on 12-31 of a leap year would 208 | be shown incorrectly. Check that we don't have that bug. 209 | """ 210 | minute = wwvb.WWVBMinuteIERS.from_datetime(datetime.datetime(2021, 1, 1, 0, 0, tzinfo=datetime.timezone.utc)) 211 | timecode = minute.as_timecode() 212 | decoded = uwwvb.decode_wwvb([int(i) for i in timecode.am]) 213 | assert decoded 214 | self.assertDateTimeEqualExceptTzInfo( 215 | datetime.datetime(2020, 12, 31, 17, 00, tzinfo=zoneinfo.ZoneInfo("America/Denver")), # Mountain time! 216 | uwwvb.as_datetime_local(decoded), 217 | ) 218 | 219 | 220 | if __name__ == "__main__": 221 | unittest.main() 222 | -------------------------------------------------------------------------------- /test/testwwvb.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | # ruff: noqa: E501 3 | 4 | """Test most wwvblib functionality""" 5 | 6 | # SPDX-FileCopyrightText: 2011-2024 Jeff Epler 7 | # 8 | # SPDX-License-Identifier: GPL-3.0-only 9 | 10 | from __future__ import annotations 11 | 12 | import copy 13 | import datetime 14 | import io 15 | import pathlib 16 | import random 17 | import sys 18 | import unittest 19 | 20 | import uwwvb 21 | import wwvb 22 | from wwvb import decode, iersdata, tz 23 | 24 | 25 | class WWVBMinute2k(wwvb.WWVBMinute): 26 | """Treats the origin of the 2-digit epoch as 2000""" 27 | 28 | epoch = 2000 29 | 30 | 31 | class WWVBTestCase(unittest.TestCase): 32 | """Test each expected output in wwvbgen_testcases/. Some outputs are from another program, some are from us""" 33 | 34 | maxDiff = 131072 35 | 36 | def test_cases(self) -> None: 37 | """Generate a test case for each expected output in tests/""" 38 | for test in ((pathlib.Path(__file__).parent) / "wwvbgen_testcases").glob("*"): 39 | with self.subTest(test=test): 40 | text = test.read_text(encoding="utf-8") 41 | lines = [line for line in text.split("\n") if not line.startswith("#")] 42 | while not lines[0]: 43 | del lines[0] 44 | text = "\n".join(lines) 45 | header = lines[0].split() 46 | timestamp = " ".join(header[:10]) 47 | options = header[10:] 48 | channel = "amplitude" 49 | style = "default" 50 | for o in options: 51 | if o.startswith("--channel="): 52 | channel = o[10:] 53 | elif o.startswith("--style="): 54 | style = o[8:] 55 | else: 56 | raise ValueError(f"Unknown option {o!r}") 57 | num_minutes = len(lines) - 2 58 | if channel == "both": 59 | num_minutes = len(lines) // 3 60 | 61 | num_headers = sum(line.startswith("WWVB timecode") for line in lines) 62 | if num_headers > 1: 63 | all_timecodes = True 64 | num_minutes = num_headers 65 | else: 66 | all_timecodes = False 67 | 68 | w = wwvb.WWVBMinute.fromstring(timestamp) 69 | result = io.StringIO() 70 | wwvb.print_timecodes( 71 | w, 72 | num_minutes, 73 | channel=channel, 74 | style=style, 75 | all_timecodes=all_timecodes, 76 | file=result, 77 | ) 78 | result_str = result.getvalue() 79 | self.assertEqual(text, result_str) 80 | 81 | 82 | class WWVBRoundtrip(unittest.TestCase): 83 | """Round-trip tests""" 84 | 85 | def test_decode(self) -> None: 86 | """Test that a range of minutes including a leap second are correctly decoded by the state-based decoder""" 87 | minute = wwvb.WWVBMinuteIERS.from_datetime(datetime.datetime(1992, 6, 30, 23, 50, tzinfo=datetime.timezone.utc)) 88 | decoder = decode.wwvbreceive() 89 | next(decoder) 90 | decoder.send(wwvb.AmplitudeModulation.MARK) 91 | any_leap_second = False 92 | for _ in range(20): 93 | timecode = minute.as_timecode() 94 | decoded: wwvb.WWVBTimecode | None = None 95 | if len(timecode.am) == 61: 96 | any_leap_second = True 97 | for code in timecode.am: 98 | decoded = decoder.send(code) or decoded 99 | assert decoded 100 | self.assertEqual( 101 | timecode.am[:60], 102 | decoded.am, 103 | f"Checking equality of minute {minute}: [expected] {timecode.am} != [actual] {decoded.am}", 104 | ) 105 | minute = minute.next_minute() 106 | self.assertTrue(any_leap_second) 107 | 108 | def test_cover_fill_pm_timecode_extended(self) -> None: 109 | """Get full coverage of the function pm_timecode_extended""" 110 | for dt in ( 111 | datetime.datetime(1992, 1, 1, tzinfo=datetime.timezone.utc), 112 | datetime.datetime(1992, 4, 5, tzinfo=datetime.timezone.utc), 113 | datetime.datetime(1992, 6, 1, tzinfo=datetime.timezone.utc), 114 | datetime.datetime(1992, 10, 25, tzinfo=datetime.timezone.utc), 115 | ): 116 | for hour in (0, 4, 11): 117 | dt1 = dt.replace(hour=hour, minute=10) 118 | minute = wwvb.WWVBMinuteIERS.from_datetime(dt1) 119 | assert minute is not None 120 | timecode = minute.as_timecode().am 121 | assert timecode 122 | 123 | def test_roundtrip(self) -> None: 124 | """Test that a wide of minutes are correctly decoded by the state-based decoder""" 125 | dt = datetime.datetime(1992, 1, 1, 0, 0, tzinfo=datetime.timezone.utc) 126 | delta = datetime.timedelta(minutes=915 if sys.implementation.name == "cpython" else 86400 - 915) 127 | while dt.year < 1993: 128 | minute = wwvb.WWVBMinuteIERS.from_datetime(dt) 129 | assert minute is not None 130 | timecode = minute.as_timecode().am 131 | assert timecode 132 | decoded_minute: wwvb.WWVBMinute | None = wwvb.WWVBMinuteIERS.from_timecode_am(minute.as_timecode()) 133 | assert decoded_minute 134 | decoded = decoded_minute.as_timecode().am 135 | self.assertEqual( 136 | timecode, 137 | decoded, 138 | f"Checking equality of minute {minute}: [expected] {timecode} != [actual] {decoded}", 139 | ) 140 | dt = dt + delta 141 | 142 | def test_noise(self) -> None: 143 | """Test against pseudorandom noise""" 144 | minute = wwvb.WWVBMinuteIERS.from_datetime(datetime.datetime(1992, 6, 30, 23, 50, tzinfo=datetime.timezone.utc)) 145 | r = random.Random(408) 146 | junk = [ 147 | r.choice( 148 | [ 149 | wwvb.AmplitudeModulation.MARK, 150 | wwvb.AmplitudeModulation.ONE, 151 | wwvb.AmplitudeModulation.ZERO, 152 | ], 153 | ) 154 | for _ in range(480) 155 | ] 156 | timecode = minute.as_timecode() 157 | test_input = [*junk, wwvb.AmplitudeModulation.MARK, *timecode.am] 158 | decoder = decode.wwvbreceive() 159 | next(decoder) 160 | for code in test_input[:-1]: 161 | decoded = decoder.send(code) 162 | self.assertIsNone(decoded) 163 | decoded = decoder.send(wwvb.AmplitudeModulation.MARK) 164 | assert decoded 165 | self.assertIsNotNone(decoded) 166 | self.assertEqual( 167 | timecode.am[:60], 168 | decoded.am, 169 | f"Checking equality of minute {minute}: [expected] {timecode.am} != [actual] {decoded.am}", 170 | ) 171 | 172 | def test_noise2(self) -> None: 173 | """Test of the full minute decoder with targeted errors to get full coverage""" 174 | minute = wwvb.WWVBMinuteIERS.from_datetime(datetime.datetime(2012, 6, 30, 23, 50, tzinfo=datetime.timezone.utc)) 175 | timecode = minute.as_timecode() 176 | decoded = wwvb.WWVBMinute.from_timecode_am(timecode) 177 | self.assertIsNotNone(decoded) 178 | for position in uwwvb.always_mark: 179 | test_input = copy.deepcopy(timecode) 180 | for noise in (0, 1): 181 | test_input.am[position] = wwvb.AmplitudeModulation(noise) 182 | decoded = wwvb.WWVBMinute.from_timecode_am(test_input) 183 | self.assertIsNone(decoded) 184 | for position in uwwvb.always_zero: 185 | test_input = copy.deepcopy(timecode) 186 | for noise in (1, 2): 187 | test_input.am[position] = wwvb.AmplitudeModulation(noise) 188 | decoded = wwvb.WWVBMinute.from_timecode_am(test_input) 189 | self.assertIsNone(decoded) 190 | for i in range(8): 191 | if i in (0b101, 0b010): # Test the 6 impossible bit-combos 192 | continue 193 | test_input = copy.deepcopy(timecode) 194 | test_input.am[36] = wwvb.AmplitudeModulation(i & 1) 195 | test_input.am[37] = wwvb.AmplitudeModulation((i >> 1) & 1) 196 | test_input.am[38] = wwvb.AmplitudeModulation((i >> 2) & 1) 197 | decoded = wwvb.WWVBMinute.from_timecode_am(test_input) 198 | self.assertIsNone(decoded) 199 | # Invalid year-day 200 | test_input = copy.deepcopy(timecode) 201 | test_input.am[22] = wwvb.AmplitudeModulation(1) 202 | test_input.am[23] = wwvb.AmplitudeModulation(1) 203 | test_input.am[25] = wwvb.AmplitudeModulation(1) 204 | decoded = wwvb.WWVBMinute.from_timecode_am(test_input) 205 | self.assertIsNone(decoded) 206 | 207 | def test_noise3(self) -> None: 208 | """Test impossible BCD values""" 209 | minute = wwvb.WWVBMinuteIERS.from_datetime(datetime.datetime(2012, 6, 30, 23, 50, tzinfo=datetime.timezone.utc)) 210 | timecode = minute.as_timecode() 211 | 212 | for poslist in [ 213 | [1, 2, 3, 4], # tens minutes 214 | [5, 6, 7, 8], # ones minutes 215 | [15, 16, 17, 18], # tens hours 216 | [25, 26, 27, 28], # tens days 217 | [30, 31, 32, 33], # ones days 218 | [40, 41, 42, 43], # tens years 219 | [45, 46, 47, 48], # ones years 220 | [50, 51, 52, 53], # ones dut1 221 | ]: 222 | with self.subTest(test=poslist): 223 | test_input = copy.deepcopy(timecode) 224 | for pi in poslist: 225 | test_input.am[pi] = wwvb.AmplitudeModulation(1) 226 | decoded = wwvb.WWVBMinute.from_timecode_am(test_input) 227 | self.assertIsNone(decoded) 228 | 229 | def test_previous_next_minute(self) -> None: 230 | """Test that previous minute and next minute are inverses""" 231 | minute = wwvb.WWVBMinuteIERS.from_datetime(datetime.datetime(1992, 6, 30, 23, 50, tzinfo=datetime.timezone.utc)) 232 | self.assertEqual(minute, minute.next_minute().previous_minute()) 233 | 234 | def test_timecode_str(self) -> None: 235 | """Test the str() and repr() methods""" 236 | minute = wwvb.WWVBMinuteIERS.from_datetime(datetime.datetime(1992, 6, 30, 23, 50, tzinfo=datetime.timezone.utc)) 237 | timecode = minute.as_timecode() 238 | self.assertEqual( 239 | str(timecode), 240 | "₂₁⁰¹⁰₀⁰⁰₀²₀₀₁₀₀⁰₀¹¹₂₀⁰⁰¹₀₁⁰⁰₀₂₀⁰₁⁰₀₀⁰₁⁰²⁰¹¹₀⁰¹₀⁰¹²⁰⁰¹₀₀¹₁₁₁₂", 241 | ) 242 | timecode.phase = [wwvb.PhaseModulation.UNSET] * 60 243 | self.assertEqual( 244 | repr(timecode), 245 | "", 246 | ) 247 | 248 | def test_extreme_dut1(self) -> None: 249 | """Test extreme dut1 dates""" 250 | s = iersdata.DUT1_DATA_START 251 | sm1 = s - datetime.timedelta(days=1) 252 | self.assertEqual(wwvb.get_dut1(s), wwvb.get_dut1(sm1)) 253 | 254 | e = iersdata.DUT1_DATA_START + datetime.timedelta(days=len(iersdata.DUT1_OFFSETS) - 1) 255 | ep1 = e + datetime.timedelta(days=1) 256 | 257 | self.assertEqual(wwvb.get_dut1(e), wwvb.get_dut1(ep1)) 258 | 259 | ep2 = datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(days=340) 260 | wwvb.get_dut1(ep2) 261 | 262 | def test_epoch(self) -> None: 263 | """Test the 1970-to-2069 epoch""" 264 | m = wwvb.WWVBMinute(69, 1, 1, 0, 0) 265 | n = wwvb.WWVBMinute(2069, 1, 1, 0, 0) 266 | self.assertEqual(m, n) 267 | 268 | m = wwvb.WWVBMinute(70, 1, 1, 0, 0) 269 | n = wwvb.WWVBMinute(1970, 1, 1, 0, 0) 270 | self.assertEqual(m, n) 271 | 272 | def test_fromstring(self) -> None: 273 | """Test the fromstring() classmethod""" 274 | s = "WWVB timecode: year=1998 days=365 hour=23 min=56 dst=0 ut1=-300 ly=0 ls=1" 275 | t = "year=1998 days=365 hour=23 min=56 dst=0 ut1=-300 ly=0 ls=1" 276 | self.assertEqual(wwvb.WWVBMinuteIERS.fromstring(s), wwvb.WWVBMinuteIERS.fromstring(t)) 277 | t = "year=1998 days=365 hour=23 min=56 dst=0 ut1=-300 ls=1" 278 | self.assertEqual(wwvb.WWVBMinuteIERS.fromstring(s), wwvb.WWVBMinuteIERS.fromstring(t)) 279 | t = "year=1998 days=365 hour=23 min=56 dst=0" 280 | self.assertEqual(wwvb.WWVBMinuteIERS.fromstring(s), wwvb.WWVBMinuteIERS.fromstring(t)) 281 | 282 | def test_from_datetime(self) -> None: 283 | """Test the from_datetime() classmethod""" 284 | d = datetime.datetime(1998, 12, 31, 23, 56, 0, tzinfo=datetime.timezone.utc) 285 | self.assertEqual( 286 | wwvb.WWVBMinuteIERS.from_datetime(d), 287 | wwvb.WWVBMinuteIERS.from_datetime(d, newls=True, newut1=-300), 288 | ) 289 | 290 | def test_exceptions(self) -> None: 291 | """Test some error detection""" 292 | with self.assertRaises(ValueError): 293 | wwvb.WWVBMinute(2021, 1, 1, 1, dst=4) 294 | 295 | with self.assertRaises(ValueError): 296 | wwvb.WWVBMinute(2021, 1, 1, 1, ut1=1) 297 | 298 | with self.assertRaises(ValueError): 299 | wwvb.WWVBMinute(2021, 1, 1, 1, ls=False) 300 | 301 | with self.assertRaises(ValueError): 302 | wwvb.WWVBMinute.fromstring("year=1998 days=365 hour=23 min=56 dst=0 ut1=-300 ly=0 ls=1 boo=1") 303 | 304 | def test_update(self) -> None: 305 | """Ensure that the 'maybe_warn_update' function is covered""" 306 | with self.assertWarnsRegex(Warning, "updateiers"): 307 | wwvb._maybe_warn_update(datetime.date(1970, 1, 1)) 308 | wwvb._maybe_warn_update(datetime.datetime(1970, 1, 1, 0, 0, tzinfo=datetime.timezone.utc)) 309 | 310 | def test_undefined(self) -> None: 311 | """Ensure that the check for unset elements in am works""" 312 | with self.assertWarnsRegex(Warning, "is unset"): 313 | str(wwvb.WWVBTimecode(60)) 314 | 315 | def test_tz(self) -> None: 316 | """Get a little more coverage in the dst change functions""" 317 | date, row = wwvb._get_dst_change_date_and_row(datetime.datetime(1960, 1, 1, tzinfo=datetime.timezone.utc)) 318 | self.assertIsNone(date) 319 | self.assertIsNone(row) 320 | 321 | self.assertIsNone(wwvb._get_dst_change_hour(datetime.datetime(1960, 1, 1, tzinfo=datetime.timezone.utc))) 322 | 323 | self.assertEqual(wwvb._get_dst_next(datetime.datetime(1960, 1, 1, tzinfo=datetime.timezone.utc)), 0b000111) 324 | 325 | # Cuba followed year-round DST for several years 326 | self.assertEqual( 327 | wwvb._get_dst_next(datetime.datetime(2005, 1, 1, tzinfo=datetime.timezone.utc), tz=tz.ZoneInfo("Cuba")), 328 | 0b101111, 329 | ) 330 | date, row = wwvb._get_dst_change_date_and_row( 331 | datetime.datetime(2005, 1, 1, tzinfo=datetime.timezone.utc), 332 | tz=tz.ZoneInfo("Cuba"), 333 | ) 334 | self.assertIsNone(date) 335 | self.assertIsNone(row) 336 | 337 | # California was weird in 1948 338 | self.assertEqual( 339 | wwvb._get_dst_next( 340 | datetime.datetime(1948, 1, 1, tzinfo=datetime.timezone.utc), 341 | tz=tz.ZoneInfo("America/Los_Angeles"), 342 | ), 343 | 0b100011, 344 | ) 345 | 346 | # Berlin had DST changes on Monday in 1917 347 | self.assertEqual( 348 | wwvb._get_dst_next( 349 | datetime.datetime(1917, 1, 1, tzinfo=datetime.timezone.utc), 350 | tz=tz.ZoneInfo("Europe/Berlin"), 351 | ), 352 | 0b100011, 353 | ) 354 | 355 | # 356 | # Australia observes DST in the other half of the year compared to the 357 | # Northern hemisphere 358 | self.assertEqual( 359 | wwvb._get_dst_next( 360 | datetime.datetime(2005, 1, 1, tzinfo=datetime.timezone.utc), 361 | tz=tz.ZoneInfo("Australia/Melbourne"), 362 | ), 363 | 0b100011, 364 | ) 365 | 366 | def test_epoch2(self) -> None: 367 | """Test that the settable epoch feature works""" 368 | self.assertEqual(wwvb.WWVBMinute(0, 1, 1, 0, 0).year, 2000) 369 | self.assertEqual(wwvb.WWVBMinute(69, 1, 1, 0, 0).year, 2069) 370 | self.assertEqual(wwvb.WWVBMinute(70, 1, 1, 0, 0).year, 1970) 371 | self.assertEqual(wwvb.WWVBMinute(99, 1, 1, 0, 0).year, 1999) 372 | 373 | # 4-digit years can always be used 374 | self.assertEqual(wwvb.WWVBMinute(2000, 1, 1, 0, 0).year, 2000) 375 | self.assertEqual(wwvb.WWVBMinute(2069, 1, 1, 0, 0).year, 2069) 376 | self.assertEqual(wwvb.WWVBMinute(1970, 1, 1, 0, 0).year, 1970) 377 | self.assertEqual(wwvb.WWVBMinute(1999, 1, 1, 0, 0).year, 1999) 378 | 379 | self.assertEqual(wwvb.WWVBMinute(1900, 1, 1, 0, 0).year, 1900) 380 | self.assertEqual(wwvb.WWVBMinute(1969, 1, 1, 0, 0).year, 1969) 381 | self.assertEqual(wwvb.WWVBMinute(2070, 1, 1, 0, 0).year, 2070) 382 | self.assertEqual(wwvb.WWVBMinute(2099, 1, 1, 0, 0).year, 2099) 383 | 384 | self.assertEqual(WWVBMinute2k(0, 1, 1, 0, 0).year, 2000) 385 | self.assertEqual(WWVBMinute2k(99, 1, 1, 0, 0).year, 2099) 386 | 387 | # 4-digit years can always be used 388 | self.assertEqual(WWVBMinute2k(2000, 1, 1, 0, 0).year, 2000) 389 | self.assertEqual(WWVBMinute2k(2069, 1, 1, 0, 0).year, 2069) 390 | self.assertEqual(WWVBMinute2k(1970, 1, 1, 0, 0).year, 1970) 391 | self.assertEqual(WWVBMinute2k(1999, 1, 1, 0, 0).year, 1999) 392 | 393 | self.assertEqual(WWVBMinute2k(1900, 1, 1, 0, 0).year, 1900) 394 | self.assertEqual(WWVBMinute2k(1969, 1, 1, 0, 0).year, 1969) 395 | self.assertEqual(WWVBMinute2k(2070, 1, 1, 0, 0).year, 2070) 396 | self.assertEqual(WWVBMinute2k(2099, 1, 1, 0, 0).year, 2099) 397 | 398 | def test_invalid_minute(self) -> None: 399 | """Check that minute 61 is not valid in an AM timecode""" 400 | base_minute = wwvb.WWVBMinute(2021, 1, 1, 0, 0) 401 | minute = base_minute.as_timecode() 402 | minute._put_am_bcd(61, 1, 2, 3, 5, 6, 7, 8) # valid BCD, invalid minute 403 | decoded_minute = wwvb.WWVBMinute.from_timecode_am(minute) 404 | assert decoded_minute is None 405 | 406 | def test_invalid_hour(self) -> None: 407 | """Check that hour 25 is not valid in an AM timecode""" 408 | base_minute = wwvb.WWVBMinute(2021, 1, 1, 0, 0) 409 | minute = base_minute.as_timecode() 410 | minute._put_am_bcd(29, 12, 13, 15, 16, 17, 18) # valid BCD, invalid hour 411 | decoded_minute = wwvb.WWVBMinute.from_timecode_am(minute) 412 | assert decoded_minute is None 413 | 414 | def test_invalid_bcd_day(self) -> None: 415 | """Check that invalid BCD is detected in AM timecode""" 416 | base_minute = wwvb.WWVBMinute(2021, 1, 1, 0, 0) 417 | minute = base_minute.as_timecode() 418 | minute.am[30:34] = [wwvb.AmplitudeModulation.ONE] * 4 # invalid BCD 0xf 419 | decoded_minute = wwvb.WWVBMinute.from_timecode_am(minute) 420 | assert decoded_minute is None 421 | 422 | def test_invalid_mark(self) -> None: 423 | """Check that invalid presence of MARK in a data field is detected""" 424 | base_minute = wwvb.WWVBMinute(2021, 1, 1, 0, 0) 425 | minute = base_minute.as_timecode() 426 | minute.am[57] = wwvb.AmplitudeModulation.MARK 427 | decoded_minute = wwvb.WWVBMinute.from_timecode_am(minute) 428 | assert decoded_minute is None 429 | 430 | 431 | if __name__ == "__main__": 432 | unittest.main() 433 | -------------------------------------------------------------------------------- /test/wwvbgen_testcases/1998leapsecond: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Jeff Epler 2 | # 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | WWVB timecode: year=1998 days=365 hour=23 min=56 dst=0 ut1=-300 ly=0 ls=1 6 | 1998-365 23:56 210100110200100001120011001102010100010200110100121000001002 7 | 1998-365 23:57 210100111200100001120011001102010100010200110100121000001002 8 | 1998-365 23:58 210101000200100001120011001102010100010200110100121000001002 9 | 1998-365 23:59 2101010012001000011200110011020101000102001101001210000010022 10 | 1999-001 00:00 200000000200000000020000000002000100101201110100121001000002 11 | 1999-001 00:01 200000001200000000020000000002000100101201110100121001000002 12 | 1999-001 00:02 200000010200000000020000000002000100101201110100121001000002 13 | -------------------------------------------------------------------------------- /test/wwvbgen_testcases/2012leapsecond: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Jeff Epler 2 | # 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | WWVB timecode: year=2012 days=182 hour=23 min=58 dst=3 ut1=-600 ly=1 ls=1 6 | 2012-182 23:58 210101000200100001120001010002001000010201100000120010011112 7 | 2012-182 23:59 2101010012001000011200010100020010000102011000001200100111122 8 | 2012-183 00:00 200000000200000000020001010002001100101201000000120010010112 9 | -------------------------------------------------------------------------------- /test/wwvbgen_testcases/all-headers: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Jeff Epler 2 | # 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | WWVB timecode: year=2021 days=201 hour=23 min=58 dst=3 ut1=-200 ly=0 ls=0 6 | 2021-201 23:58 210101000200100001120010000002000100010200100001020001000112 7 | 8 | WWVB timecode: year=2021 days=201 hour=23 min=59 dst=3 ut1=-200 ly=0 ls=0 9 | 2021-201 23:59 210101001200100001120010000002000100010200100001020001000112 10 | 11 | WWVB timecode: year=2021 days=202 hour=00 min=00 dst=3 ut1=-200 ly=0 ls=0 12 | 2021-202 00:00 200000000200000000020010000002001000010200100001020001000112 13 | 14 | WWVB timecode: year=2021 days=202 hour=00 min=01 dst=3 ut1=-200 ly=0 ls=0 15 | 2021-202 00:01 200000001200000000020010000002001000010200100001020001000112 16 | 17 | WWVB timecode: year=2021 days=202 hour=00 min=02 dst=3 ut1=-200 ly=0 ls=0 18 | 2021-202 00:02 200000010200000000020010000002001000010200100001020001000112 19 | 20 | WWVB timecode: year=2021 days=202 hour=00 min=03 dst=3 ut1=-200 ly=0 ls=0 21 | 2021-202 00:03 200000011200000000020010000002001000010200100001020001000112 22 | 23 | WWVB timecode: year=2021 days=202 hour=00 min=04 dst=3 ut1=-200 ly=0 ls=0 24 | 2021-202 00:04 200000100200000000020010000002001000010200100001020001000112 25 | 26 | WWVB timecode: year=2021 days=202 hour=00 min=05 dst=3 ut1=-200 ly=0 ls=0 27 | 2021-202 00:05 200000101200000000020010000002001000010200100001020001000112 28 | 29 | WWVB timecode: year=2021 days=202 hour=00 min=06 dst=3 ut1=-200 ly=0 ls=0 30 | 2021-202 00:06 200000110200000000020010000002001000010200100001020001000112 31 | 32 | WWVB timecode: year=2021 days=202 hour=00 min=07 dst=3 ut1=-200 ly=0 ls=0 33 | 2021-202 00:07 200000111200000000020010000002001000010200100001020001000112 34 | -------------------------------------------------------------------------------- /test/wwvbgen_testcases/bar: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2022 Jeff Epler 2 | # 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | WWVB timecode: year=2021 days=313 hour=18 min=02 dst=0 ut1=-100 ly=0 ls=0 --style=bar 6 | 2021-313 18:02 🬋🬍🬍🬎🬍🬎🬍🬎🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬋🬍🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬋🬎🬍🬎🬍🬎🬍🬎🬋🬍🬍🬎🬍🬎🬋🬎🬋🬎🬍🬎🬍🬎🬍🬎🬍🬎🬋🬎🬋🬍🬍🬎🬍🬎🬋🬎🬋🬎🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬋🬍🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬋🬍🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬍🬎🬍🬎🬍🬎🬍🬎🬋🬍 7 | 2021-313 18:03 🬋🬍🬍🬎🬍🬎🬍🬎🬍🬎🬍🬎🬍🬎🬋🬎🬋🬎🬋🬍🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬋🬎🬍🬎🬍🬎🬍🬎🬋🬍🬍🬎🬍🬎🬋🬎🬋🬎🬍🬎🬍🬎🬍🬎🬍🬎🬋🬎🬋🬍🬍🬎🬍🬎🬋🬎🬋🬎🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬋🬍🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬋🬍🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬍🬎🬍🬎🬍🬎🬍🬎🬋🬍 8 | 2021-313 18:04 🬋🬍🬍🬎🬍🬎🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬍🬎🬋🬍🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬋🬎🬍🬎🬍🬎🬍🬎🬋🬍🬍🬎🬍🬎🬋🬎🬋🬎🬍🬎🬍🬎🬍🬎🬍🬎🬋🬎🬋🬍🬍🬎🬍🬎🬋🬎🬋🬎🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬋🬍🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬋🬍🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬍🬎🬍🬎🬍🬎🬍🬎🬋🬍 9 | 2021-313 18:05 🬋🬍🬍🬎🬍🬎🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬋🬎🬋🬍🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬋🬎🬍🬎🬍🬎🬍🬎🬋🬍🬍🬎🬍🬎🬋🬎🬋🬎🬍🬎🬍🬎🬍🬎🬍🬎🬋🬎🬋🬍🬍🬎🬍🬎🬋🬎🬋🬎🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬋🬍🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬋🬍🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬍🬎🬍🬎🬍🬎🬍🬎🬋🬍 10 | 2021-313 18:06 🬋🬍🬍🬎🬍🬎🬍🬎🬍🬎🬍🬎🬋🬎🬋🬎🬍🬎🬋🬍🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬋🬎🬍🬎🬍🬎🬍🬎🬋🬍🬍🬎🬍🬎🬋🬎🬋🬎🬍🬎🬍🬎🬍🬎🬍🬎🬋🬎🬋🬍🬍🬎🬍🬎🬋🬎🬋🬎🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬋🬍🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬋🬍🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬍🬎🬍🬎🬍🬎🬍🬎🬋🬍 11 | 2021-313 18:07 🬋🬍🬍🬎🬍🬎🬍🬎🬍🬎🬍🬎🬋🬎🬋🬎🬋🬎🬋🬍🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬋🬎🬍🬎🬍🬎🬍🬎🬋🬍🬍🬎🬍🬎🬋🬎🬋🬎🬍🬎🬍🬎🬍🬎🬍🬎🬋🬎🬋🬍🬍🬎🬍🬎🬋🬎🬋🬎🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬋🬍🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬋🬍🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬍🬎🬍🬎🬍🬎🬍🬎🬋🬍 12 | 2021-313 18:08 🬋🬍🬍🬎🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬍🬎🬍🬎🬋🬍🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬋🬎🬍🬎🬍🬎🬍🬎🬋🬍🬍🬎🬍🬎🬋🬎🬋🬎🬍🬎🬍🬎🬍🬎🬍🬎🬋🬎🬋🬍🬍🬎🬍🬎🬋🬎🬋🬎🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬋🬍🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬋🬍🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬍🬎🬍🬎🬍🬎🬍🬎🬋🬍 13 | 2021-313 18:09 🬋🬍🬍🬎🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬍🬎🬋🬎🬋🬍🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬋🬎🬍🬎🬍🬎🬍🬎🬋🬍🬍🬎🬍🬎🬋🬎🬋🬎🬍🬎🬍🬎🬍🬎🬍🬎🬋🬎🬋🬍🬍🬎🬍🬎🬋🬎🬋🬎🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬋🬍🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬋🬍🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬍🬎🬍🬎🬍🬎🬍🬎🬋🬍 14 | 2021-313 18:10 🬋🬍🬍🬎🬍🬎🬋🬎🬍🬎🬍🬎🬍🬎🬍🬎🬍🬎🬋🬍🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬋🬎🬍🬎🬍🬎🬍🬎🬋🬍🬍🬎🬍🬎🬋🬎🬋🬎🬍🬎🬍🬎🬍🬎🬍🬎🬋🬎🬋🬍🬍🬎🬍🬎🬋🬎🬋🬎🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬋🬍🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬋🬍🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬍🬎🬍🬎🬍🬎🬍🬎🬋🬍 15 | 2021-313 18:11 🬋🬍🬍🬎🬍🬎🬋🬎🬍🬎🬍🬎🬍🬎🬍🬎🬋🬎🬋🬍🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬋🬎🬍🬎🬍🬎🬍🬎🬋🬍🬍🬎🬍🬎🬋🬎🬋🬎🬍🬎🬍🬎🬍🬎🬍🬎🬋🬎🬋🬍🬍🬎🬍🬎🬋🬎🬋🬎🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬋🬍🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬋🬍🬍🬎🬍🬎🬍🬎🬋🬎🬍🬎🬍🬎🬍🬎🬍🬎🬍🬎🬋🬍 16 | -------------------------------------------------------------------------------- /test/wwvbgen_testcases/both: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Jeff Epler 2 | # 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | WWVB timecode: year=2020 days=001 hour=00 min=00 dst=0 ut1=-200 ly=1 ls=0 --channel=both 6 | 2020-001 00:00 200000000200000000020000000002000100010200100001020000010002 7 | 001110110100011111000101000000100000101101000000110000110110 8 | 9 | 2020-001 00:01 200000001200000000020000000002000100010200100001020000010002 10 | 001110110100010110010101000000100000101101000010110000110110 11 | 12 | 2020-001 00:02 200000010200000000020000000002000100010200100001020000010002 13 | 001110110100001101000101000000100000101101000100110000110110 14 | 15 | 2020-001 00:03 200000011200000000020000000002000100010200100001020000010002 16 | 001110110100000100010101000000100000101101000110110000110110 17 | 18 | 2020-001 00:04 200000100200000000020000000002000100010200100001020000010002 19 | 001110110100010010000101000000100000101101001000110000110110 20 | 21 | 2020-001 00:05 200000101200000000020000000002000100010200100001020000010002 22 | 001110110100011011010101000000100000101101001010110000110110 23 | 24 | 2020-001 00:06 200000110200000000020000000002000100010200100001020000010002 25 | 001110110100000000000101000000100000101101001100110000110110 26 | 27 | 2020-001 00:07 200000111200000000020000000002000100010200100001020000010002 28 | 001110110100001001010101000000100000101101001110110000110110 29 | 30 | 2020-001 00:08 200001000200000000020000000002000100010200100001020000010002 31 | 001110110100000101000101000000100000101101010000110000110110 32 | 33 | 2020-001 00:09 200001001200000000020000000002000100010200100001020000010002 34 | 001110110100001100010101000000100000101101010010110000110110 35 | -------------------------------------------------------------------------------- /test/wwvbgen_testcases/cradek: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Jeff Epler 2 | # 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | WWVB timecode: year=2020 days=001 hour=00 min=00 dst=0 ut1=-200 ly=1 ls=0 --style=cradek 6 | 2020-001 00:00 -00000000-000000000-000000000-000100010-001000010-000001000- 7 | 2020-001 00:01 -00000001-000000000-000000000-000100010-001000010-000001000- 8 | 2020-001 00:02 -00000010-000000000-000000000-000100010-001000010-000001000- 9 | 2020-001 00:03 -00000011-000000000-000000000-000100010-001000010-000001000- 10 | 2020-001 00:04 -00000100-000000000-000000000-000100010-001000010-000001000- 11 | 2020-001 00:05 -00000101-000000000-000000000-000100010-001000010-000001000- 12 | 2020-001 00:06 -00000110-000000000-000000000-000100010-001000010-000001000- 13 | 2020-001 00:07 -00000111-000000000-000000000-000100010-001000010-000001000- 14 | 2020-001 00:08 -00001000-000000000-000000000-000100010-001000010-000001000- 15 | 2020-001 00:09 -00001001-000000000-000000000-000100010-001000010-000001000- 16 | -------------------------------------------------------------------------------- /test/wwvbgen_testcases/duration: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Jeff Epler 2 | # 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | WWVB timecode: year=2020 days=001 hour=00 min=00 dst=0 ut1=-200 ly=1 ls=0 --style=duration 6 | 2020-001 00:00 822222222822222222282222222228222522252822522225282222252228 7 | 2020-001 00:01 822222225822222222282222222228222522252822522225282222252228 8 | 2020-001 00:02 822222252822222222282222222228222522252822522225282222252228 9 | 2020-001 00:03 822222255822222222282222222228222522252822522225282222252228 10 | 2020-001 00:04 822222522822222222282222222228222522252822522225282222252228 11 | 2020-001 00:05 822222525822222222282222222228222522252822522225282222252228 12 | 2020-001 00:06 822222552822222222282222222228222522252822522225282222252228 13 | 2020-001 00:07 822222555822222222282222222228222522252822522225282222252228 14 | 2020-001 00:08 822225222822222222282222222228222522252822522225282222252228 15 | 2020-001 00:09 822225225822222222282222222228222522252822522225282222252228 16 | -------------------------------------------------------------------------------- /test/wwvbgen_testcases/enddst-phase: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Jeff Epler 2 | # 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | WWVB timecode: year=2021 days=311 hour=08 min=10 dst=1 ut1=-100 ly=0 ls=0 --channel=phase 6 | 2021-311 08:10 010000110100000111110110000001010110111111100110110101010001 7 | 2021-311 08:11 001001100111100011101110101111010010110010100111001000110001 8 | 2021-311 08:12 011100011010001110101100101100110111000110000101101001110100 9 | 2021-311 08:13 101010000101110001011010110110111111110000001001001000001110 10 | 2021-311 08:14 100011000100111001010011010010111101011101110001111001100100 11 | 2021-311 08:15 100010101011011001111111011010100000011011111000001011000010 12 | 2021-311 08:16 001110110100001110000101011110010111110100100001011010110110 13 | 2021-311 08:17 001110110100000111010101011110010111110100100011011010110110 14 | 2021-311 08:18 001110110100011100000101011110010111110100100101011010110110 15 | 2021-311 08:19 001110110100010101010101011110010111110100100111011010110110 16 | -------------------------------------------------------------------------------- /test/wwvbgen_testcases/enddst-phase-2: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Jeff Epler 2 | # 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | WWVB timecode: year=2021 days=311 hour=11 min=01 dst=1 ut1=-100 ly=0 ls=0 --channel=phase 6 | 2021-311 11:01 001110110100000111010101011110010111111101101011011010110110 7 | 2021-311 11:02 001110110100011100000101011110010111111101101101011010110110 8 | 2021-311 11:03 001110110100010101010101011110010111111101101111011010110110 9 | 2021-311 11:04 001110110100011001000101011110010111111101110001011010110110 10 | 2021-311 11:05 001110110100010000010101011110010111111101110011011010110110 11 | 2021-311 11:06 001110110100001011000101011110010111111101110101011010110110 12 | 2021-311 11:07 001110110100000010010101011110010111111101110111011010110110 13 | 2021-311 11:08 001110110100010100000101011110010111111101111001011010110110 14 | 2021-311 11:09 001110110100011101010101011110010111111101111011011010110110 15 | 2021-311 11:10 111111100110110101010001001001100111100011101110101111010010 16 | -------------------------------------------------------------------------------- /test/wwvbgen_testcases/endleapyear: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Jeff Epler 2 | # 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | WWVB timecode: year=2000 days=366 hour=23 min=58 dst=0 ut1=0 ly=1 ls=0 6 | 2000-366 23:58 210101000200100001120011001102011000101200000000020000010002 7 | 2000-366 23:59 210101001200100001120011001102011000101200000000020000010002 8 | 2001-001 00:00 200000000200000000020000000002000100101200000000020001000002 9 | 2001-001 00:01 200000001200000000020000000002000100101200000000020001000002 10 | -------------------------------------------------------------------------------- /test/wwvbgen_testcases/leapday1: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Jeff Epler 2 | # 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | WWVB timecode: year=2000 days=061 hour=23 min=59 dst=0 ut1=0 ly=1 ls=0 6 | 2000-061 23:59 210101001200100001120000001102000100101200000000020000010002 7 | 2000-062 00:00 200000000200000000020000001102001000101200000000020000010002 8 | 2000-062 00:01 200000001200000000020000001102001000101200000000020000010002 9 | -------------------------------------------------------------------------------- /test/wwvbgen_testcases/leapday28: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Jeff Epler 2 | # 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | WWVB timecode: year=2000 days=059 hour=23 min=59 dst=0 ut1=0 ly=1 ls=0 6 | 2000-059 23:59 210101001200100001120000001012100100101200000000020000010002 7 | 2000-060 00:00 200000000200000000020000001102000000101200000000020000010002 8 | 2000-060 00:01 200000001200000000020000001102000000101200000000020000010002 9 | -------------------------------------------------------------------------------- /test/wwvbgen_testcases/leapday29: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Jeff Epler 2 | # 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | WWVB timecode: year=2000 days=060 hour=23 min=59 dst=0 ut1=0 ly=1 ls=0 6 | 2000-060 23:59 210101001200100001120000001102000000101200000000020000010002 7 | 2000-061 00:00 200000000200000000020000001102000100101200000000020000010002 8 | 2000-061 00:01 200000001200000000020000001102000100101200000000020000010002 9 | -------------------------------------------------------------------------------- /test/wwvbgen_testcases/negleapsecond: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Jeff Epler 2 | # 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | WWVB timecode: year=1998 days=365 hour=23 min=56 dst=0 ut1=500 ly=0 ls=1 6 | 1998-365 23:56 210100110200100001120011001102010100101201010100121000001002 7 | 1998-365 23:57 210100111200100001120011001102010100101201010100121000001002 8 | 1998-365 23:58 210101000200100001120011001102010100101201010100121000001002 9 | 1998-365 23:59 21010100120010000112001100110201010010120101010012100000100 10 | 1999-001 00:00 200000000200000000020000000002000100010201010100121001000002 11 | 1999-001 00:01 200000001200000000020000000002000100010201010100121001000002 12 | 1999-001 00:02 200000010200000000020000000002000100010201010100121001000002 13 | -------------------------------------------------------------------------------- /test/wwvbgen_testcases/nextdst: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Jeff Epler 2 | # 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | WWVB timecode: year=2010 days=073 hour=23 min=58 dst=2 ut1=0 ly=0 ls=0 6 | 2010-073 23:58 210101000200100001120000001112001100101200000000120000000102 7 | 2010-073 23:59 210101001200100001120000001112001100101200000000120000000102 8 | 2010-074 00:00 200000000200000000020000001112010000101200000000120000000112 9 | 2010-074 00:01 200000001200000000020000001112010000101200000000120000000112 10 | 2010-074 00:02 200000010200000000020000001112010000101200000000120000000112 11 | -------------------------------------------------------------------------------- /test/wwvbgen_testcases/nextst: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Jeff Epler 2 | # 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | WWVB timecode: year=2010 days=311 hour=23 min=58 dst=1 ut1=0 ly=0 ls=0 6 | 2010-311 23:58 210101000200100001120011000012000100101200000000120000000012 7 | 2010-311 23:59 210101001200100001120011000012000100101200000000120000000012 8 | 2010-312 00:00 200000000200000000020011000012001000101200000000120000000002 9 | 2010-312 00:01 200000001200000000020011000012001000101200000000120000000002 10 | 2010-312 00:02 200000010200000000020011000012001000101200000000120000000002 11 | -------------------------------------------------------------------------------- /test/wwvbgen_testcases/nonleapday1: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Jeff Epler 2 | # 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | WWVB timecode: year=2001 days=060 hour=23 min=59 dst=0 ut1=0 ly=0 ls=0 6 | 2001-060 23:59 210101001200100001120000001102000000101200000000020001000002 7 | 2001-061 00:00 200000000200000000020000001102000100101200000000020001000002 8 | 2001-061 00:01 200000001200000000020000001102000100101200000000020001000002 9 | -------------------------------------------------------------------------------- /test/wwvbgen_testcases/nonleapday28: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Jeff Epler 2 | # 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | WWVB timecode: year=2001 days=059 hour=23 min=59 dst=0 ut1=0 ly=0 ls=0 6 | 2001-059 23:59 210101001200100001120000001012100100101200000000020001000002 7 | 2001-060 00:00 200000000200000000020000001102000000101200000000020001000002 8 | 2001-060 00:01 200000001200000000020000001102000000101200000000020001000002 9 | -------------------------------------------------------------------------------- /test/wwvbgen_testcases/phase: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Jeff Epler 2 | # 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | WWVB timecode: year=2020 days=001 hour=00 min=00 dst=0 ut1=-200 ly=1 ls=0 --channel=phase 6 | 2020-001 00:00 001110110100011111000101000000100000101101000000110000110110 7 | 2020-001 00:01 001110110100010110010101000000100000101101000010110000110110 8 | 2020-001 00:02 001110110100001101000101000000100000101101000100110000110110 9 | 2020-001 00:03 001110110100000100010101000000100000101101000110110000110110 10 | 2020-001 00:04 001110110100010010000101000000100000101101001000110000110110 11 | 2020-001 00:05 001110110100011011010101000000100000101101001010110000110110 12 | 2020-001 00:06 001110110100000000000101000000100000101101001100110000110110 13 | 2020-001 00:07 001110110100001001010101000000100000101101001110110000110110 14 | 2020-001 00:08 001110110100000101000101000000100000101101010000110000110110 15 | 2020-001 00:09 001110110100001100010101000000100000101101010010110000110110 16 | -------------------------------------------------------------------------------- /test/wwvbgen_testcases/startdst: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Jeff Epler 2 | # 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | WWVB timecode: year=2010 days=072 hour=23 min=58 dst=0 ut1=0 ly=0 ls=0 6 | 2010-072 23:58 210101000200100001120000001112001000101200000000120000000002 7 | 2010-072 23:59 210101001200100001120000001112001000101200000000120000000002 8 | 2010-073 00:00 200000000200000000020000001112001100101200000000120000000102 9 | 2010-073 00:01 200000001200000000020000001112001100101200000000120000000102 10 | 2010-073 00:02 200000010200000000020000001112001100101200000000120000000102 11 | -------------------------------------------------------------------------------- /test/wwvbgen_testcases/startdst-phase: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Jeff Epler 2 | # 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | WWVB timecode: year=2021 days=073 hour=08 min=10 dst=2 ut1=-200 ly=0 ls=0 --channel=phase 6 | 2021-073 08:10 001000011010000011111011000000101011011111110011011010101000 7 | 2021-073 08:11 100100110011110001110111010111101001011001010011100100011000 8 | 2021-073 08:12 101110011010001110101100101100110111000110000101101001110100 9 | 2021-073 08:13 101010000101110001011010110110111111110000001001001000011101 10 | 2021-073 08:14 000110001001110010100110100101111010111011100011110011001001 11 | 2021-073 08:15 000101010110110011111110110101000000110111110000010110000100 12 | 2021-073 08:16 001110110100011000000101010100001001000110100001011100110110 13 | 2021-073 08:17 001110110100010001010101010100001001000110100011011100110110 14 | 2021-073 08:18 001110110100001010000101010100001001000110100101011100110110 15 | 2021-073 08:19 001110110100000011010101010100001001000110100111011100110110 16 | -------------------------------------------------------------------------------- /test/wwvbgen_testcases/startdst-phase-2: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Jeff Epler 2 | # 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | WWVB timecode: year=2021 days=073 hour=02 min=10 dst=2 ut1=-200 ly=0 ls=0 --channel=phase 6 | 2021-073 02:10 111111100110110101010001001001100111100011101110101111010010 7 | 2021-073 02:11 110010100111001000110001011100001000011010000011111011000000 8 | 2021-073 02:12 101011011010001110101100101100110111000110000101101001110100 9 | 2021-073 02:13 101010000101110001011010110110111111110000001001001000110101 10 | 2021-073 02:14 000000110111110000010110000100001110100011000100111001010011 11 | 2021-073 02:15 010010111101011101110001111001100100100010101011011001111111 12 | 2021-073 02:16 001110110100010111000101010100001000101111010001011100110110 13 | 2021-073 02:17 001110110100011110010101010100001000101111010011011100110110 14 | 2021-073 02:18 001110110100000101000101010100001000101111010101011100110110 15 | 2021-073 02:19 001110110100001100010101010100001000101111010111011100110110 16 | -------------------------------------------------------------------------------- /test/wwvbgen_testcases/startleapyear: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Jeff Epler 2 | # 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | WWVB timecode: year=1999 days=365 hour=23 min=58 dst=0 ut1=0 ly=0 ls=0 6 | 1999-365 23:58 210101000200100001120011001102010100101200000100121001000002 7 | 1999-365 23:59 210101001200100001120011001102010100101200000100121001000002 8 | 2000-001 00:00 200000000200000000020000000002000100101200000000020000010002 9 | 2000-001 00:01 200000001200000000020000000002000100101200000000020000010002 10 | -------------------------------------------------------------------------------- /test/wwvbgen_testcases/startst: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Jeff Epler 2 | # 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | WWVB timecode: year=2010 days=310 hour=23 min=58 dst=3 ut1=0 ly=0 ls=0 6 | 2010-310 23:58 210101000200100001120011000012000000101200000000120000000112 7 | 2010-310 23:59 210101001200100001120011000012000000101200000000120000000112 8 | 2010-311 00:00 200000000200000000020011000012000100101200000000120000000012 9 | 2010-311 00:01 200000001200000000020011000012000100101200000000120000000012 10 | 2010-311 00:02 200000010200000000020011000012000100101200000000120000000012 11 | -------------------------------------------------------------------------------- /test/wwvbgen_testcases/y2k: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Jeff Epler 2 | # 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | WWVB timecode: year=1999 days=365 hour=23 min=55 dst=0 ut1=0 ly=0 ls=0 6 | 1999-365 23:55 210100101200100001120011001102010100101200000100121001000002 7 | 1999-365 23:56 210100110200100001120011001102010100101200000100121001000002 8 | 1999-365 23:57 210100111200100001120011001102010100101200000100121001000002 9 | 1999-365 23:58 210101000200100001120011001102010100101200000100121001000002 10 | 1999-365 23:59 210101001200100001120011001102010100101200000100121001000002 11 | 2000-001 00:00 200000000200000000020000000002000100101200000000020000010002 12 | 2000-001 00:01 200000001200000000020000000002000100101200000000020000010002 13 | 2000-001 00:02 200000010200000000020000000002000100101200000000020000010002 14 | 2000-001 00:03 200000011200000000020000000002000100101200000000020000010002 15 | 2000-001 00:04 200000100200000000020000000002000100101200000000020000010002 16 | -------------------------------------------------------------------------------- /test/wwvbgen_testcases/y2k-1: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Jeff Epler 2 | # 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | WWVB timecode: year=1999 days=364 hour=23 min=55 dst=0 ut1=0 ly=0 ls=0 6 | 1999-364 23:55 210100101200100001120011001102010000101200000100121001000002 7 | 1999-364 23:56 210100110200100001120011001102010000101200000100121001000002 8 | 1999-364 23:57 210100111200100001120011001102010000101200000100121001000002 9 | 1999-364 23:58 210101000200100001120011001102010000101200000100121001000002 10 | 1999-364 23:59 210101001200100001120011001102010000101200000100121001000002 11 | 1999-365 00:00 200000000200000000020011001102010100101200000100121001000002 12 | 1999-365 00:01 200000001200000000020011001102010100101200000100121001000002 13 | 1999-365 00:02 200000010200000000020011001102010100101200000100121001000002 14 | 1999-365 00:03 200000011200000000020011001102010100101200000100121001000002 15 | 1999-365 00:04 200000100200000000020011001102010100101200000100121001000002 16 | -------------------------------------------------------------------------------- /test/wwvbgen_testcases/y2k1: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Jeff Epler 2 | # 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | WWVB timecode: year=2000 days=366 hour=23 min=57 dst=0 ut1=0 ly=1 ls=0 6 | 2000-366 23:57 210100111200100001120011001102011000101200000000020000010002 7 | 2000-366 23:58 210101000200100001120011001102011000101200000000020000010002 8 | 2000-366 23:59 210101001200100001120011001102011000101200000000020000010002 9 | 2001-001 00:00 200000000200000000020000000002000100101200000000020001000002 10 | 2001-001 00:01 200000001200000000020000000002000100101200000000020001000002 11 | 2001-001 00:02 200000010200000000020000000002000100101200000000020001000002 12 | -------------------------------------------------------------------------------- /test/wwvbgen_testcases/y2k1-1: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Jeff Epler 2 | # 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | WWVB timecode: year=2000 days=365 hour=23 min=57 dst=0 ut1=0 ly=1 ls=0 6 | 2000-365 23:57 210100111200100001120011001102010100101200000000020000010002 7 | 2000-365 23:58 210101000200100001120011001102010100101200000000020000010002 8 | 2000-365 23:59 210101001200100001120011001102010100101200000000020000010002 9 | 2000-366 00:00 200000000200000000020011001102011000101200000000020000010002 10 | 2000-366 00:01 200000001200000000020011001102011000101200000000020000010002 11 | 2000-366 00:02 200000010200000000020011001102011000101200000000020000010002 12 | --------------------------------------------------------------------------------