date-formatter 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c390fc86284148fbbd76384d5e0a2a81aa92db33
4
- data.tar.gz: b0a78b8d0d1b342d99125b7b7b64a5cecc2265f3
3
+ metadata.gz: 9df162a0fb3e1ec3c03706ff45460dd2063c2fa5
4
+ data.tar.gz: 77554d8bae8a8775767c02d8f0e4d1b26df8ea85
5
5
  SHA512:
6
- metadata.gz: 4b470f1e3b04ec4146175e488c1b210129799b3083188f9e21e1cc44c94b12303e5a47a535d740e187334026a38cfe8852cfe44774e125b1ad9cf46f4d8f370f
7
- data.tar.gz: b751629fdfb1be81962c61a00d1ae28cb5754a4112b59a06c0861d2c763bd4b8a0dbceea14e9be61834e8977a8ac048e672308bc21f685e1675a529501977790
6
+ metadata.gz: f712a4d3e6494680829656dfb2cdf07afec25402a06c543c6b963905bcb4df5bf8b163ae8bd77b00341fba88d184986a163e20954b53feb214054b3affd58359
7
+ data.tar.gz: dc2017997ec35eb9a10aac2bc344d4dedbe9aa1493236f44bc5706fc466431716d45a4f1f49211b22ca0e1680d06b7a40f94ad0c420d34dd6ea7a4d9cea24821
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # date-formatter - date formatter by example; auto-builds the strftime format string from a example date
1
+ # date-formatter - date formatter by example; auto-builds the strftime format string from an example date
2
2
 
3
3
 
4
4
  * home :: [github.com/feedreader/pluto](https://github.com/feedreader/pluto)
@@ -9,24 +9,81 @@
9
9
 
10
10
 
11
11
 
12
-
13
12
  ## Usage
14
13
 
14
+ The date by example lets you format dates e.g. "January 04, 2020"
15
+ using an example as a format string e.g "January 04, 2020" instead of the classic strftime format specifier e.g. "%B %d, %Y". The date by example adds:
16
+
17
+ - `String#to_strfime`
18
+ - `Date#format`
19
+ - `Time#format`
20
+ - `DateTime#format`
21
+ - `NilClass#format`
22
+
23
+ to the built-in classes.
24
+
25
+
26
+
27
+ ### `String#to_strftime`
28
+
29
+ The new `String#to_strftime` method auto-builds the `strftime` format string
30
+ from an example date:
31
+
32
+ ``` ruby
33
+ require 'date/formatter'
34
+
35
+ p 'January 02, 2006'.to_strftime #=> "%B %d, %Y"
36
+ p 'Mon, Jan 02'.to_strftime #=> "%a, %b %d"
37
+ p '2 Jan 2006'.to_strftime #=> "%-d %b %Y"
38
+ p 'Monday, January 2, 2006'.to_strftime #=> "%A, %B %-d, %Y"
39
+
40
+ p 'Mon, Jan 02 3:00'.to_strftime #=> "%a, %b %d %-H:%M"
41
+ p '2 Mon 2006 03:00'.to_strftime #=> "%-d %b %Y %H:%M"
42
+ ```
43
+
44
+
45
+ ### `Date#format`
46
+
47
+ The new `Date#format` method formats the date like the passed in example:
48
+
49
+ ``` ruby
50
+ date = Date.today ## test run on 2020-02-09
51
+
52
+ p date.format( 'January 02, 2006' ) #=> "February 09, 2020"
53
+ p date.format( 'Mon, Jan 02' ) #=> "Sun, Feb 09"
54
+ p date.format( '2 Jan 2006' ) #=> "9 Feb 2020"
55
+ p date.format( 'Monday, January 2, 2006' ) #=> "Sunday, February 9, 2020"
56
+ ```
57
+
58
+
59
+
60
+ ### `Time#format`
61
+
62
+ The new `Time#format` method format the time like the passed in example:
63
+
64
+ ``` ruby
65
+ time = Time.now ## test run on 2020-02-09 00:00
15
66
 
67
+ p time.format( 'January 02, 2006' ) #=> "February 09, 2020"
68
+ p time.format( 'Mon, Jan 02' ) #=> "Sun, Feb 09"
69
+ p time.format( '2 Jan 2006' ) #=> "9 Feb 2020"
70
+ p time.format( 'Monday, January 2, 2006' ) #=> "Sunday, February 9, 2020"
16
71
 
17
- Examples:
72
+ p time.format( 'Mon, Jan 02 3:00' ) #=> "Sun, Feb 09 0:00"
73
+ p time.format( '2 Mon 2006 03:00' ) #=> "9 Sun 2020 00:00"
74
+ ```
18
75
 
19
- | Date by Example | => `strftime` Format |
20
- |-------------------------|----------------|
21
- | January 04, 2020 | => `%B %d, %Y` |
22
- | Fri, Jan 04 | => `%a, %b %d` |
23
- | 4 Jan 2020 | => `%-d %b %Y` |
24
- | Friday, January 4, 2020 | => `%A, %B %-d, %Y` |
25
- | Fri, Jan 04 8:00 | => `%a, %b %d %-H:%M` |
26
- | 4 Jan 2020 08:00 | => `%-d %b %Y %H:%M` |
27
76
 
77
+ ### `NilClass#format`
28
78
 
79
+ For convenience the new `NilClass#format` will catch format calls on `nil`
80
+ and NOT crash but return an empty string
81
+ following the `NilClass#to_s` example:
29
82
 
83
+ ``` ruby
84
+ p nil.format( 'January 02, 2006' ) #=> ""
85
+ p nil.to_s #=> ""
86
+ ```
30
87
 
31
88
 
32
89
  ## License
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ Hoe.spec 'date-formatter' do
5
5
 
6
6
  self.version = DateByExample::VERSION
7
7
 
8
- self.summary = "date-formatter - date formatter by example; auto-builds the strftime format string from a example date"
8
+ self.summary = "date-formatter - date formatter by example; auto-builds the strftime format string from an example date"
9
9
  self.description = summary
10
10
 
11
11
  self.urls = ['https://github.com/feedreader/pluto']
@@ -1,8 +1,8 @@
1
1
 
2
2
  module DateByExample
3
3
  MAJOR = 0 ## todo: namespace inside version or something - why? why not??
4
- MINOR = 0
5
- PATCH = 1
4
+ MINOR = 1
5
+ PATCH = 0
6
6
  VERSION = [MAJOR,MINOR,PATCH].join('.')
7
7
 
8
8
  def self.version
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: date-formatter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3.16'
41
41
  description: date-formatter - date formatter by example; auto-builds the strftime
42
- format string from a example date
42
+ format string from an example date
43
43
  email: wwwmake@googlegroups.com
44
44
  executables: []
45
45
  extensions: []
@@ -83,5 +83,5 @@ rubygems_version: 2.5.2
83
83
  signing_key:
84
84
  specification_version: 4
85
85
  summary: date-formatter - date formatter by example; auto-builds the strftime format
86
- string from a example date
86
+ string from an example date
87
87
  test_files: []