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 +4 -4
- data/lib/hellobase.rb +4 -1
- data/lib/hellobase/duration_arithmetic.rb +23 -0
- data/lib/hellobase/duration_creation.rb +9 -0
- data/lib/hellobase/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c814e00e57d6767849c9c27fb41458fa01e32dd833ebabc0907e0b57799ea3ac
|
4
|
+
data.tar.gz: 6ea45cd68519017799bdfe22e65401746a2970c60a436361d70db514e69d67bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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/
|
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
|
+
)
|
data/lib/hellobase/version.rb
CHANGED
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.
|
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
|