hellobase 0.1.5 → 0.1.6

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: c9a3bef090b09fe7abe292328fa8b00651b5848175316252dade58061967cb26
4
- data.tar.gz: 11b1384b3789910fe052ee4ae90d9d74253d917aefff90895a24caec54226566
3
+ metadata.gz: c814e00e57d6767849c9c27fb41458fa01e32dd833ebabc0907e0b57799ea3ac
4
+ data.tar.gz: 6ea45cd68519017799bdfe22e65401746a2970c60a436361d70db514e69d67bb
5
5
  SHA512:
6
- metadata.gz: f5bd340087ddc083027a3eefbf14c5874646399652891f522fda9d5a988886ff5724cfd1a8861a208a13044af70d98dfe7f08aba11a5a4c9b3b3e641735a6f7e
7
- data.tar.gz: 23e2691a82055e76dc64cbd464bfe739de824c1843805a8ee4ad6e2c0a2114522952aeb39163068b7d5f6910378adc7fb0c5f549bbc91e185b75737175cc9c3b
6
+ metadata.gz: af434eb545c62fba36bbeadc02bd42f64ce51e1589f95688b2c59e7980fe6b4d95959a7c9fed1ace55ee291f37737d5bed304b48331119598149d98a49bd7b5d
7
+ data.tar.gz: f329e56d95923a8ac6e3cfb0dc130f35215960533c00f2ba661467acdebf00662d31580178fc7199dc03d119ad848f1022bf7132e895ddf31e14c21136ba5105
data/lib/hellobase.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'bigdecimal'
2
2
  require 'date'
3
3
  require 'active_support/core_ext/date'
4
- require 'active_support/core_ext/date_time'
4
+ require 'active_support/core_ext/time'
5
5
  require 'active_support/duration'
6
6
  require 'tod'
7
7
 
@@ -9,6 +9,8 @@ require 'hellobase/array_access'
9
9
  require 'hellobase/date_creation'
10
10
  require 'hellobase/datetime_creation'
11
11
  require 'hellobase/divide_by_zero'
12
+ require 'hellobase/duration_arithmetic'
13
+ require 'hellobase/duration_creation'
12
14
  require 'hellobase/string_access'
13
15
  require 'hellobase/time_creation'
14
16
 
@@ -16,6 +18,7 @@ module Hellobase
16
18
  DATE_FORMAT = /^\d{4}-\d{2}-\d{2}$/
17
19
  TIME_FORMAT = /^\d{2}:\d{2}:\d{2}$/
18
20
  DATETIME_FORMAT = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} UTC$/
21
+ DURATION_FORMAT = /^P-?\d+Y-?\d+M-?\d+DT-?\d+H-?\d+M-?\d+S$/
19
22
 
20
23
  class Error < StandardError
21
24
  attr_reader :type, :object
@@ -0,0 +1,23 @@
1
+ ActiveSupport::Duration.prepend(
2
+ Module.new do
3
+ def before(val)
4
+ raise Hellobase::Error.new(:duration_arithmetic, nil, self) if val.is_a?(Date) && has_time_parts?
5
+
6
+ super
7
+ end
8
+
9
+ def after(val)
10
+ raise Hellobase::Error.new(:duration_arithmetic, nil, self) if val.is_a?(Date) && has_time_parts?
11
+
12
+ super
13
+ end
14
+
15
+ private
16
+
17
+ def has_time_parts?
18
+ ((parts[:hours] || 0) != 0) ||
19
+ ((parts[:minutes] || 0) != 0) ||
20
+ ((parts[:seconds] || 0) != 0)
21
+ end
22
+ end
23
+ )
@@ -0,0 +1,9 @@
1
+ ActiveSupport::Duration.singleton_class.prepend(
2
+ Module.new do
3
+ def parse(string)
4
+ raise Hellobase::Error.new(:duration_format, nil, string) unless string =~ Hellobase::DURATION_FORMAT
5
+
6
+ super
7
+ end
8
+ end
9
+ )
@@ -1,3 +1,3 @@
1
1
  module Hellobase
2
- VERSION = '0.1.5'
2
+ VERSION = '0.1.6'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hellobase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anthony Wang
@@ -85,6 +85,8 @@ files:
85
85
  - lib/hellobase/date_creation.rb
86
86
  - lib/hellobase/datetime_creation.rb
87
87
  - lib/hellobase/divide_by_zero.rb
88
+ - lib/hellobase/duration_arithmetic.rb
89
+ - lib/hellobase/duration_creation.rb
88
90
  - lib/hellobase/string_access.rb
89
91
  - lib/hellobase/time_creation.rb
90
92
  - lib/hellobase/version.rb