zone 0.1.1 → 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 +4 -4
- data/CHANGELOG.md +77 -0
- data/README.md +122 -27
- data/TEST_PLAN.md +911 -0
- data/completions/README.md +126 -0
- data/completions/_zone +89 -0
- data/docs/user-experience-review.md +150 -0
- data/exe/zone +2 -265
- data/lib/zone/cli.rb +64 -0
- data/lib/zone/colors.rb +179 -0
- data/lib/zone/field.rb +67 -0
- data/lib/zone/field_line.rb +97 -0
- data/lib/zone/field_mapping.rb +51 -0
- data/lib/zone/input.rb +52 -0
- data/lib/zone/logging.rb +38 -0
- data/lib/zone/options.rb +142 -0
- data/lib/zone/output.rb +39 -0
- data/lib/zone/pattern.rb +59 -0
- data/lib/zone/timestamp.rb +138 -0
- data/lib/zone/timestamp_patterns.rb +169 -0
- data/lib/zone/transform.rb +69 -0
- data/lib/zone/version.rb +1 -1
- data/lib/zone.rb +45 -1
- data/todo.md +85 -0
- metadata +19 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8be1f2c6eebecd142bfd5ef95bd1fefbe02a4cc2e873caa61f7ddeb837b28eff
|
|
4
|
+
data.tar.gz: a318b8c2d32fd77f89aa2aacdf39eb01ee04218c4a5bd3e68312dcf24bbe2a67
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
@@ -3,18 +3,22 @@
|
|
|
3
3
|
Timezone conversion and datetime formatting for the command line
|
|
4
4
|
|
|
5
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
|
+
|
|
6
10
|
# Fuzzy timezone matching
|
|
7
11
|
zone --zone tokyo 2025-11-05T02:40:32+00:00
|
|
8
|
-
# => 2025-11
|
|
12
|
+
# => Nov 05, 2025 - 11:40 AM JST
|
|
9
13
|
|
|
10
|
-
# Process CSV timestamps
|
|
11
|
-
cat data.csv | zone --
|
|
14
|
+
# Process CSV timestamps (field mode)
|
|
15
|
+
cat data.csv | zone --field 3 --delimiter ',' --zone pacific
|
|
12
16
|
# => customer,purchase_date,amount
|
|
13
|
-
# => alice,42.00,Nov 04 -
|
|
17
|
+
# => alice,42.00,Nov 04, 2025 - 6:40 PM PST
|
|
14
18
|
|
|
15
|
-
# Make logs readable
|
|
16
|
-
tail -f app.log | zone
|
|
17
|
-
# => Nov 04 -
|
|
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
|
|
18
22
|
```
|
|
19
23
|
|
|
20
24
|
## Installation
|
|
@@ -29,21 +33,62 @@ Or with Bundler:
|
|
|
29
33
|
bundle add zone
|
|
30
34
|
```
|
|
31
35
|
|
|
36
|
+
## How It Works
|
|
37
|
+
|
|
38
|
+
Zone operates in two modes:
|
|
39
|
+
|
|
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.
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
echo "Event at 2025-01-15T10:30:00Z completed" | zone --pretty
|
|
44
|
+
# => Event at Jan 15, 2025 - 10:30 AM UTC completed
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
**Field Mode (Explicit)**: Splits lines by delimiter, converts a specific field, then rejoins. Use this for structured data like CSV or TSV files.
|
|
48
|
+
|
|
49
|
+
```bash
|
|
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
|
|
61
|
+
```
|
|
62
|
+
|
|
32
63
|
## Usage
|
|
33
64
|
|
|
34
65
|
Convert timezones:
|
|
35
66
|
|
|
36
67
|
```bash
|
|
37
68
|
zone --zone 'New York' '2025-11-05T02:40:32+00:00'
|
|
38
|
-
# => 2025-
|
|
69
|
+
# => Nov 04, 2025 - 9:40 PM EST
|
|
39
70
|
```
|
|
40
71
|
|
|
41
72
|
Change formats:
|
|
42
73
|
|
|
43
74
|
```bash
|
|
44
|
-
|
|
45
|
-
|
|
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
|
|
46
86
|
|
|
87
|
+
# Unix timestamp
|
|
88
|
+
zone --unix '2025-01-15T10:30:00Z'
|
|
89
|
+
# => 1736937000
|
|
90
|
+
|
|
91
|
+
# Custom format
|
|
47
92
|
zone --strftime '%Y-%m-%d %H:%M' '2025-11-05T02:40:32+00:00'
|
|
48
93
|
# => 2025-11-05 02:40
|
|
49
94
|
```
|
|
@@ -51,11 +96,15 @@ zone --strftime '%Y-%m-%d %H:%M' '2025-11-05T02:40:32+00:00'
|
|
|
51
96
|
Process structured data:
|
|
52
97
|
|
|
53
98
|
```bash
|
|
54
|
-
# Convert column 2
|
|
55
|
-
cat events.csv | zone --
|
|
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
|
|
56
104
|
|
|
57
|
-
#
|
|
58
|
-
zone --
|
|
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
|
|
59
108
|
```
|
|
60
109
|
|
|
61
110
|
Multiple timestamps:
|
|
@@ -71,43 +120,89 @@ zone 1730772120 1730858520 1730944920 --zone tokyo --pretty
|
|
|
71
120
|
|
|
72
121
|
**Output Formats**
|
|
73
122
|
|
|
74
|
-
-
|
|
123
|
+
- `-p, --pretty [STYLE]` - Pretty format (1=12hr, 2=24hr, 3=ISO-compact, default: 1)
|
|
124
|
+
- `--iso8601` - ISO 8601 format
|
|
75
125
|
- `--unix` - Unix timestamp
|
|
76
|
-
- `--
|
|
77
|
-
- `--strftime FORMAT` - Custom format
|
|
126
|
+
- `--strftime FORMAT` - Custom strftime format
|
|
78
127
|
|
|
79
128
|
**Timezones**
|
|
80
129
|
|
|
81
|
-
- `--zone TZ` - Convert to timezone (fuzzy matching)
|
|
130
|
+
- `--zone TZ` - Convert to timezone (fuzzy matching, default: local)
|
|
82
131
|
- `--utc` - Convert to UTC
|
|
83
|
-
- `--local` - Convert to local time
|
|
132
|
+
- `--local` - Convert to local time (default)
|
|
84
133
|
|
|
85
134
|
**Data Processing**
|
|
86
135
|
|
|
87
|
-
- `--
|
|
88
|
-
- `--delimiter PATTERN` - Field separator (
|
|
89
|
-
- `--headers` - Skip first line
|
|
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)
|
|
90
139
|
|
|
91
140
|
**Other**
|
|
92
141
|
|
|
142
|
+
- `--color MODE` - Colorize output (auto, always, never, default: auto)
|
|
93
143
|
- `--verbose` - Show debug output
|
|
94
144
|
- `--help` - Show help
|
|
95
145
|
|
|
96
146
|
## Examples
|
|
97
147
|
|
|
98
|
-
|
|
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:
|
|
99
171
|
|
|
100
172
|
```bash
|
|
101
|
-
|
|
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
|
|
102
182
|
```
|
|
103
183
|
|
|
104
|
-
|
|
184
|
+
**Idempotent Conversions**: Chain zone commands together:
|
|
105
185
|
|
|
106
186
|
```bash
|
|
107
|
-
|
|
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
|
|
108
203
|
```
|
|
109
204
|
|
|
110
|
-
Quick
|
|
205
|
+
**Quick Conversions**:
|
|
111
206
|
|
|
112
207
|
```bash
|
|
113
208
|
zone --zone berlin "3pm PST"
|