date_by_example 0.1.0 → 0.2.0

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: 8467f9d24308479efdaf1fd7a0e1071f3fe37c97c90b36386153f72348ad0c92
4
- data.tar.gz: 5013f2e7a18cdcdf3f13ab21b1bb47981850a42934704f72aa9fd91fd3e646d2
3
+ metadata.gz: 1121705e8d1587de4002f86445d53f1e4275879d1902bc5c477e053d3aae87f8
4
+ data.tar.gz: b7d1c8d8123ceff5dce0486c228f7db23670162b775c55357fa8fd9cb8320906
5
5
  SHA512:
6
- metadata.gz: 1560b2ef198d33fed16adfa0efedc8477691b6eb40ebea5cb5d0205e67afdbf9b30aa7537c64c956ad3952f64b96cec5bb4b23d94ef07eb311db133c228ff021
7
- data.tar.gz: 0f2472d0cd4db73ed9adf508bbb28e7f6c58edbd083037a828218ff00350cd681483700ba985521faa7ae464b360090b01969f1d0a32ba76e8939d2360d59195
6
+ metadata.gz: 6a0a905efc610731033640bc3e693444ce88dc9502f38d1b9fd316b3dfcf82bd5334f4ad5dc000ef01f48aa33616cfb2d670694ffbee122a674b53bb72078dd2
7
+ data.tar.gz: e3818473246d186e794ad14998bddc0e21e2bc52b427093471e1571eed26425bd21df26a33ea7bd3808e79b4dce9f5218feea65be7169cf5a73b2d5c2c547ea9
data/CHANGELOG.md ADDED
@@ -0,0 +1,21 @@
1
+ ## Version 0.2.0 11/24/2026
2
+
3
+ * Requires Ruby 3.4 or later
4
+ * Adds a runtime dependency on zeitwerk for code loading
5
+ * Classes now live under `DateByExample`; the top-level `ExampleFormatter`
6
+ still works as an alias for `DateByExample::ExampleFormatter`
7
+ * Adds word-style formatting with `{{Token}}` syntax, e.g. `{{Mon}} {{Date:1}}, {{Year}}`
8
+ * Adds `by_example_go` and `by_example_word` to choose a style explicitly;
9
+ `by_example` uses word style whenever the format contains `{{`
10
+ * BREAKING: `ExampleFormatter` is now abstract; use `ExampleFormatter.for`,
11
+ `DateByExample::GoFormatter.new`, or `DateByExample::WordFormatter.new`.
12
+ `FORMATS` moved to `DateByExample::GoFormatter`
13
+ * BREAKING: Go-style `3` is now unpadded (`%-l`) as documented; it was space-padded
14
+ * Fixes Go-style `.000000000` nanoseconds
15
+ * Fixes Go-style zone `-0700` (was the typo `-7000`)
16
+ * Adds Go-style `_2` and `__2` for space-padded day and day of year
17
+ * A literal `%` in a format no longer reaches strftime
18
+
19
+ ## Version 0.1.1 6/22/2018
20
+
21
+ * Adds "%l" for single digit hours
data/README.md CHANGED
@@ -1,9 +1,15 @@
1
1
  # DateByExample
2
2
 
3
- Provides a Ruby implementation of Go-style date formatting by example
3
+ Provides two kinds of date formatting that are hopefully easier to read than Ruby's native strftime.
4
+
5
+ The first kind is based on Go's string formatting and is based on a reference date of "Jan 2, 2006 at 3:04:05 PM MST", like `2006-01-02`
6
+
7
+ The second kind uses tokens as in `{{year}}` to provide a possibly easier to read, if more verbose option, so something like `{{year}}-{{monthnum}}-{{date}}`.
4
8
 
5
9
  ## Installation
6
10
 
11
+ This gem requires Ruby 3.4 and up.
12
+
7
13
  Add this line to your application's Gemfile:
8
14
 
