zone 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ec4bf54c71190831471974566598f5f99d1398588eb781d6bf05d5b09e8d208b
4
- data.tar.gz: b2984b02b1e3b384bfc2593e3f24e9fb79507eec7bd7b4fa33981023b2daeda7
3
+ metadata.gz: 8be1f2c6eebecd142bfd5ef95bd1fefbe02a4cc2e873caa61f7ddeb837b28eff
4
+ data.tar.gz: a318b8c2d32fd77f89aa2aacdf39eb01ee04218c4a5bd3e68312dcf24bbe2a67
5
5
  SHA512:
6
- metadata.gz: 1ab5600b1439b2ff8692eaa08baf9c8687978f5c8c9e3639d1031c509fb45db59379f77359d76274c8030ca02bb7589c57ebf3692867a55188567a3c39b8c6a6
7
- data.tar.gz: 2223d049e9c21f2805c0ab411c9623a11fd5da50a05d742e48d9dfc0edff90a2fe8481db551d3f46a19f09103a35156a0b91d89419fc553ac18b1d18ddb824e9
6
+ metadata.gz: 5ed2ddc6514b9b5de43eafb0ebdde0b4b841d0ef94446dd2b1a794abe858dd443755699ac92ee070856f461e9e7c8fd72e018822989faf246cbe0b30eba84d15
7
+ data.tar.gz: 91b2edc5636d550b133de5d78372ae3b2e5103a9fd56cce8a28c719ef4e655d54a52f4db1eee278be6a61bccd22ac35aa12e521df1258dc7d7c6ab317c473f18
data/CHANGELOG.md CHANGED
@@ -1,5 +1,82 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ### Added
4
+
5
+ #### --color Flag
6
+ Added `--color` flag with three modes for controlling ANSI color output:
7
+ - `auto` (default): Colors when stdout is a TTY device
8
+ - `always`: Always show colors (useful for piping to `less -R`)
9
+ - `never`: Never show colors (useful for scripting and CI)
10
+
11
+ Both pattern mode and field mode now respect this setting and colorize converted timestamps in cyan.
12
+
13
+ #### Pretty Format Variants
14
+ Implemented `-p [STYLE]` / `--pretty [STYLE]` with three preset formats:
15
+ - `-p 1`: `Jan 15, 2025 - 10:30 AM EST` (12-hour with AM/PM) - default
16
+ - `-p 2`: `Jan 15, 2025 - 22:30 EST` (24-hour for international users)
17
+ - `-p 3`: `2025-01-15 22:30 EST` (ISO-style compact, sortable)
18
+
19
+ All three formats include the year and timezone abbreviation, emphasizing zone's core conversion feature over simple formatting.
20
+
21
+ ### Changed
22
+
23
+ #### New Defaults for Better UX
24
+ - **Default format**: Changed from ISO8601 to pretty format 1 (12-hour with AM/PM)
25
+ - **Default timezone**: Changed from UTC to local timezone
26
+
27
+ These changes give new users immediate visual feedback, showing the tool's value on first use. Users running `zone "2025-01-15T10:30:00Z"` now see their local time in a readable format instead of unchanged ISO8601.
28
+
29
+ #### Updated Pattern Matching
30
+ - Added patterns for all three pretty output formats (P03-P05)
31
+ - Renumbered unix timestamp pattern to P06
32
+ - Renumbered relative time pattern to P07
33
+ - Zone maintains full idempotency: can parse all its own output formats
34
+
35
+ ### Technical Details
36
+
37
+ **Files Modified:**
38
+ - `lib/zone/timestamp.rb`: Updated `to_pretty(style)` to accept style parameter (1/2/3)
39
+ - `lib/zone/timestamp_patterns.rb`: Added P03-P05 patterns for pretty formats, updated validation
40
+ - `lib/zone/cli.rb`:
41
+ - Added `--color` option with auto/always/never modes
42
+ - Added `colorize(stream)` helper method
43
+ - Changed default timezone from UTC to local
44
+ - Changed default format from ISO8601 to pretty1
45
+ - Updated `determine_format_method` to handle pretty style variants
46
+ - Added color support to field mode output via `sub()` replacement
47
+ - `README.md`: Updated all examples, options, and documentation
48
+
49
+ **Backward Compatibility:**
50
+ - This is a **breaking change** for scripts that relied on default ISO8601/UTC output
51
+ - Users who want the old behavior should explicitly specify `--iso8601 --utc`
52
+ - The `--pretty` flag behavior changed from a boolean to accepting an optional integer style
53
+
54
+ **Testing Verified:**
55
+ - ✓ All three pretty formats produce correct output
56
+ - ✓ Default behavior shows pretty1 with local timezone
57
+ - ✓ Color modes work correctly (auto/always/never)
58
+ - ✓ Field mode colorizes transformed timestamps
59
+ - ✓ Idempotency maintained: zone can parse its own output
60
+ - ✓ Pattern matching recognizes all zone output formats
61
+
62
+ ### Rationale
63
+
64
+ **Why these three formats?**
65
+
66
+ 1. **Format 1 (12hr)**: Most readable for North American users, matches human conversation style
67
+ 2. **Format 2 (24hr)**: International standard, technical contexts, no AM/PM ambiguity
68
+ 3. **Format 3 (ISO-compact)**: Sortable, structured, good for logs and data processing
69
+
70
+ All formats prioritize **conversion** (showing timezone) over pure **formatting** (date-only output), aligning with the tool's name and purpose.
71
+
72
+ **Why default to local timezone?**
73
+
74
+ The principle of least surprise: users running timezone conversion tools expect to see their local time. UTC is correct for APIs and storage, but humans think in local time. Power users who need UTC will specify `--utc` explicitly.
75
+
76
+ **Why default to pretty format?**
77
+
78
+ Immediate visual feedback shows the tool working. Seeing "Jan 15, 2025 - 10:30 AM EST" is instantly recognizable as a timestamp conversion. ISO8601 output looks identical to input for many timestamps, giving no feedback that anything happened.
79
+
3
80
  ## [0.1.0] - 2025-11-04
