dohutil 0.2.18 → 0.2.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dohutil/core_ext/datewithtime.rb +14 -11
- data/lib/dohutil/move_weekday.rb +19 -0
- data/test/core_ext/force_deep_copy.dt.rb +12 -0
- data/test/move_weekday.dt.rb +14 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 11e21aabdec5db1053d2a609c679cb848d5f32de
|
4
|
+
data.tar.gz: 4f9c3de05bea5bb32f9f38d9f265a98eaee187fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 208b4173bc678932f4918b17368bacf6c307a2f81ce69cde3d7296e12437391dbd84d2b9ce3953637acea6569283a63fcbabe73bf11367feaab98ed03c4c75d4
|
7
|
+
data.tar.gz: 5e035ce4725f6db7b5224ab33fa94978b94c4d4339397e4db8829303eed41a7946fcb46802fb016b5a7e65e782cee03df424cfbaa9cdfba60008a11fffb1f9c9
|
@@ -2,22 +2,22 @@ require 'date'
|
|
2
2
|
require 'time'
|
3
3
|
|
4
4
|
class DateTime
|
5
|
-
|
6
|
-
unless const_defined?(:SECONDS_IN_DAY)
|
7
|
-
SECONDS_IN_DAY = Rational(1, 60 * 60 * 24)
|
8
|
-
end
|
5
|
+
DAY_SECONDS = 60 * 60 * 24
|
9
6
|
|
10
7
|
def self.zow
|
11
|
-
|
12
|
-
|
8
|
+
now.zowify
|
9
|
+
end
|
10
|
+
|
11
|
+
def zowify
|
12
|
+
self.class.new(year, month, mday, hour, min, sec, 0)
|
13
13
|
end
|
14
14
|
|
15
15
|
def self.seconds_to_days(seconds)
|
16
|
-
seconds.to_f
|
16
|
+
seconds.to_f / DAY_SECONDS.to_f
|
17
17
|
end
|
18
18
|
|
19
19
|
def next_second(n = 1)
|
20
|
-
self + (
|
20
|
+
self + self.class.seconds_to_days(n)
|
21
21
|
end
|
22
22
|
|
23
23
|
def prev_second(n = 1)
|
@@ -26,14 +26,17 @@ class DateTime
|
|
26
26
|
|
27
27
|
# subtract another DateTime object, return difference in seconds
|
28
28
|
def sub_dt(other)
|
29
|
-
((self - other)
|
29
|
+
((self - other) * DAY_SECONDS).to_i
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
33
|
class Time
|
34
34
|
def self.zow
|
35
|
-
|
36
|
-
|
35
|
+
now.zowify
|
36
|
+
end
|
37
|
+
|
38
|
+
def zowify
|
39
|
+
self.class.new(year, month, mday, hour, min, sec, 0)
|
37
40
|
end
|
38
41
|
|
39
42
|
def next_second(n = 1)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'dohutil/core_ext/date'
|
2
|
+
|
3
|
+
class Date
|
4
|
+
def next_weekday
|
5
|
+
retval = self + 1
|
6
|
+
until retval.weekday?
|
7
|
+
retval += 1
|
8
|
+
end
|
9
|
+
retval
|
10
|
+
end
|
11
|
+
|
12
|
+
def previous_weekday
|
13
|
+
retval = self - 1
|
14
|
+
until retval.weekday?
|
15
|
+
retval -= 1
|
16
|
+
end
|
17
|
+
retval
|
18
|
+
end
|
19
|
+
end
|
@@ -5,15 +5,27 @@ module Doh
|
|
5
5
|
class Parent
|
6
6
|
force_deep_copy :var1, :var2
|
7
7
|
attr_accessor :var1, :var2
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@var1 = @var2 = nil
|
11
|
+
end
|
8
12
|
end
|
9
13
|
|
10
14
|
class Child < Parent
|
11
15
|
force_deep_copy :var3
|
12
16
|
attr_accessor :var3
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
@var3 = nil
|
20
|
+
end
|
13
21
|
end
|
14
22
|
|
15
23
|
class ShallowParent
|
16
24
|
attr_accessor :var1, :var2
|
25
|
+
|
26
|
+
def initialize
|
27
|
+
@var1 = @var2 = nil
|
28
|
+
end
|
17
29
|
end
|
18
30
|
|
19
31
|
class Test_core_ext_force_deep_copy < DohTest::TestGroup
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'dohutil/move_weekday'
|
2
|
+
|
3
|
+
module Doh
|
4
|
+
|
5
|
+
class TestMoveWeekday < DohTest::TestGroup
|
6
|
+
def test_move_weekday
|
7
|
+
assert_equal(Date.new(2011, 11, 11).to_s, Date.new(2011, 11, 10).next_weekday.to_s)
|
8
|
+
assert_equal(Date.new(2011, 11, 14).to_s, Date.new(2011, 11, 11).next_weekday.to_s)
|
9
|
+
assert_equal(Date.new(2011, 11, 11).to_s, Date.new(2011, 11, 14).previous_weekday.to_s)
|
10
|
+
assert_equal(Date.new(2011, 11, 10).to_s, Date.new(2011, 11, 11).previous_weekday.to_s)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dohutil
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.19
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Makani Mason
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-12-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: dohroot
|
@@ -82,6 +82,7 @@ files:
|
|
82
82
|
- lib/dohutil/current_date.rb
|
83
83
|
- lib/dohutil/disable_verbose.rb
|
84
84
|
- lib/dohutil/env.rb
|
85
|
+
- lib/dohutil/move_weekday.rb
|
85
86
|
- lib/dohutil/password_helper.rb
|
86
87
|
- lib/dohutil/to_display.rb
|
87
88
|
- test/core_ext/bigdecimal.dt.rb
|
@@ -89,6 +90,7 @@ files:
|
|
89
90
|
- test/core_ext/datewithtime.dt.rb
|
90
91
|
- test/core_ext/force_deep_copy.dt.rb
|
91
92
|
- test/core_ext/string.dt.rb
|
93
|
+
- test/move_weekday.dt.rb
|
92
94
|
- MIT-LICENSE
|
93
95
|
homepage: https://github.com/atpsoft/dohutil
|
94
96
|
licenses:
|
@@ -120,3 +122,4 @@ test_files:
|
|
120
122
|
- test/core_ext/datewithtime.dt.rb
|
121
123
|
- test/core_ext/force_deep_copy.dt.rb
|
122
124
|
- test/core_ext/string.dt.rb
|
125
|
+
- test/move_weekday.dt.rb
|