9
15
  ```ruby
@@ -24,19 +30,26 @@ Or install it yourself as:
24
30
 
25
31
  This gem adds a `by_example` method to `Date`, `Time`, and `DateTime`.
26
32
 
27
- The argument to this method is the formatted version of a reference date.
33
+ The argument to this method is the formatted version of a reference date, in either format.
34
+
35
+ You get the word format if your string contains a `{{` token. Note that there's no way to escape this at the moment, if your Go-style string has a raw `{{`, you must use `by_example_go`. (In word format, content within `{{` delimiters that doesn't match a token is passed through unchanged.)
36
+
37
+ You can force a particular parser with `by_example_word` or `by_example_go`.
28
38
 
29
39
  For example:
30
40
 
31
41
  ```
32
42
  > d = Date.today
33
43
  > d.by_example("2006-01-02") => "2018-06-11"
44
+ > d.by_example("{{year}}-{{monthnum}}-{{date}}") => "2018-06-11"
34
45
 
35
46
  > t = DateTime.now
36
47
  > t.by_example("Jan 02 2006 @ 3:04 pm") => "Jun 11 2018 @ 3:52 pm"
48
+ > t.by_example("{{Mon}} {{date}} {{year}} @ {{Hour:12}}:{{Min}} {{pm}}") => "Jun 11 2018 @ 3:52 pm"
37
49
 
38
50
  > t = Time.now
39
51
  > t.by_example("Jan 02 2006 @ 3:04 pm") => "Jun 11 2018 @ 3:53 pm"
52
+ > t.by_example("{{Mon}} {{date}} {{year}} @ {{Hour:12}}:{{Min}} {{pm}}") => "Jun 11 2018 @ 3:53 pm"
40
53
  ```
41
54
 
42
55
  The reference date is Jan 2, 2006 at 3:04:05 PM MST, which can be
@@ -44,17 +57,64 @@ remembered as 1 2 3 4 5 6 -7.
44
57
 
45
58
  I realize that remembering the reference date is not the easy part,
46
59
  but I think it's easier than remembering all the strftime format
47
- strings
48
-
49
- ### Supported formats
50
-
51
- * Year: 2000 and 00 (but not Ruby's %c for the century)
52
- * Month: January, JANUARY, Jan, JAN, 1, and 01, but not " 1" for space padding
53
- * Day: 2, 02, 002 (for day of year), Monday, MONDAY, Mon, MON, but not " 2" for space padding
54
- * Hour: 15, 3, pm, PM
55
- * Minute: 04
56
- * Second: 05, 05.000 for milliseconds and 05.000000 and 05.000000000
57
- * Time Zone: -7000, -07:00, -07:00:00, MST
60
+ strings.
61
+
62
+ ### Format reference
63
+
64
+ Note that in word style, token matching is case-insensitive, except that an all-caps name will give all-caps output where that makes sense. Unknown tokens are ignored and passed through.
65
+
66
+ Note that in go style, there's no way to escape literal numbers that match go patterns. So `The 2nd date is: 2006-01` will match on the `2`. Likewise, an underscore right before a `2` is read as Go's space-padded day, so `2006_1_2` gives `2018_6 5`. If this is a problem, try word style.
67
+
68
+ Numbers are zero-padded by default.
69
+
70
+ Example time: Tuesday, June 5, 2018 at 1:04:07.123456789 PM CDT. A dash means that style has no equivalent.
71
+
72
+ | Unit | Output | Go style | Word style |
73
+ |---|---|---|---|
74
+ | Year | 2018 | `2006` | `{{Year}}` |
75
+ | | 18 | `06` | `{{Yr}}`, `{{Year:short}}` |
76
+ | | 20 | — | `{{Century}}` |
77
+ | Month | June | `January` | `{{Month}}` |
78
+ | | JUNE | `JANUARY` | `{{MONTH}}` |
79
+ | | Jun | `Jan` | `{{Mon}}`, `{{Month:short}}` |
80
+ | | JUN | `JAN` | `{{MON}}` |
81
+ | | 06 | `01` | `{{MonthNum}}`, `{{Month:01}}` |
82
+ | | 6 | `1` | `{{MonthNum:1}}`, `{{Month:1}}` |
83
+ | | `" 6"` | — | `{{MonthNum:_1}}`, `{{Month:_1}}` |
84
+ | Day of month | 05 | `02` | `{{Date}}`, `{{Date:01}}` |
85
+ | | 5 | `2` | `{{Date:1}}` |
86
+ | | `" 5"` | `_2` | `{{Date:_1}}` |
87
+ | Day of year | 156 | `002` | `{{DayOfYear}}` |
88
+ | | 156 (space padded) | `__2` | `{{DayOfYear:_1}}` |
89
+ | | 156 (unpadded) | — | `{{DayOfYear:1}}` |
90
+ | Weekday | Tuesday | `Monday` | `{{Weekday}}` |
91
+ | | TUESDAY | `MONDAY` | `{{WEEKDAY}}` |
92
+ | | Tue | `Mon` | `{{Day}}`, `{{Weekday:short}}` |
93
+ | | TUE | `MON` | `{{DAY}}` |
94
+ | Hour (24) | 13 (09 at 9am) | `15` | `{{Hour:24}}`, `{{Hour:024}}` |
95
+ | | 13 (9 at 9am) | — | `{{Hour:-24}}` |
96
+ | | 13 (`" 9"` at 9am) | — | `{{Hour:_24}}` |
97
+ | Hour (12) | 01 | `03` | `{{Hour}}`, `{{Hour:012}}` |
98
+ | | 1 | `3` | `{{Hour:12}}` |
99
+ | | `" 1"` | — | `{{Hour:_12}}` |
100
+ | AM/PM | PM | `PM` | `{{AM}}`, `{{PM}}` |
101
+ | | pm | `pm` | `{{am}}`, `{{pm}}` |
102
+ | Minute | 04 | `04` | `{{Min}}` |
103
+ | | 4 | — | `{{Min:1}}` |
104
+ | | `" 4"` | — | `{{Min:_1}}` |
105
+ | Second | 07 | `05` | `{{Sec}}` |
106
+ | | 7 | — | `{{Sec:1}}` |
107
+ | | `" 7"` | — | `{{Sec:_1}}` |
108
+ | | 07.123 | `05.000` | `{{Sec:Milli}}`, `{{Sec:00.000}}` |
109
+ | | 07.123456 | `05.000000` | `{{Sec:Micro}}`, `{{Sec:00.000000}}` |
110
+ | | 07.123456789 | `05.000000000` | `{{Sec:Nano}}`, `{{Sec:00.000000000}}` |
111
+ | Fraction | 123 | — | `{{Milli}}` |
112
+ | | 123456 | — | `{{Micro}}` |
113
+ | | 123456789 | — | `{{Nano}}` |
114
+ | Time zone | CDT | `MST` | `{{Zone}}`, `{{Zone:name}}` |
115
+ | | -0500 | `-0700` | `{{Offset}}`, `{{Zone:+0000}}`, `{{Zone:offset}}` |
116
+ | | -05:00 | `-07:00` | `{{Zone:+00:00}}` |
117
+ | | -05:00:00 | `-07:00:00` | `{{Zone:+00:00:00}}` |
58
118
 
59
119
  ### Unsupported Formats
60
120
 
@@ -64,10 +124,10 @@ This does not support Ruby's week based formats
64
124
 
65
125
  The slow part of using this gem is generating the format string from
66
126
  the example, if you want to reuse a format multiple times, you can do so
67
- by creating and reusing an `ExampleFormatter`
127
+ by creating and reusing an `ExampleFormatter` (or a `DateByExample::GoFormatter` or `DateByExample::WordFormatter` directly)
68
128
 
69
129
  ```
70
- > ef = ExampleFormatter.new("01/02/06")
130
+ > ef = ExampleFormatter.for("01/02/06")
71
131
  > ef.format(Date.today) => "06/11/18"
72
132
  > ef.format(Time.now) => "06/11/18"
73
133
  ```
@@ -80,7 +140,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
80
140
 
81
141
  ## Contributing
82
142
 
83
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/date_by_example. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
143
+ Bug reports and pull requests are welcome on GitHub at https://github.com/noelrappin/date_by_example. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
84
144
 
85
145
  ## License
86
146
 
@@ -88,4 +148,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
88
148
 
89
149
  ## Code of Conduct
90
150
 
91
- Everyone interacting in the DateByExample project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/date_by_example/blob/master/CODE_OF_CONDUCT.md).
151
+ Everyone interacting in the DateByExample project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/noelrappin/date_by_example/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile CHANGED
@@ -1,6 +1,23 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
+ require "standard/rake"
3
4
 
4
5
  RSpec::Core::RakeTask.new(:spec)
5
6
 
6
- task default: :spec
7
+ task default: %i[spec standard]
8
+
9
+ desc "Benchmark Go-style and word-style formatting"
10
+ task :benchmark do
11
+ require "benchmark"
12
+ require_relative "lib/date_by_example"
13
+
14
+ date = DateTime.new(2018, 6, 9, 13, 15)
15
+ Benchmark.bm(5) do |x|
16
+ x.report("go") do
17
+ 1_000_000.times { ExampleFormatter.for("2 Jan 06 15:04").format(date) }
18
+ end
19
+ x.report("word") do
20
+ 1_000_000.times { ExampleFormatter.for("{{Date:1}} {{Mon}} {{Yr}} {{Hour:24}}:{{Min}}").format(date) }
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,15 @@
1
+ module DateByExample
2
+ module ByExample
3
+ def by_example(example)
4
+ ExampleFormatter.for(example).format(self)
5
+ end
6
+
7
+ def by_example_go(example)
8
+ GoFormatter.new(example).format(self)
9
+ end
10
+
11
+ def by_example_word(example)
12
+ WordFormatter.new(example).format(self)
13
+ end
14
+ end
15
+ end
@@ -1,48 +1,32 @@
1
- class ExampleFormatter
2
- attr_accessor :reference
1
+ module DateByExample
2
+ class ExampleFormatter
3
+ def self.for(reference)
4
+ (reference.include?("{{") ? WordFormatter : GoFormatter).new(reference)
5
+ end
3
6
 
4
- def initialize(reference)
5
- @reference = reference
6
- @format_string = nil
7
- end
7
+ attr_reader :reference
8
8
 
9
- FORMATS = {
10
- ".000000000" => ".9N",
11
- "-07:00:00" => "%::z",
12
- ".000000" => ".%6N",
13
- "January" => "%B",
14
- "JANUARY" => "%^B",
15
- "Monday" => "%A",
16
- "MONDAY" => "%^A",
17
- "-07:00" => "%:z",
18
- "-7000" => "%z",
19
- "2006" => "%Y",
20
- ".000" => ".%L",
21
- "002" => "%j",
22
- "Jan" => "%b",
23
- "JAN" => "%^b",
24
- "Mon" => "%a",
25
- "MON" => "%^a",
26
- "MST" => "%Z",
27
- "15" => "%H",
28
- "06" => "%y",
29
- "01" => "%m",
30
- "02" => "%d",
31
- "03" => "%I",
32
- "PM" => "%p",
33
- "pm" => "%P",
34
- "04" => "%M",
35
- "05" => "%S",
36
- "1" => "%-m",
37
- "2" => "%-e"}.freeze
9
+ def initialize(reference)
10
+ if instance_of?(ExampleFormatter)
11
+ raise NotImplementedError, "ExampleFormatter is abstract; use ExampleFormatter.for"
12
+ end
38
13
 
39
- FORMAT_MATCHER = Regexp.union(FORMATS.keys)
14
+ @reference = reference
15
+ @format_string = nil
16
+ end
40
17
 
41
- def format_string
42
- @format_string ||= reference.gsub(FORMAT_MATCHER, FORMATS)
43
- end
18
+ def format_string
19
+ @format_string ||= compile
20
+ end
21
+
22
+ def format(date)
23
+ date.strftime(format_string)
24
+ end
25
+
26
+ private
44
27
 
45
- def format(date)
46
- date.strftime(format_string)
28
+ def compile
29
+ raise NotImplementedError, "#{self.class} must implement #compile"
30
+ end
47
31
  end
48
32
  end
@@ -0,0 +1,62 @@
1
+ module DateByExample
2
+ # Go-style formatting: the format is the reference time
3
+ # Mon Jan 2 15:04:05 MST 2006, written the way you want the output to look.
4
+
5
+ class GoFormatter < ExampleFormatter
6
+ FORMATS = {
7
+ # year
8
+ "2006" => "%Y",
9
+ "06" => "%y",
10
+
11
+ # month
12
+ "January" => "%B",
13
+ "JANUARY" => "%^B",
14
+ "Jan" => "%b",
15
+ "JAN" => "%^b",
16
+ "01" => "%m",
17
+ "1" => "%-m",
18
+
19
+ # day
20
+ "02" => "%d",
21
+ "_2" => "%e",
22
+ "2" => "%-d",
23
+ "002" => "%j",
24
+ "__2" => "%_j",
25
+ "Monday" => "%A",
26
+ "MONDAY" => "%^A",
27
+ "Mon" => "%a",
28
+ "MON" => "%^a",
29
+
30
+ # hour
31
+ "15" => "%H",
32
+ "03" => "%I",
33
+ "3" => "%-l",
34
+ "PM" => "%p",
35
+ "pm" => "%P",
36
+
37
+ # minute and second
38
+ "04" => "%M",
39
+ "05" => "%S",
40
+ ".000" => ".%L",
41
+ ".000000" => ".%6N",
42
+ ".000000000" => ".%9N",
43
+
44
+ # time zone
45
+ "MST" => "%Z",
46
+ "-0700" => "%z",
47
+ "-07:00" => "%:z",
48
+ "-07:00:00" => "%::z",
49
+
50
+ # a literal percent sign must not reach strftime unescaped
51
+ "%" => "%%"
52
+ }.freeze
53
+
54
+ FORMAT_MATCHER = Regexp.union(FORMATS.keys.sort_by { -it.length })
55
+
56
+ private
57
+
58
+ def compile
59
+ reference.gsub(FORMAT_MATCHER, FORMATS)
60
+ end
61
+ end
62
+ end
@@ -1,3 +1,3 @@
1
1
  module DateByExample
2
- VERSION = "0.1.0".freeze
2
+ VERSION = "0.2.0".freeze
3
3
  end
@@ -0,0 +1,126 @@
1
+ module DateByExample
2
+ # Word-style formatting: tokens like {{Month}} or {{Hour:12}}.
3
+ # Names are case-insensitive; an all-caps name gives all-caps output.
4
+ # Modifiers are case-insensitive. Unknown tokens are left as literal text.
5
+ class WordFormatter < ExampleFormatter
6
+ TOKENS = {
7
+ # year
8
+ "year" => "%Y",
9
+ "year:short" => "%y",
10
+ "yr" => "%y",
11
+ "century" => "%C",
12
+
13
+ # month
14
+ "month" => "%B",
15
+ "month:short" => "%b",
16
+ "mon" => "%b",
17
+ "month:01" => "%m",
18
+ "month:1" => "%-m",
19
+ "month:_1" => "%_m",
20
+ "monthnum" => "%m",
21
+ "monthnum:01" => "%m",
22
+ "monthnum:1" => "%-m",
23
+ "monthnum:_1" => "%_m",
24
+
25
+ # day of month
26
+ "date" => "%d",
27
+ "date:01" => "%d",
28
+ "date:1" => "%-d",
29
+ "date:_1" => "%e",
30
+
31
+ # day of year
32
+ "dayofyear" => "%j",
33
+ "dayofyear:001" => "%j",
34
+ "dayofyear:1" => "%-j",
35
+ "dayofyear:_1" => "%_j",
36
+
37
+ # day of week
38
+ "weekday" => "%A",
39
+ "weekday:short" => "%a",
40
+ "day" => "%a",
41
+
42
+ # hour
43
+ "hour" => "%I",
44
+ "hour:012" => "%I",
45
+ "hour:12" => "%-l",
46
+ "hour:_12" => "%l",
47
+ "hour:24" => "%H",
48
+ "hour:024" => "%H",
49
+ "hour:-24" => "%-H",
50
+ "hour:_24" => "%k",
51
+ "am" => "%p",
52
+ "pm" => "%p",
53
+
54
+ # minute
55
+ "min" => "%M",
56
+ "min:01" => "%M",
57
+ "min:1" => "%-M",
58
+ "min:_1" => "%_M",
59
+
60
+ # second
61
+ "sec" => "%S",
62
+ "sec:01" => "%S",
63
+ "sec:1" => "%-S",
64
+ "sec:_1" => "%_S",
65
+ "sec:00.000" => "%S.%L",
66
+ "sec:00.000000" => "%S.%6N",
67
+ "sec:00.000000000" => "%S.%9N",
68
+ "sec:milli" => "%S.%L",
69
+ "sec:micro" => "%S.%6N",
70
+ "sec:nano" => "%S.%9N",
71
+ "milli" => "%L",
72
+ "micro" => "%6N",
73
+ "nano" => "%9N",
74
+
75
+ # time zone
76
+ "zone" => "%Z",
77
+ "zone:name" => "%Z",
78
+ "zone:+0000" => "%z",
79
+ "zone:offset" => "%z",
80
+ "offset" => "%z",
81
+ "zone:+00:00" => "%:z",
82
+ "zone:+00:00:00" => "%::z"
83
+ }.freeze
84
+
85
+ TOKEN_MATCHER = /\{\{\w+(?::[^}]*)?\}\}/
86
+
87
+ private
88
+
89
+ def compile
90
+ escape_percents(reference)
91
+ .then { replace_tokens(it) }
92
+ end
93
+
94
+ def replace_tokens(str)
95
+ str.gsub(TOKEN_MATCHER) { strftime_code(unwrap(it)) || it }
96
+ end
97
+
98
+ def strftime_code(body)
99
+ TOKENS[body.downcase]&.then { style(it, body) }
100
+ end
101
+
102
+ def style(code, body)
103
+ return "%P" if lowercase_meridian?(body)
104
+
105
+ all_caps?(name_of(body)) ? upcase(code) : code
106
+ end
107
+
108
+ def escape_percents(string) = string.gsub("%", "%%")
109
+
110
+ def unwrap(token) = token.delete_prefix("{{").delete_suffix("}}")
111
+
112
+ def name_of(body) = body.split(":").first
113
+
114
+ def lowercase_meridian?(body)
115
+ %w[am pm].include?(body)
116
+ end
117
+
118
+ def all_caps?(name)
119
+ name == name.upcase
120
+ end
121
+
122
+ def upcase(code)
123
+ code.gsub("%", "%^")
124
+ end
125
+ end
126
+ end
@@ -1,22 +1,14 @@
1
1
  require "date"
2
- require "date_by_example/date"
3
- require "date_by_example/date_time"
4
- require "date_by_example/time"
5
- require "date_by_example/version"
6
- require "date_by_example/example_formatter"
7
- require "benchmark"
2
+ require "zeitwerk"
8
3
 
9
4
  module DateByExample
10
- def self.benchmark
11
- dt = DateTime.new(2018, 6, 9, 13, 15)
12
- Benchmark.bm do |x|
13
- x.report do
14
- 1_000_000.times do
15
- ExampleFormatter.new("2 Jan 06 15:04").format(dt)
16
- end
17
- end
18
- end
19
-
20
- # GSUB version is 16.15 seconds
21
- end
22
5
  end
6
+
7
+ loader = Zeitwerk::Loader.for_gem
8
+ loader.setup
9
+
10
+ Date.include(DateByExample::ByExample)
11
+ Time.include(DateByExample::ByExample)
12
+
13
+ # Top-level name from 0.1, kept for compatibility
14
+ ExampleFormatter = DateByExample::ExampleFormatter
metadata CHANGED
@@ -1,134 +1,77 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: date_by_example
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
- - Noel Rappin
8
- autorequire:
7
+ - Noel Rappin
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2018-06-11 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1.16'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.16'
27
- - !ruby/object:Gem::Dependency
28
- name: rake
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '10.0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '10.0'
41
- - !ruby/object:Gem::Dependency
42
- name: rspec
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '3.0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '3.0'
55
- - !ruby/object:Gem::Dependency
56
- name: rubocop
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '0.57'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '0.57'
69
- - !ruby/object:Gem::Dependency
70
- name: rubocop-rspec
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '1.25'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '1.25'
83
- description: Go style date formatting by example
12
+ - !ruby/object:Gem::Dependency
13
+ name: zeitwerk
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ -
17
+ - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: "2.6"
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ -
25
+ - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: "2.6"
28
+ description: |
29
+ Adds by_example to Date, Time, and DateTime. Format with Go's reference
30
+ date ("Jan 2, 2006") or with word tokens ("{{Mon}} {{Date:1}}, {{Year}}")
31
+ instead of memorizing strftime codes.
84
32
  email:
85
- - noelrappin@gmail.com
33
+ - noelrappin@gmail.com
86
34
  executables: []
87
35
  extensions: []
88
36
  extra_rdoc_files: []
89
37
  files:
90
- - ".DS_Store"
91
- - ".gitignore"
92
- - ".rspec"
93
- - ".rubocop.yml"
94
- - ".travis.yml"
95
- - CODE_OF_CONDUCT.md
96
- - Gemfile
97
- - Gemfile.lock
98
- - LICENSE.txt
99
- - README.md
100
- - Rakefile
101
- - bin/console
102
- - bin/setup
103
- - date_by_example.gemspec
104
- - lib/date_by_example.rb
105
- - lib/date_by_example/date.rb
106
- - lib/date_by_example/date_time.rb
107
- - lib/date_by_example/example_formatter.rb
108
- - lib/date_by_example/time.rb
109
- - lib/date_by_example/version.rb
110
- homepage: http://www.github.com/noelrappin/date_by_example
38
+ - CHANGELOG.md
39
+ - CODE_OF_CONDUCT.md
40
+ - LICENSE.txt
41
+ - README.md
42
+ - Rakefile
43
+ - lib/date_by_example.rb
44
+ - lib/date_by_example/by_example.rb
45
+ - lib/date_by_example/example_formatter.rb
46
+ - lib/date_by_example/go_formatter.rb
47
+ - lib/date_by_example/version.rb
48
+ - lib/date_by_example/word_formatter.rb
49
+ homepage: "https://github.com/noelrappin/date_by_example"
111
50
  licenses:
112
- - MIT
113
- metadata: {}
114
- post_install_message:
51
+ - MIT
52
+ metadata:
53
+ allowed_push_host: "https://rubygems.org"
54
+ homepage_uri: "https://github.com/noelrappin/date_by_example"
55
+ source_code_uri: "https://github.com/noelrappin/date_by_example"
56
+ changelog_uri: "https://github.com/noelrappin/date_by_example/blob/main/CHANGELOG.md"
57
+ rubygems_mfa_required: "true"
115
58
  rdoc_options: []
116
59
  require_paths:
117
- - lib
60
+ - lib
118
61
  required_ruby_version: !ruby/object:Gem::Requirement
119
62
  requirements:
120
- - - ">="
121
- - !ruby/object:Gem::Version
122
- version: '0'
63
+ -
64
+ - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "3.4"
123
67
  required_rubygems_version: !ruby/object:Gem::Requirement
124
68
  requirements:
125
- - - ">="
126
- - !ruby/object:Gem::Version
127
- version: '0'
69
+ -
70
+ - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: "0"
128
73
  requirements: []
129
- rubyforge_project:
130
- rubygems_version: 2.7.6
131
- signing_key:
74
+ rubygems_version: 4.1.1
132
75
  specification_version: 4
133
- summary: Go style date formatting by example
76
+ summary: "Format dates by example, Go-style or with readable {{Token}} templates"
134
77
  test_files: []
data/.DS_Store DELETED
Binary file
data/.gitignore DELETED
@@ -1,11 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
-
10
- # rspec failure tracking
11
- .rspec_status
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
data/.rubocop.yml DELETED
@@ -1,149 +0,0 @@
1
- require:
2
- - rubocop-rspec
3
-
4
- AllCops:
5
- Exclude:
6
- - "db/schema.rb" # You can't touch this
7
- - ".bundle/**/*" # Auto-generated
8
- - "bin/**/*" # Auto-generated
9
- - "vendor/**/*" # We cannot solve the world's problems
10
- TargetRubyVersion: 2.5
11
-
12
- Rails:
13
- Enabled: false
14
-
15
- Metrics/AbcSize:
16
- Enabled: false
17
-
18
- Metrics/BlockLength:
19
- Enabled: false
20
-
21
- Metrics/ClassLength:
22
- Enabled: false
23
-
24
- Metrics/LineLength:
25
- Enabled: false
26
-
27
- Metrics/MethodLength:
28
- Enabled: false
29
-
30
- Metrics/ParameterLists:
31
- Enabled: false
32
-
33
- Layout/AlignParameters:
34
- EnforcedStyle: with_fixed_indentation
35
- IndentationWidth: 2
36
-
37
- Style/CaseEquality:
38
- Enabled: false
39
-
40
- Layout/EmptyLinesAroundBlockBody:
41
- Exclude:
42
- - "spec/**/*"
43
- - "lib/tasks/*.rake"
44
-
45
- Layout/FirstParameterIndentation:
46
- IndentationWidth: 2
47
-
48
- Style/FrozenStringLiteralComment:
49
- Enabled: false
50
-
51
- Layout/IndentArray:
52
- IndentationWidth: 2
53
-
54
- Layout/IndentAssignment:
55
- IndentationWidth: 2
56
-
57
- Layout/IndentHash:
58
- IndentationWidth: 2
59
-
60
- Layout/MultilineMethodCallBraceLayout:
61
- EnforcedStyle: same_line
62
-
63
- Layout/MultilineMethodCallIndentation:
64
- EnforcedStyle: indented
65
- IndentationWidth: 2
66
-
67
- Layout/MultilineHashBraceLayout:
68
- EnforcedStyle: same_line
69
-
70
- Layout/MultilineOperationIndentation:
71
- EnforcedStyle: indented
72
- IndentationWidth: 2
73
-
74
- Naming/VariableNumber:
75
- EnforcedStyle: snake_case
76
-
77
- Style/SignalException:
78
- EnforcedStyle: only_raise
79
-
80
- Style/StringLiterals:
81
- EnforcedStyle: double_quotes
82
-
83
- Style/TrivialAccessors:
84
- ExactNameMatch: true
85
-
86
- Style/TrailingCommaInHashLiteral:
87
- EnforcedStyleForMultiline: no_comma
88
-
89
- Style/TrailingCommaInArrayLiteral:
90
- EnforcedStyleForMultiline: no_comma
91
-
92
- Style/TrailingCommaInArguments:
93
- EnforcedStyleForMultiline: no_comma
94
-
95
- Layout/SpaceInsideBlockBraces:
96
- EnforcedStyle: space
97
- EnforcedStyleForEmptyBraces: no_space
98
- SpaceBeforeBlockParameters: true
99
-
100
- Layout/SpaceInsideHashLiteralBraces:
101
- EnforcedStyle: no_space
102
- EnforcedStyleForEmptyBraces: no_space
103
-
104
- Style/Documentation:
105
- Enabled: false
106
-
107
- Style/BlockDelimiters:
108
- Exclude:
109
- - "spec/**/*" # because let statements use braces for multiline blocks
110
-
111
- Layout/BlockEndNewline:
112
- Exclude:
113
- - "spec/**/*" # because let statements use braces for multiline blocks
114
-
115
- Layout/MultilineBlockLayout:
116
- Exclude:
117
- - "spec/**/*" # because let statements use braces for multiline blocks
118
-
119
- Style/Semicolon:
120
- AllowAsExpressionSeparator: true
121
- Exclude:
122
- - "spec/**/*" # because sometimes we use this in expect or then blocks
123
-
124
- Style/RaiseArgs:
125
- Enabled: false
126
-
127
- Style/AccessModifierDeclarations:
128
- Enabled: false
129
-
130
- RSpec/ContextWording:
131
- Enabled: false
132
-
133
- RSpec/ExampleLength:
134
- Enabled: false
135
-
136
- RSpec/HookArgument:
137
- EnforcedStyle: "example"
138
-
139
- RSpec/MultipleExpectations:
140
- Enabled: false
141
-
142
- RSpec/NestedGroups:
143
- Enabled: false
144
-
145
- RSpec/DescribedClass:
146
- Enabled: false
147
-
148
- Style/DateTime:
149
- Enabled: false
data/.travis.yml DELETED
@@ -1,5 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.5.1
5
- before_install: gem install bundler -v 1.16.1
data/Gemfile DELETED
@@ -1,6 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
-
5
- # Specify your gem's dependencies in date_by_example.gemspec
6
- gemspec
data/Gemfile.lock DELETED
@@ -1,56 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- date_by_example (0.1.0)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- ast (2.4.0)
10
- diff-lcs (1.3)
11
- jaro_winkler (1.5.1)
12
- parallel (1.12.1)
13
- parser (2.5.1.0)
14
- ast (~> 2.4.0)
15
- powerpack (0.1.1)
16
- rainbow (3.0.0)
17
- rake (10.5.0)
18
- rspec (3.7.0)
19
- rspec-core (~> 3.7.0)
20
- rspec-expectations (~> 3.7.0)
21
- rspec-mocks (~> 3.7.0)
22
- rspec-core (3.7.1)
23
- rspec-support (~> 3.7.0)
24
- rspec-expectations (3.7.0)
25
- diff-lcs (>= 1.2.0, < 2.0)
26
- rspec-support (~> 3.7.0)
27
- rspec-mocks (3.7.0)
28
- diff-lcs (>= 1.2.0, < 2.0)
29
- rspec-support (~> 3.7.0)
30
- rspec-support (3.7.1)
31
- rubocop (0.57.1)
32
- jaro_winkler (~> 1.5.1)
33
- parallel (~> 1.10)
34
- parser (>= 2.5)
35
- powerpack (~> 0.1)
36
- rainbow (>= 2.2.2, < 4.0)
37
- ruby-progressbar (~> 1.7)
38
- unicode-display_width (~> 1.0, >= 1.0.1)
39
- rubocop-rspec (1.26.0)
40
- rubocop (>= 0.53.0)
41
- ruby-progressbar (1.9.0)
42
- unicode-display_width (1.4.0)
43
-
44
- PLATFORMS
45
- ruby
46
-
47
- DEPENDENCIES
48
- bundler (~> 1.16)
49
- date_by_example!
50
- rake (~> 10.0)
51
- rspec (~> 3.0)
52
- rubocop (~> 0.57)
53
- rubocop-rspec (~> 1.25)
54
-
55
- BUNDLED WITH
56
- 1.16.1
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "date_by_example"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
@@ -1,37 +0,0 @@
1
- lib = File.expand_path("lib", __dir__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require "date_by_example/version"
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = "date_by_example"
7
- spec.version = DateByExample::VERSION
8
- spec.authors = ["Noel Rappin"]
9
- spec.email = ["noelrappin@gmail.com"]
10
-
11
- spec.summary = "Go style date formatting by example"
12
- spec.description = "Go style date formatting by example"
13
- spec.homepage = "http://www.github.com/noelrappin/date_by_example"
14
- spec.license = "MIT"
15
-
16
- # # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
- # # to allow pushing to a single host or delete this section to allow pushing to any host.
18
- # if spec.respond_to?(:metadata)
19
- # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
20
- # else
21
- # raise "RubyGems 2.0 or newer is required to protect against " \
22
- # "public gem pushes."
23
- # end
24
-
25
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
- f.match(%r{^(test|spec|features)/})
27
- end
28
- spec.bindir = "exe"
29
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
- spec.require_paths = ["lib"]
31
-
32
- spec.add_development_dependency "bundler", "~> 1.16"
33
- spec.add_development_dependency "rake", "~> 10.0"
34
- spec.add_development_dependency "rspec", "~> 3.0"
35
- spec.add_development_dependency "rubocop", "~> 0.57"
36
- spec.add_development_dependency "rubocop-rspec", "~> 1.25"
37
- end
@@ -1,5 +0,0 @@
1
- class Date
2
- def by_example(example)
3
- ExampleFormatter.new(example).format(self)
4
- end
5
- end
@@ -1,5 +0,0 @@
1
- class DateTime
2
- def by_example(example)
3
- ExampleFormatter.new(example).format(self)
4
- end
5
- end
@@ -1,5 +0,0 @@
1
- class Time
2
- def by_example(example)
3
- ExampleFormatter.new(example).format(self)
4
- end
5
- end