4
81
 
5
82
  - Initial release
data/README.md CHANGED
@@ -1,39 +1,234 @@
1
1
  # Zone
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
3
+ Timezone conversion and datetime formatting for the command line
4
4
 
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/zone`. To experiment with that code, run `bin/console` for an interactive prompt.
5
+ ```bash
6
+ # Convert to your local timezone (default behavior)
7
+ zone 2025-11-05T02:40:32+00:00
8
+ # => Nov 05, 2025 - 9:40 PM EST
9
+
10
+ # Fuzzy timezone matching
11
+ zone --zone tokyo 2025-11-05T02:40:32+00:00
12
+ # => Nov 05, 2025 - 11:40 AM JST
13
+
14
+ # Process CSV timestamps (field mode)
15
+ cat data.csv | zone --field 3 --delimiter ',' --zone pacific
16
+ # => customer,purchase_date,amount
17
+ # => alice,42.00,Nov 04, 2025 - 6:40 PM PST
18
+
19
+ # Make logs readable (pattern mode - default)
20
+ tail -f app.log | zone
21
+ # => Nov 04, 2025 - 9:15 PM EST [ERROR] Database connection timeout
22
+ ```
6
23
 
7
24
  ## Installation
8
25
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
26
+ ```bash
27
+ gem install zone
28
+ ```
29
+
30
+ Or with Bundler:
31
+
32
+ ```bash
33
+ bundle add zone
34
+ ```
35
+
36
+ ## How It Works
37
+
38
+ Zone operates in two modes:
10
39
 
11
- Install the gem and add to the application's Gemfile by executing:
40
+ **Pattern Mode (Default)**: Finds and converts timestamps in arbitrary text. Zone automatically detects timestamps using smart regex patterns and updates them in place. This is like `bat` for timestamps - text goes in, formatted timestamps come out.
12
41
 
13
42
  ```bash
