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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ed6b5fa818bdb8effe154d73e21ef88a433f3ad1
4
- data.tar.gz: ad59b935768f11444d9b2d13289c57ba5c2b25e9
3
+ metadata.gz: c58785a99ed7c9fb62a41d421569b2ce5b8e3a94
4
+ data.tar.gz: c59ebe0f315adce3039242ab3b837e16c7c65f3a
5
5
  SHA512:
6
- metadata.gz: a2a27deda39995e0d24824eac83cfb1197b56aa7c115760173ebca7f7d968da6bd713dc29d8957f63430d37f1dc08be66c645c7b9cf842ee9be4d1057a50cc9a
7
- data.tar.gz: 804a6cf89eaf5a0ae3de2f63907176c233182fe786eb177e00cb887f73b3532a8add0a2505cb2a95923dc5083c2605d96534b105aa10359ffea7376c50f4faed
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
- require "over_the_midnight"
28
- otm = OverTheMidnight.new(date, "25:00")
29
- otm.to_time.strftime("%Y/%m/%d %H:%M")
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 = OverTheMidnight.new(date, 30.5)
33
- otm.to_time.strftime("%Y/%m/%d %H:%M")
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
@@ -4,7 +4,7 @@ module OverTheMidnight
4
4
  LIB = File.expand_path(File.dirname(__FILE__))
5
5
  ROOT = File.dirname(OverTheMidnight::LIB)
6
6
 
7
- def self.new(*args)
7
+ def self.create(*args)
8
8
  self::Time.new(*args)
9
9
  end
10
10
  end
@@ -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 to_time
13
- parse
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
@@ -1,3 +1,3 @@
1
1
  module OverTheMidnight
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: over_the_midnight
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
7
  - sekizo