1
+ =========
1
2
when 🌐🕐
2
3
=========
3
4
@@ -17,64 +18,106 @@ Scenario
17
18
--------
18
19
19
20
Your favorite sporting event, concert, performance, conference, or symposium is happening
20
- in Ulan Bator and all you know is the time of event is relative to the location city or time zone.
21
- But wait! You need to know when that occurs relative to you while traveling to Seoul or Paris.
21
+ in Ulan Bator and all you know is the time of event relative to the city or time zone.
22
+ So what time is that for you in your local time? What time did it or will it occur at some
23
+ other time? What about for your friends in other locations around the world?
24
+
25
+ Features
26
+ --------
27
+
28
+ ``when `` can refer to source and target locations via the ``--source `` and ``--target `` specifiers.
29
+
30
+ * ``when `` can download a GeoNames _ cities database for referencing locations by city name
31
+ * All IANA time zone definitions are available, as well as the most common time zone aliases (i.e.: ``EST `` => ``US/Eastern ``)
32
+ * Display current lunar state
33
+ * List common holidays for a given country and/or year (US or configurable)
34
+ * Show dates for full moons
35
+ * Extensive configuration options for results
36
+ * JSON output
22
37
23
38
Installation
24
- ------------
39
+ ============
25
40
26
- Install from PyPI::
41
+ Install from PyPI:
42
+
43
+ .. code :: bash
27
44
28
45
$ pip install when
29
46
30
- or using pipx _::
47
+ or using pipx _:
48
+
49
+ .. code :: bash
31
50
32
51
$ pipx install when
33
52
34
- or::
53
+ or:
54
+
55
+ .. code :: bash
35
56
36
57
$ pipx install git+https://github.com/dakrauth/when.git
37
58
38
- .. _pipx : https://pypa.github.io/pipx/
59
+ .. note ::
60
+
61
+ Once installed, if you wish to utilize ``when ``'s full capabilities, you should
62
+ install the GeoNames cities database as describe next.
63
+
64
+
65
+
66
+ Database installation
67
+ ---------------------
39
68
40
- To access city names, you must install the cities database::
69
+ To access city names, you need to install the cities database after installing the ``when `` application:
70
+
71
+ .. code :: bash
41
72
42
73
when --db [options]
43
74
44
- For ``options ``:
75
+ Where ``options `` are:
76
+
77
+ * ``--db-size ``: You can specify a database down size by using one of the following:
78
+ - ``sm `` - cities with population > 15,000 + country capitals (~2.9M download, ~2M DB)
79
+ - ``md `` - **default **, same as ``sm ``, plus:
80
+ - cities with population > 5,000 (~4.8M download, ~3.1M DB)
81
+ - seat of first-order admin division, i.e. US state
82
+ - ``lg `` - same as ``md ``, plus:
83
+ - cities with population > 1,000 (~9.5M download, ~5.8M DB)
84
+ - seat of admin division down to third level (counties)
85
+ - ``xl `` - same as ``lg ``, plus:
86
+ - cities with population > 500 (~12.1M download, ~7.2M DB)
87
+ - seat of admin division down to fourth order
88
+ * ``--db-pop ``: Filter non-admin division seats providing a minimum city population size
89
+ * ``--db-force ``: Force an existing database to be overwritten
45
90
46
- You can specify minimum city size by adding ``--size SIZE ``, where *SIZE * can be one of:
91
+ Database Usage
92
+ ==============
47
93
48
- - ``15000 `` - cities with population > 15000 or country capitals
49
- - ``5000 `` - cities with population > 5000 or seat of first-order admin division, i.e. US state
50
- - ``1000 `` - cities with population > 1000 or seat of third order admin division
51
- - ``500 `` - cities with population > 500 or seat of fourth-order admin division
94
+ * Search: ``--db-search ``
52
95
53
- Additionally, you can filter non-admin division seats using `` --pop POP ``.
96
+ Once installed, you can search the database:
54
97
55
- The appropriate GeoNames Gazetteer is downloaded and a Sqlite database generated.
98
+ .. code :: bash
56
99
57
- Usage
58
- -----
100
+ $ when --db-search New York
101
+ 5106292, West New York, West New York, US, New Jersey, America/New_York
102
+ 5128581, New York City, New York City, US, New York, America/New_York
59
103
60
- Once installed, you can search the database::
104
+ * Aliases: `` --db-alias ``
61
105
62
- $ when --db- search New York
63
- 5106292, West New York, West New York, US, New Jersey, America/New_York
64
- 5128581, New York City, New York City, US, New York, America/New_York
106
+ You can add aliases for easier search. In the example directly above, we see that New York City has
107
+ a GeoNames ID of 5128581. Pass that to the `` --db-alias `` option along with another name that
108
+ you would like to use:
65
109
110
+ .. code :: bash
66
111
67
- Additionally, you can add aliases. In the example directly above, we see that New York City has
68
- a GeoNames ID of 5128581. Pass that to the `` --db-alias `` option along with another name that
69
- you would like to use::
112
+ $ when --db-alias 5128581 NYC
113
+ $ when --source NYC
114
+ 2023-07-06 07:58:33-0400 (EDT, America/New_York) 187d27w (New York City, New York, US)[🌕 Full Moon]
70
115
71
- $ when --db-alias 5128581 NYC
72
- $ when --source NYC
73
- 2023-07-06 07:58:33-0400 (EDT, America/New_York) 187d27w (New York City, New York, US)[🌕 Full Moon]
116
+ * Alias listing: ``--db-aliases ``
74
117
75
118
76
- Example
77
- -------
119
+ Examples
120
+ ========
78
121
79
122
For the sake of clarity, in the following examples I am in Seoul, Korea.
80
123
@@ -101,24 +144,100 @@ For the sake of clarity, in the following examples I am in Seoul, Korea.
101
144
1945-03-07 22:00:00-0400 (EWT, America/New_York) 066d10w [🌘 Waning Crescent]
102
145
103
146
104
- Develop
105
- -------
147
+ Development
148
+ ===========
106
149
107
- Requirements Python 3.10+. Also, [just](https://github.com/casey/just) for convenience.
150
+ Requires Python 3.10+ and just _ for convenience.
108
151
109
152
.. code :: bash
110
153
111
154
$ git clone git@github.com:dakrauth/when.git
112
155
$ cd when
113
- $ just
114
- $ just venv
156
+ $ just # or just help
157
+
158
+ Set up dev env:
159
+
160
+ .. code :: bash
161
+
162
+ $ just init
163
+
164
+ Test, and code coverage:
165
+
166
+ .. code :: bash
167
+
115
168
$ just test
169
+ $ just cov
170
+
171
+ Only run a test matching matching a given substring:
172
+
173
+ .. code :: bash
174
+
175
+ $ just test -k test_sometest
176
+
177
+ Interactive development:
178
+
179
+ .. code :: bash
180
+
116
181
$ . ./venv/bin/activate
117
182
$ when --help
118
183
$ when --db
119
184
120
185
Further Reading
121
- ---------------
186
+ ===============
187
+
188
+ `Time Zones Aren’t Offsets – Offsets Aren’t Time Zones `_
189
+
190
+ .. _pipx : https://pypa.github.io/pipx/
191
+ .. _just : https://github.com/casey/just
192
+ .. _`Time Zones Aren’t Offsets – Offsets Aren’t Time Zones` : https://spin.atomicobject.com/time-zones-offsets/)
193
+ .. _GeoNames : https://www.geonames.org/export/
194
+
195
+ Complete Usage
196
+ ==============
197
+
198
+ .. code :: bash
199
+
200
+ usage: when [--delta {long,short}] [--offset [+-]? (\d +wdhm)+] [-h] [--prefix] [-s SOURCE] [-t TARGET] [-f FORMAT] [-g] [--all]
201
+ [--holidays COUNTRY_CODE] [-v] [-V] [--json] [--config] [--db] [--db-force] [--db-search] [--exact] [--db-alias DB_ALIAS]
202
+ [--db-aliases] [--db-size DB_SIZE] [--db-pop DB_POP] [--tz-alias] [--fullmoon]
203
+ [timestr ...]
204
+
205
+ Convert times to and from time zones or cities
206
+
207
+ positional arguments:
208
+ timestr Timestamp to parse, defaults to local time
209
+
210
+ options:
211
+ --delta {long,short} Show the delta to the given timestamp
212
+ --offset [+-]? (\d +wdhm)+
213
+ Show the difference from a given offset
214
+ -h, --help Show helpful usage information
215
+ --prefix Show when' s directory
216
+ -s SOURCE, --source SOURCE
217
+ Timezone / city to convert the timestr from, defaulting to local time
218
+ -t TARGET, --target TARGET
219
+ Timezone / city to convert the timestr to (globbing patterns allowed, can be comma delimited), defaulting to local
220
+ time
221
+ -f FORMAT, --format FORMAT
222
+ Output formatting. Additional formats can be shown using the -v option with -h
223
+ -g, --group Group sources together under same target results
224
+ --all Show times in all common timezones
225
+ --holidays COUNTRY_CODE
226
+ Show holidays for given country code.
227
+ -v, --verbosity Verbosity (-v, -vv, etc). Use -v to show `when` extension detailed help
228
+ -V, --version show program' s version number and exit
229
+ --json Output results in nicely formatted JSON
230
+ --config Toggle config mode. With no other option, dump current configuration settings
231
+ --db Create cities database, used with --db-size and --db-pop
232
+ --db-force Force an existing database to be overwritten
233
+ --db-search Search database for the given city
234
+ --exact DB searches must be exact
235
+ --db-alias DB_ALIAS Create a new alias from the city id
236
+ --db-aliases Show all DB aliases
237
+ --db-size DB_SIZE Geonames file size. Can be one of ' xl' (' xlarge' ), ' lg' (' large' ), ' md' (' medium' ), ' sm' (' small' ).
238
+ --db-pop DB_POP City population minimum.
239
+ --tz-alias Search for a time zone alias
240
+ --fullmoon Show full moon(s) for given year or month. Can be in the format of: ' next' | ' prev' | YYYY[-MM]
241
+
242
+ Use -v option for details
122
243
123
- [Time Zones Aren’t Offsets – Offsets Aren’t Time Zones
124
- ](https://spin.atomicobject.com/time-zones-offsets/)
0 commit comments