over_the_midnight 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 +4 -4
- data/README.md +50 -5
- data/lib/over_the_midnight.rb +1 -1
- data/lib/over_the_midnight/time.rb +22 -2
- data/lib/over_the_midnight/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c58785a99ed7c9fb62a41d421569b2ce5b8e3a94
|
4
|
+
data.tar.gz: c59ebe0f315adce3039242ab3b837e16c7c65f3a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 524e82d2a47a2a5d7c27db07b38f89f8cc6a8cc6b6f2893f1134f3b39461dc828b57a1a69fdbc2f958dfc7fffe16ab7622e91ccd3a38d104f5a308c30ea7250f
|
7
|
+
data.tar.gz: 33be6d372928bf22ba981d616d28e0fe20a0b356e3704561bc8a4f72e78c60b5a606a5c72af177e05cbcb5aa80c552dd3b3d666c9a883593c70b08c2d4e8a483
|
data/README.md
CHANGED
@@ -21,18 +21,63 @@ Or install it yourself as:
|
|
21
21
|
## Usage
|
22
22
|
|
23
23
|
``` ruby
|
24
|
+
require "over_the_midnight"
|
25
|
+
|
24
26
|
date = Date.new(2016, 8, 13)
|
25
27
|
|
28
|
+
#--------------------#
|
26
29
|
# version 0.1.x
|
27
|
-
|
28
|
-
otm
|
29
|
-
|
30
|
+
# otm = OverTheMidnight.new(date, "25:00")
|
31
|
+
# otm.to_time.strftime("%Y/%m/%d %H:%M")
|
32
|
+
#=> "2016/08/14 01:00"
|
33
|
+
|
34
|
+
# otm = OverTheMidnight.new(date, 30.5)
|
35
|
+
# otm.to_time.strftime("%Y/%m/%d %H:%M")
|
36
|
+
#=> "2016/08/14 06:30"
|
37
|
+
|
38
|
+
#--------------------#
|
39
|
+
# version 0.2.x
|
40
|
+
|
41
|
+
otm = OverTheMidnight.create(date, "25:00")
|
42
|
+
|
43
|
+
otm.class
|
44
|
+
#=> OverTheMidnight::Time
|
45
|
+
|
46
|
+
otm.date.to_s
|
47
|
+
#=> "2016/08/13"
|
48
|
+
|
49
|
+
otm.time.class
|
50
|
+
#=> Time
|
51
|
+
|
52
|
+
otm.time.strftime("%Y/%m/%d %H:%M")
|
30
53
|
#=> "2016/08/14 01:00"
|
31
54
|
|
32
|
-
otm
|
33
|
-
|
55
|
+
otm.to_s
|
56
|
+
#=> "2016/08/13 25:00"
|
57
|
+
|
58
|
+
#created with Numeric
|
59
|
+
otm = OverTheMidnight.create(date, 30.5)
|
60
|
+
|
61
|
+
otm.time.strftime("%Y/%m/%d %H:%M")
|
34
62
|
#=> "2016/08/14 06:30"
|
35
63
|
|
64
|
+
otm.to_s
|
65
|
+
#=> "2016/08/13 30:30"
|
66
|
+
|
67
|
+
|
68
|
+
# created with Time
|
69
|
+
time = Time.local((date + 1).year, (date + 1).month, (date + 1).day, 10, 45)
|
70
|
+
|
71
|
+
otm = OvertTheMidnight.create(date, time)
|
72
|
+
|
73
|
+
otm.time.strftime("%Y/%m/%d %H:%M")
|
74
|
+
#=> "2016/08/14 10:45"
|
75
|
+
# NOT "2016/08/13 10:45"
|
76
|
+
|
77
|
+
otm.to_s
|
78
|
+
#=> "2016/08/13 34:45"
|
79
|
+
# NOT "2016/08/14 10:45"
|
80
|
+
|
36
81
|
```
|
37
82
|
|
38
83
|
## Development
|
data/lib/over_the_midnight.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
require "date"
|
2
2
|
|
3
3
|
class OverTheMidnight::Time
|
4
|
+
DATE_FORMAT = "%Y/%m/%d"
|
5
|
+
TIME_FORMAT = "%H:%M"
|
6
|
+
|
4
7
|
attr_reader :date
|
5
8
|
|
6
9
|
def initialize(date, time)
|
@@ -9,8 +12,19 @@ class OverTheMidnight::Time
|
|
9
12
|
@raw_time = time
|
10
13
|
end
|
11
14
|
|
12
|
-
def
|
13
|
-
|
15
|
+
def hour
|
16
|
+
time.hour + ((time.to_date - date).to_i * 24)
|
17
|
+
end
|
18
|
+
|
19
|
+
def time
|
20
|
+
@time ||= parse
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_s
|
24
|
+
date_format = date.strftime(DATE_FORMAT)
|
25
|
+
format = [date_format, TIME_FORMAT].join(" ")
|
26
|
+
format.gsub!(/\%H/, "#{hour}")
|
27
|
+
time.strftime(format)
|
14
28
|
end
|
15
29
|
|
16
30
|
private
|
@@ -21,6 +35,8 @@ class OverTheMidnight::Time
|
|
21
35
|
parse_string
|
22
36
|
when Numeric
|
23
37
|
parse_numeric
|
38
|
+
when Time
|
39
|
+
parse_time
|
24
40
|
else
|
25
41
|
raise "invalid time"
|
26
42
|
end
|
@@ -42,4 +58,8 @@ class OverTheMidnight::Time
|
|
42
58
|
_date = @date + (@raw_time / 24)
|
43
59
|
Time.new(_date.year, _date.month, _date.day, hour, min)
|
44
60
|
end
|
61
|
+
|
62
|
+
def parse_time
|
63
|
+
@raw_time
|
64
|
+
end
|
45
65
|
end
|