14
- bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
43
+ echo "Event at 2025-01-15T10:30:00Z completed" | zone --pretty
44
+ # => Event at Jan 15, 2025 - 10:30 AM UTC completed
15
45
  ```
16
46
 
17
- If bundler is not being used to manage dependencies, install the gem by executing:
47
+ **Field Mode (Explicit)**: Splits lines by delimiter, converts a specific field, then rejoins. Use this for structured data like CSV or TSV files.
18
48
 
19
49
  ```bash
20
- gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
50
+ echo "alice,1736937000,active" | zone --field 2 --delimiter ',' --pretty
51
+ # => alice,Jan 15, 2025 - 10:30 AM UTC,active
52
+ ```
53
+
54
+ Field mode requires both `--field` and `--delimiter` flags.
55
+
56
+ **Idempotency**: Zone can parse its own output formats, so you can pipe zone output back through zone:
57
+
58
+ ```bash
59
+ zone "2025-01-15T10:30:00Z" --pretty | zone --unix
60
+ # => 1736937000
21
61
  ```
22
62
 
23
63
  ## Usage
24
64
 
25
- TODO: Write usage instructions here
65
+ Convert timezones:
66
+
67
+ ```bash
68
+ zone --zone 'New York' '2025-11-05T02:40:32+00:00'
69
+ # => Nov 04, 2025 - 9:40 PM EST
70
+ ```
71
+
72
+ Change formats:
73
+
74
+ ```bash
75
+ # Pretty format 1: 12-hour with AM/PM (default)
76
+ zone -p 1 '2025-01-15T10:30:00Z'
77
+ # => Jan 15, 2025 - 10:30 AM UTC
78
+
79
+ # Pretty format 2: 24-hour
80
+ zone -p 2 '2025-01-15T10:30:00Z'
81
+ # => Jan 15, 2025 - 10:30 UTC
82
+
83
+ # Pretty format 3: ISO-compact
84
+ zone -p 3 '2025-01-15T10:30:00Z'
85
+ # => 2025-01-15 10:30 UTC
86
+
87
+ # Unix timestamp
88
+ zone --unix '2025-01-15T10:30:00Z'
89
+ # => 1736937000
90
+
91
+ # Custom format
92
+ zone --strftime '%Y-%m-%d %H:%M' '2025-11-05T02:40:32+00:00'
93
+ # => 2025-11-05 02:40
94
+ ```
95
+
96
+ Process structured data:
97
+
98
+ ```bash
99
+ # Convert column 2 with explicit delimiter
100
+ cat events.csv | zone --field 2 --delimiter ',' --zone UTC
101
+
102
+ # Skip header row, use tab delimiter
103
+ zone --field 2 --delimiter '\t' --headers < data.tsv
104
+
105
+ # Regex delimiter (outputs as tabs)
106
+ echo "alice 1736937000 active" | zone --field 2 --delimiter '/\s+/' --pretty
107
+ # => alice Jan 15, 2025 - 10:30 AM UTC active
108
+ ```
109
+
110
+ Multiple timestamps:
111
+
112
+ ```bash
113
+ zone 1730772120 1730858520 1730944920 --zone tokyo --pretty
114
+ # => Nov 05 - 11:42 AM JST
115
+ # => Nov 06 - 11:42 AM JST
116
+ # => Nov 07 - 11:42 AM JST
117
+ ```
118
+
119
+ ## Options
120
+
121
+ **Output Formats**
122
+
123
+ - `-p, --pretty [STYLE]` - Pretty format (1=12hr, 2=24hr, 3=ISO-compact, default: 1)
124
+ - `--iso8601` - ISO 8601 format
125
+ - `--unix` - Unix timestamp
126
+ - `--strftime FORMAT` - Custom strftime format
26
127
 
27
- ## Development
128
+ **Timezones**
28
129
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
130
+ - `--zone TZ` - Convert to timezone (fuzzy matching, default: local)
131
+ - `--utc` - Convert to UTC
132
+ - `--local` - Convert to local time (default)
133
+
134
+ **Data Processing**
135
+
136
+ - `--field N` - Field index or name to convert (requires --delimiter)
137
+ - `--delimiter PATTERN` - Field separator (string or /regex/)
138
+ - `--headers` - Skip first line as headers (requires --field)
139
+
140
+ **Other**
141
+
142
+ - `--color MODE` - Colorize output (auto, always, never, default: auto)
143
+ - `--verbose` - Show debug output
144
+ - `--help` - Show help
145
+
146
+ ## Examples
147
+
148
+ **Pattern Mode**: Find and convert timestamps in arbitrary text:
149
+
150
+ ```bash
151
+ # Logs with embedded timestamps (converts to local time by default)
152
+ grep "ERROR" app.log | zone
153
+
154
+ # Multiple timestamps per line
155
+ echo "Start: 1736937000, End: 1736940600" | zone
156
+ # => Start: Jan 15, 2025 - 5:30 AM EST, End: Jan 15, 2025 - 6:30 AM EST
157
+
158
+ # Use different pretty formats
159
+ echo "Event: 2025-01-15T10:30:00Z" | zone -p 2
160
+ # => Event: Jan 15, 2025 - 10:30 UTC
161
+
162
+ echo "Event: 2025-01-15T10:30:00Z" | zone -p 3
163
+ # => Event: 2025-01-15 10:30 UTC
164
+
165
+ # Mixed formats in same line
166
+ echo "Logged in at 2025-01-15T10:30:00Z (1736937000)" | zone --unix
167
+ # => Logged in at 1736937000 (1736937000)
168
+ ```
169
+
170
+ **Field Mode**: Convert specific columns in structured data:
171
+
172
+ ```bash
173
+ # CSV with explicit delimiter
174
+ cat trades.csv | zone --field 3 --delimiter ',' --zone 'New York' -p 2
175
+
176
+ # Tab-separated with headers
177
+ zone --field timestamp --delimiter '\t' --headers < data.tsv
178
+
179
+ # Regex delimiter
180
+ echo "alice 1736937000 active" | zone --field 2 --delimiter '/\s+/'
181
+ # => alice Jan 15, 2025 - 5:30 AM EST active
182
+ ```
183
+
184
+ **Idempotent Conversions**: Chain zone commands together:
185
+
186
+ ```bash
187
+ # Convert format multiple times
188
+ zone "2025-01-15T10:30:00Z" -p 2 | zone --unix | zone --zone tokyo
189
+ # => Jan 15, 2025 - 19:30 JST
190
+
191
+ # Process zone's own output
192
+ zone "now" | zone --zone berlin -p 3
193
+ ```
194
+
195
+ **Color Control**:
196
+
197
+ ```bash
198
+ # Force colors even when piping
199
+ zone "2025-01-15T10:30:00Z" --color always | less -R
200
+
201
+ # Disable colors for scripting
202
+ zone "2025-01-15T10:30:00Z" --color never
203
+ ```
204
+
205
+ **Quick Conversions**:
206
+
207
+ ```bash
208
+ zone --zone berlin "3pm PST"
209
+ # => 2025-11-05T00:00:00+01:00
210
+
211
+ zone --zone pacific now
212
+ # => 2025-11-04T16:42:15-08:00
213
+ ```
214
+
215
+ ## Timezone Matching
216
+
217
+ Zone uses fuzzy matching for timezone names:
218
+
219
+ ```bash
220
+ zone --zone pacific # => US/Pacific
221
+ zone --zone tokyo # => Asia/Tokyo
222
+ zone --zone europe # => Europe/London (first match)
223
+ zone --zone 'US/Eastern' # => US/Eastern (exact match)
224
+ ```
30
225
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
226
+ Use `--verbose` to see which timezone was matched.
32
227
 
33
228
  ## Contributing
34
229
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/gillisd/zone.
230
+ Bug reports and pull requests are welcome on [GitHub](https://github.com/gillisd/zone).
36
231
 
37
232
  ## License
38
233
 
39
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
234
+ [MIT License](https://opensource.org/licenses/MIT)