win32-taskscheduler 2.0.1 → 2.0.4
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/win32-taskscheduler.rb +1 -1
- data/lib/win32/taskscheduler.rb +266 -292
- data/lib/win32/taskscheduler/constants.rb +6 -6
- data/lib/win32/taskscheduler/helper.rb +10 -10
- data/lib/win32/taskscheduler/sid.rb +12 -12
- data/lib/win32/taskscheduler/time_calc_helper.rb +71 -40
- data/lib/win32/taskscheduler/version.rb +1 -1
- metadata +5 -53
- data/CHANGELOG.md +0 -184
- data/Gemfile +0 -3
- data/README.md +0 -78
- data/RELEASE_NOTES.md +0 -14
- data/Rakefile +0 -38
- data/VERSION +0 -1
- data/appveyor.yml +0 -40
- data/examples/taskscheduler_example.rb +0 -54
- data/spec/functional/win32/taskscheduler/time_calc_helper_spec.rb +0 -392
- data/spec/functional/win32/taskscheduler_spec.rb +0 -883
- data/spec/spec_helper.rb +0 -224
- data/spec/unit/win32/taskscheduler/constants_spec.rb +0 -20
- data/spec/unit/win32/taskscheduler/time_calc_helper_spec.rb +0 -217
- data/spec/unit/win32/taskscheduler_spec.rb +0 -169
- data/test/test_taskscheduler.rb +0 -690
- data/win32-taskscheduler.gemspec +0 -34
data/Gemfile
DELETED
data/README.md
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
# Description
|
2
|
-
|
3
|
-
[](https://badge.fury.io/rb/win32-taskscheduler)
|
4
|
-
|
5
|
-
The win32-taskscheduler library is a Ruby interface to the MS Windows Task Scheduler. It is analogous to the Unix cron daemon.
|
6
|
-
|
7
|
-
# Installation
|
8
|
-
|
9
|
-
```
|
10
|
-
gem install win32-taskscheduler
|
11
|
-
```
|
12
|
-
|
13
|
-
# Synopsis
|
14
|
-
|
15
|
-
```ruby
|
16
|
-
require 'win32/taskscheduler'
|
17
|
-
include Win32
|
18
|
-
|
19
|
-
ts = TaskScheduler.new
|
20
|
-
|
21
|
-
# Create a trigger that starts on April 25, 2014 at 11:05 pm. The trigger
|
22
|
-
# will run on the first and last week of the month, on Monday and Friday,
|
23
|
-
# in the months of April and May.
|
24
|
-
#
|
25
|
-
trigger = {
|
26
|
-
:start_year => 2014,
|
27
|
-
:start_month => 4,
|
28
|
-
:start_day => 25,
|
29
|
-
:start_hour => 23,
|
30
|
-
:start_minute => 5,
|
31
|
-
:trigger_type => TaskScheduler::MONTHLYDOW,
|
32
|
-
:type => {
|
33
|
-
:weeks => TaskScheduler::FIRST_WEEK | TaskScheduler::LAST_WEEK,
|
34
|
-
:days_of_week => TaskScheduler::MONDAY | TaskScheduler::FRIDAY,
|
35
|
-
:months => TaskScheduler::APRIL | TaskScheduler::MAY
|
36
|
-
}
|
37
|
-
}
|
38
|
-
|
39
|
-
ts.new_work_item('my_notepad', trigger)
|
40
|
-
ts.application_name = 'notepad.exe'
|
41
|
-
ts.activate('my_notepad')
|
42
|
-
```
|
43
|
-
|
44
|
-
# Documentation
|
45
|
-
|
46
|
-
If you installed this library as a gem then the documentation was built for you and can be viewed if your gem server is running. There is also some documentation on the github wiki page.
|
47
|
-
|
48
|
-
# Acknowledgements
|
49
|
-
|
50
|
-
This library was modeled to some degree on the Win32::TaskScheduler Perl module by Umberto Nicoletti. However, there are some differences. Please see the documentation for details.
|
51
|
-
|
52
|
-
# Warranty
|
53
|
-
|
54
|
-
This package is provided "as is" and without any express or implied warranties, including, without limitation, the implied warranties of merchantability and fitness for a particular purpose.
|
55
|
-
|
56
|
-
# Known Issues
|
57
|
-
|
58
|
-
Some versions of Ruby have been known to segfault when attempting to create a task. If this happens you will need to upgrade your version of Ruby. Or, at least, your version of win32ole.
|
59
|
-
|
60
|
-
In some cases JRuby appears to raise a native exception rather than a Ruby exception on failure. This should be mostly harmless.
|
61
|
-
|
62
|
-
Please submit any bug reports to the project page at:
|
63
|
-
|
64
|
-
<http://github.com/chef/win32-taskscheduler>
|
65
|
-
|
66
|
-
# Copyright
|
67
|
-
|
68
|
-
- (C) 2003-2017 Daniel J. Berger All Rights Reserved
|
69
|
-
- (C) 2018 Chef Software, Inc. All Rights Reserved
|
70
|
-
|
71
|
-
# License
|
72
|
-
|
73
|
-
Artistic 2.0
|
74
|
-
|
75
|
-
# Authors
|
76
|
-
|
77
|
-
- Park Heesob
|
78
|
-
- Daniel Berger
|
data/RELEASE_NOTES.md
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
<!---
|
2
|
-
This file is reset every time a new release is done. The contents of this file are for the currently unreleased version.
|
3
|
-
|
4
|
-
Example Note:
|
5
|
-
|
6
|
-
## Example Heading
|
7
|
-
Details about the thing that changed that needs to get included in the Release Notes in markdown.
|
8
|
-
-->
|
9
|
-
|
10
|
-
# win32-taskscheduler 0.4.1 release notes:
|
11
|
-
In this release we have fixed issue as below:
|
12
|
-
|
13
|
-
-- Fix the issue of "no mapping" while creating Windows task for SYSTEM USERS. [Issue: https://github.com/chef/chef/issues/7227]
|
14
|
-
|
data/Rakefile
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'rake'
|
2
|
-
require 'rake/clean'
|
3
|
-
require 'rake/testtask'
|
4
|
-
require 'rspec/core/rake_task'
|
5
|
-
|
6
|
-
CLEAN.include("**/*.gem", "**/*.rbc")
|
7
|
-
|
8
|
-
namespace 'gem' do
|
9
|
-
desc 'Build the win32-taskscheduler gem'
|
10
|
-
task :create => [:clean] do
|
11
|
-
require 'rubygems/package'
|
12
|
-
spec = eval(IO.read('win32-taskscheduler.gemspec'))
|
13
|
-
Gem::Package.build(spec, true)
|
14
|
-
end
|
15
|
-
|
16
|
-
desc 'Install the win32-taskscheduler library as a gem'
|
17
|
-
task :install => [:create] do
|
18
|
-
file = Dir['win32-taskscheduler*.gem'].first
|
19
|
-
sh "gem install -l #{file}"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
desc 'Run the example code'
|
24
|
-
task :example do
|
25
|
-
ruby '-Iib examples/taskscheduler_example.rb'
|
26
|
-
end
|
27
|
-
|
28
|
-
RSpec::Core::RakeTask.new(:spec) do |spec|
|
29
|
-
spec.pattern = FileList["spec/**/*_spec.rb", "spec/**/**/*_spec.rb"].to_a
|
30
|
-
end
|
31
|
-
|
32
|
-
desc 'Run the test suite for the win32-taskscheduler library'
|
33
|
-
Rake::TestTask.new do |t|
|
34
|
-
t.verbose = true
|
35
|
-
t.warning = true
|
36
|
-
end
|
37
|
-
|
38
|
-
task :default => :test
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2.0.1
|
data/appveyor.yml
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
version: "ole-{build}"
|
2
|
-
|
3
|
-
os: Windows server 2012
|
4
|
-
platform:
|
5
|
-
- x64
|
6
|
-
|
7
|
-
cache:
|
8
|
-
- vendor/bundle
|
9
|
-
|
10
|
-
clone_folder: c:\projects\win32-taskscheduler
|
11
|
-
clone_depth: 1
|
12
|
-
branches:
|
13
|
-
only:
|
14
|
-
- ole
|
15
|
-
|
16
|
-
environment:
|
17
|
-
matrix:
|
18
|
-
- ruby_version: "25-x64"
|
19
|
-
- ruby_version: "25"
|
20
|
-
- ruby_version: "24-x64"
|
21
|
-
- ruby_version: "24"
|
22
|
-
|
23
|
-
install:
|
24
|
-
- systeminfo
|
25
|
-
- winrm quickconfig -q
|
26
|
-
- SET PATH=C:\Ruby%ruby_version%\bin;%PATH%
|
27
|
-
- echo %PATH%
|
28
|
-
- bundle config --local path vendor/bundle # use the cache we define above
|
29
|
-
|
30
|
-
build_script:
|
31
|
-
- bundle install || bundle install || bundle install
|
32
|
-
|
33
|
-
before_test:
|
34
|
-
- ruby --version
|
35
|
-
- gem --version
|
36
|
-
- bundler --version
|
37
|
-
- bundle env
|
38
|
-
|
39
|
-
test_script:
|
40
|
-
- bundle exec rake spec
|
@@ -1,54 +0,0 @@
|
|
1
|
-
#######################################################################
|
2
|
-
# taskscheduler_example.rb
|
3
|
-
#
|
4
|
-
# A test script for general futzing. You can run this example via the
|
5
|
-
# 'example' rake task.
|
6
|
-
#
|
7
|
-
# Modify as you see fit.
|
8
|
-
#######################################################################
|
9
|
-
require "win32/taskscheduler"
|
10
|
-
require "fileutils"
|
11
|
-
require "pp"
|
12
|
-
include Win32
|
13
|
-
|
14
|
-
puts "VERSION: " + TaskScheduler::VERSION
|
15
|
-
|
16
|
-
ts = TaskScheduler.new
|
17
|
-
|
18
|
-
trigger = {
|
19
|
-
start_year: 2009,
|
20
|
-
start_month: 4,
|
21
|
-
start_day: 11,
|
22
|
-
start_hour: 7,
|
23
|
-
start_minute: 14,
|
24
|
-
trigger_type: TaskScheduler::DAILY,
|
25
|
-
type: { "days_interval" => 1 }
|
26
|
-
}
|
27
|
-
|
28
|
-
unless ts.enum.grep(/foo/).length > 0
|
29
|
-
ts.new_work_item("foo", trigger)
|
30
|
-
ts.application_name = "notepad.exe"
|
31
|
-
puts "Task Added"
|
32
|
-
end
|
33
|
-
|
34
|
-
ts.activate("foo")
|
35
|
-
ts.priority = TaskScheduler::IDLE
|
36
|
-
ts.working_directory = "C:\\"
|
37
|
-
|
38
|
-
puts "App name: " + ts.application_name
|
39
|
-
puts "Creator: " + ts.creator
|
40
|
-
puts "Exit code: " + ts.exit_code.to_s
|
41
|
-
puts "Max run time: " + ts.max_run_time.to_s
|
42
|
-
puts "Next run time: " + ts.next_run_time.to_s
|
43
|
-
puts "Parameters: " + ts.parameters
|
44
|
-
puts "Priority: " + ts.priority.to_s
|
45
|
-
puts "Status: " + ts.status
|
46
|
-
puts "Trigger count: " + ts.trigger_count.to_s
|
47
|
-
puts "Trigger string: " + ts.trigger_string(0)
|
48
|
-
puts "Working directory: " + ts.working_directory
|
49
|
-
puts "Trigger: "
|
50
|
-
|
51
|
-
pp ts.trigger(0)
|
52
|
-
|
53
|
-
ts.delete("foo")
|
54
|
-
puts "Task deleted"
|
@@ -1,392 +0,0 @@
|
|
1
|
-
require 'win32/taskscheduler/time_calc_helper'
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
RSpec.describe Win32::TaskScheduler::TimeCalcHelper do
|
5
|
-
let(:object) { klass.new }
|
6
|
-
let(:klass) do
|
7
|
-
Class.new do
|
8
|
-
include Win32::TaskScheduler::TimeCalcHelper
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
describe 'Format Test:' do
|
13
|
-
context 'An Invalid Date-Time string' do
|
14
|
-
time_str = 'An Invalid String'
|
15
|
-
let(:time_details) { object.time_details(time_str) }
|
16
|
-
it 'Returns an empty hash' do
|
17
|
-
expect(time_details).to be_a(Hash)
|
18
|
-
expect(time_details).to be_empty
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
context 'A valid Date string' do
|
23
|
-
time_str = 'P1Y2M3D'
|
24
|
-
let(:time_details) { object.time_details(time_str) }
|
25
|
-
it 'Returns a valid Hash with only Date values' do
|
26
|
-
expect(time_details).to be_a(Hash)
|
27
|
-
expect(time_details[:year]).to eql('1')
|
28
|
-
expect(time_details[:month]).to eql('2')
|
29
|
-
expect(time_details[:day]).to eql('3')
|
30
|
-
expect(time_details[:hour]).to be_nil
|
31
|
-
expect(time_details[:min]).to be_nil
|
32
|
-
expect(time_details[:sec]).to be_nil
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
context 'A valid Time string' do
|
37
|
-
time_str = 'PT4H5M6S'
|
38
|
-
let(:time_details) { object.time_details(time_str) }
|
39
|
-
it 'Returns a valid Hash with only Time values' do
|
40
|
-
expect(time_details).to be_a(Hash)
|
41
|
-
expect(time_details[:year]).to be_nil
|
42
|
-
expect(time_details[:month]).to be_nil
|
43
|
-
expect(time_details[:day]).to be_nil
|
44
|
-
expect(time_details[:hour]).to eql('4')
|
45
|
-
expect(time_details[:min]).to eql('5')
|
46
|
-
expect(time_details[:sec]).to eql('6')
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
context 'A valid Date-Time string' do
|
51
|
-
time_str = 'P1Y2M3DT4H5M6S'
|
52
|
-
let(:time_details) { object.time_details(time_str) }
|
53
|
-
it 'returns a valid Hash with values' do
|
54
|
-
expect(time_details).to be_a(Hash)
|
55
|
-
expect(time_details[:year]).to eql('1')
|
56
|
-
expect(time_details[:month]).to eql('2')
|
57
|
-
expect(time_details[:day]).to eql('3')
|
58
|
-
expect(time_details[:hour]).to eql('4')
|
59
|
-
expect(time_details[:min]).to eql('5')
|
60
|
-
expect(time_details[:sec]).to eql('6')
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
context 'An Unformatted Date-Time string' do
|
65
|
-
time_str = 'P2M3D1YT6S5M4H'
|
66
|
-
let(:time_details) { object.time_details(time_str) }
|
67
|
-
it 'Returns a valid Hash with values' do
|
68
|
-
expect(time_details).to be_a(Hash)
|
69
|
-
expect(time_details[:year]).to eql('1')
|
70
|
-
expect(time_details[:month]).to eql('2')
|
71
|
-
expect(time_details[:day]).to eql('3')
|
72
|
-
expect(time_details[:hour]).to eql('4')
|
73
|
-
expect(time_details[:min]).to eql('5')
|
74
|
-
expect(time_details[:sec]).to eql('6')
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
context 'A Date-Time string with few parameters' do
|
79
|
-
time_str = 'P1Y2MT3M4S'
|
80
|
-
let(:time_details) { object.time_details(time_str) }
|
81
|
-
it 'Returns a valid Hash with selected values' do
|
82
|
-
expect(time_details).to be_a(Hash)
|
83
|
-
expect(time_details[:year]).to eql('1')
|
84
|
-
expect(time_details[:month]).to eql('2')
|
85
|
-
expect(time_details[:day]).to be_nil
|
86
|
-
expect(time_details[:hour]).to be_nil
|
87
|
-
expect(time_details[:min]).to eql('3')
|
88
|
-
expect(time_details[:sec]).to eql('4')
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
describe 'Year conversion:' do
|
94
|
-
# Time.now to be a Non-Leap Year(0001-01-01 00:00:00), So that
|
95
|
-
# Tests suites will be independant of their execution Time
|
96
|
-
before(:each) do
|
97
|
-
allow(Time).to receive(:now).and_return(Time.new(1))
|
98
|
-
end
|
99
|
-
|
100
|
-
let(:current_time) { Time.new(1) }
|
101
|
-
context 'on given year' do
|
102
|
-
time_str = 'P1Y'
|
103
|
-
let(:time_seconds) { object.time_in_seconds(time_str) }
|
104
|
-
let(:next_time) { current_time + time_seconds }
|
105
|
-
it 'returns expected year' do
|
106
|
-
expect(next_time.year).to eql(current_time.year + 1)
|
107
|
-
expect(next_time.month).to eql(current_time.month)
|
108
|
-
expect(next_time.day).to eql(current_time.day)
|
109
|
-
expect(next_time.hour).to eql(current_time.hour)
|
110
|
-
expect(next_time.min).to eql(current_time.min)
|
111
|
-
expect(next_time.sec).to eql(current_time.sec)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
context 'on given months' do
|
116
|
-
time_str = 'P12M'
|
117
|
-
let(:time_seconds) { object.time_in_seconds(time_str) }
|
118
|
-
let(:next_time) { current_time + time_seconds }
|
119
|
-
it 'returns expected year' do
|
120
|
-
expect(next_time.year).to eql(current_time.year + 1)
|
121
|
-
expect(next_time.month).to eql(current_time.month)
|
122
|
-
expect(next_time.day).to eql(current_time.day)
|
123
|
-
expect(next_time.hour).to eql(current_time.hour)
|
124
|
-
expect(next_time.min).to eql(current_time.min)
|
125
|
-
expect(next_time.sec).to eql(current_time.sec)
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
context 'on given days' do
|
130
|
-
time_str = 'P365D'
|
131
|
-
let(:time_seconds) { object.time_in_seconds(time_str) }
|
132
|
-
let(:next_time) { current_time + time_seconds }
|
133
|
-
it 'returns expected year' do
|
134
|
-
expect(next_time.year).to eql(current_time.year + 1)
|
135
|
-
expect(next_time.month).to eql(current_time.month)
|
136
|
-
expect(next_time.day).to eql(current_time.day)
|
137
|
-
expect(next_time.hour).to eql(current_time.hour)
|
138
|
-
expect(next_time.min).to eql(current_time.min)
|
139
|
-
expect(next_time.sec).to eql(current_time.sec)
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
context 'by given year and month' do
|
144
|
-
time_str = 'P1Y12M'
|
145
|
-
let(:time_seconds) { object.time_in_seconds(time_str) }
|
146
|
-
let(:next_time) { current_time + time_seconds }
|
147
|
-
it 'returns expected year' do
|
148
|
-
expect(next_time.year).to eql(current_time.year + 2)
|
149
|
-
expect(next_time.month).to eql(current_time.month)
|
150
|
-
expect(next_time.day).to eql(current_time.day)
|
151
|
-
expect(next_time.hour).to eql(current_time.hour)
|
152
|
-
expect(next_time.min).to eql(current_time.min)
|
153
|
-
expect(next_time.sec).to eql(current_time.sec)
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
context 'by given year, months and days' do
|
158
|
-
time_str = 'P1Y12M365D'
|
159
|
-
let(:time_seconds) { object.time_in_seconds(time_str) }
|
160
|
-
let(:next_time) { current_time + time_seconds }
|
161
|
-
it 'Returns the actual incremented day' do
|
162
|
-
expect(next_time.year).to eql(current_time.year + 3)
|
163
|
-
expect(next_time.month).to eql(current_time.month)
|
164
|
-
expect(next_time.day).to eql(current_time.day)
|
165
|
-
expect(next_time.hour).to eql(current_time.hour)
|
166
|
-
expect(next_time.min).to eql(current_time.min)
|
167
|
-
expect(next_time.sec).to eql(current_time.sec)
|
168
|
-
end
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
describe 'Month conversion:' do
|
173
|
-
# Time.now to be a Non-Leap Year(0001-01-01 00:00:00), So that
|
174
|
-
# Tests suites will be independant of their execution Time
|
175
|
-
before(:each) do
|
176
|
-
allow(Time).to receive(:now).and_return(Time.new(1))
|
177
|
-
end
|
178
|
-
|
179
|
-
let(:current_time) { Time.new(1) }
|
180
|
-
context 'on given month' do
|
181
|
-
time_str = 'P1M'
|
182
|
-
let(:time_seconds) { object.time_in_seconds(time_str) }
|
183
|
-
let(:next_time) { current_time + time_seconds }
|
184
|
-
it 'returns expected month' do
|
185
|
-
expect(next_time.year).to eql(current_time.year)
|
186
|
-
expect(next_time.month).to eql(current_time.month + 1)
|
187
|
-
expect(next_time.day).to eql(current_time.day)
|
188
|
-
expect(next_time.hour).to eql(current_time.hour)
|
189
|
-
expect(next_time.min).to eql(current_time.min)
|
190
|
-
expect(next_time.sec).to eql(current_time.sec)
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
context 'on given days' do
|
195
|
-
# Since we are running test on 1st month, next month will occur in 31 days
|
196
|
-
time_str = 'P31D'
|
197
|
-
let(:time_seconds) { object.time_in_seconds(time_str) }
|
198
|
-
let(:next_time) { current_time + time_seconds }
|
199
|
-
it 'returns expected month' do
|
200
|
-
expect(next_time.year).to eql(current_time.year)
|
201
|
-
expect(next_time.month).to eql(current_time.month + 1)
|
202
|
-
expect(next_time.day).to eql(current_time.day)
|
203
|
-
expect(next_time.hour).to eql(current_time.hour)
|
204
|
-
expect(next_time.min).to eql(current_time.min)
|
205
|
-
expect(next_time.sec).to eql(current_time.sec)
|
206
|
-
end
|
207
|
-
end
|
208
|
-
|
209
|
-
context 'by given month and days' do
|
210
|
-
# Since we are running test on 1st month, next month will occur in 31 days
|
211
|
-
time_str = 'P1M31D'
|
212
|
-
let(:time_seconds) { object.time_in_seconds(time_str) }
|
213
|
-
let(:next_time) { current_time + time_seconds }
|
214
|
-
it 'returns expected month' do
|
215
|
-
expect(next_time.year).to eql(current_time.year)
|
216
|
-
expect(next_time.month).to eql(current_time.month + 2)
|
217
|
-
expect(next_time.day).to eql(current_time.day)
|
218
|
-
expect(next_time.hour).to eql(current_time.hour)
|
219
|
-
expect(next_time.min).to eql(current_time.min)
|
220
|
-
expect(next_time.sec).to eql(current_time.sec)
|
221
|
-
end
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
describe 'Day conversion:' do
|
226
|
-
# Time.now to be a Non-Leap Year(0001-01-01 00:00:00), So that
|
227
|
-
# Tests suites will be independant of their execution Time
|
228
|
-
before(:each) do
|
229
|
-
allow(Time).to receive(:now).and_return(Time.new(1))
|
230
|
-
end
|
231
|
-
|
232
|
-
let(:current_time) { Time.new(1) }
|
233
|
-
context 'on given days' do
|
234
|
-
time_str = 'P1D'
|
235
|
-
let(:time_seconds) { object.time_in_seconds(time_str) }
|
236
|
-
let(:next_time) { current_time + time_seconds }
|
237
|
-
it 'returns expected days' do
|
238
|
-
expect(next_time.year).to eql(current_time.year)
|
239
|
-
expect(next_time.month).to eql(current_time.month)
|
240
|
-
expect(next_time.day).to eql(current_time.day + 1)
|
241
|
-
expect(next_time.hour).to eql(current_time.hour)
|
242
|
-
expect(next_time.min).to eql(current_time.min)
|
243
|
-
expect(next_time.sec).to eql(current_time.sec)
|
244
|
-
end
|
245
|
-
end
|
246
|
-
|
247
|
-
context 'on given hours' do
|
248
|
-
time_str = 'PT24H'
|
249
|
-
let(:time_seconds) { object.time_in_seconds(time_str) }
|
250
|
-
let(:next_time) { current_time + time_seconds }
|
251
|
-
it 'returns expected days' do
|
252
|
-
expect(next_time.year).to eql(current_time.year)
|
253
|
-
expect(next_time.month).to eql(current_time.month)
|
254
|
-
expect(next_time.day).to eql(current_time.day + 1)
|
255
|
-
expect(next_time.hour).to eql(current_time.hour)
|
256
|
-
expect(next_time.min).to eql(current_time.min)
|
257
|
-
expect(next_time.sec).to eql(current_time.sec)
|
258
|
-
end
|
259
|
-
end
|
260
|
-
|
261
|
-
context 'on given minutes' do
|
262
|
-
time_str = 'PT1440M'
|
263
|
-
let(:time_seconds) { object.time_in_seconds(time_str) }
|
264
|
-
let(:next_time) { current_time + time_seconds }
|
265
|
-
it 'returns expected days' do
|
266
|
-
expect(next_time.year).to eql(current_time.year)
|
267
|
-
expect(next_time.month).to eql(current_time.month)
|
268
|
-
expect(next_time.day).to eql(current_time.day + 1)
|
269
|
-
expect(next_time.hour).to eql(current_time.hour)
|
270
|
-
expect(next_time.min).to eql(current_time.min)
|
271
|
-
expect(next_time.sec).to eql(current_time.sec)
|
272
|
-
end
|
273
|
-
end
|
274
|
-
|
275
|
-
context 'on given seconds' do
|
276
|
-
time_str = 'PT86400S'
|
277
|
-
let(:time_seconds) { object.time_in_seconds(time_str) }
|
278
|
-
let(:next_time) { current_time + time_seconds }
|
279
|
-
it 'returns expected days' do
|
280
|
-
expect(next_time.year).to eql(current_time.year)
|
281
|
-
expect(next_time.month).to eql(current_time.month)
|
282
|
-
expect(next_time.day).to eql(current_time.day + 1)
|
283
|
-
expect(next_time.hour).to eql(current_time.hour)
|
284
|
-
expect(next_time.min).to eql(current_time.min)
|
285
|
-
expect(next_time.sec).to eql(current_time.sec)
|
286
|
-
end
|
287
|
-
end
|
288
|
-
|
289
|
-
context 'By the given days, hours, minutes and seconds' do
|
290
|
-
time_str = 'P1DT24H1440M86400S'
|
291
|
-
let(:time_seconds) { object.time_in_seconds(time_str) }
|
292
|
-
let(:next_time) { current_time + time_seconds }
|
293
|
-
it 'returns expected days' do
|
294
|
-
expect(next_time.year).to eql(current_time.year)
|
295
|
-
expect(next_time.month).to eql(current_time.month)
|
296
|
-
expect(next_time.day).to eql(current_time.day + 4)
|
297
|
-
expect(next_time.hour).to eql(current_time.hour)
|
298
|
-
expect(next_time.min).to eql(current_time.min)
|
299
|
-
expect(next_time.sec).to eql(current_time.sec)
|
300
|
-
end
|
301
|
-
end
|
302
|
-
end
|
303
|
-
|
304
|
-
describe 'Minute conversion:' do
|
305
|
-
# Time.now to be a Non-Leap Year(0001-01-01 00:00:00), So that
|
306
|
-
# Tests suites will be independant of their execution Time
|
307
|
-
before(:each) do
|
308
|
-
allow(Time).to receive(:now).and_return(Time.new(1))
|
309
|
-
end
|
310
|
-
|
311
|
-
let(:current_time) { Time.new(1) }
|
312
|
-
context 'on given minute' do
|
313
|
-
time_str = 'PT1M'
|
314
|
-
let(:time_seconds) { object.time_in_seconds(time_str) }
|
315
|
-
let(:next_time) { current_time + time_seconds }
|
316
|
-
it 'returns expected minutes' do
|
317
|
-
expect(next_time.year).to eql(current_time.year)
|
318
|
-
expect(next_time.month).to eql(current_time.month)
|
319
|
-
expect(next_time.day).to eql(current_time.day)
|
320
|
-
expect(next_time.hour).to eql(current_time.hour)
|
321
|
-
expect(next_time.min).to eql(current_time.min + 1)
|
322
|
-
expect(next_time.sec).to eql(current_time.sec)
|
323
|
-
end
|
324
|
-
end
|
325
|
-
|
326
|
-
context 'on given seconds' do
|
327
|
-
time_str = 'PT60S'
|
328
|
-
let(:time_seconds) { object.time_in_seconds(time_str) }
|
329
|
-
let(:next_time) { current_time + time_seconds }
|
330
|
-
it 'returns expected minutes' do
|
331
|
-
expect(next_time.year).to eql(current_time.year)
|
332
|
-
expect(next_time.month).to eql(current_time.month)
|
333
|
-
expect(next_time.day).to eql(current_time.day)
|
334
|
-
expect(next_time.hour).to eql(current_time.hour)
|
335
|
-
expect(next_time.min).to eql(current_time.min + 1)
|
336
|
-
expect(next_time.sec).to eql(current_time.sec)
|
337
|
-
end
|
338
|
-
end
|
339
|
-
|
340
|
-
context 'By given minutes and seconds' do
|
341
|
-
time_str = 'PT1M60S'
|
342
|
-
let(:time_seconds) { object.time_in_seconds(time_str) }
|
343
|
-
let(:next_time) { current_time + time_seconds }
|
344
|
-
it 'returns expected minutes' do
|
345
|
-
expect(next_time.year).to eql(current_time.year)
|
346
|
-
expect(next_time.month).to eql(current_time.month)
|
347
|
-
expect(next_time.day).to eql(current_time.day)
|
348
|
-
expect(next_time.hour).to eql(current_time.hour)
|
349
|
-
expect(next_time.min).to eql(current_time.min + 2)
|
350
|
-
expect(next_time.sec).to eql(current_time.sec)
|
351
|
-
end
|
352
|
-
end
|
353
|
-
end
|
354
|
-
|
355
|
-
describe 'Date-Time conversions:' do
|
356
|
-
# For a single string given in leap/non-leap year
|
357
|
-
time_str = 'P400Y500M600DT700H800M900S'
|
358
|
-
|
359
|
-
context 'In a non leap year' do
|
360
|
-
let(:current_time) { Time.new(1) }
|
361
|
-
let(:time_seconds) { object.time_in_seconds(time_str) }
|
362
|
-
let(:next_time) { current_time + time_seconds }
|
363
|
-
it 'returns expected values' do
|
364
|
-
allow(Time).to receive(:now).and_return(Time.new(1))
|
365
|
-
|
366
|
-
expect(next_time.year).to eql(current_time.year + 443)
|
367
|
-
expect(next_time.month).to eql(current_time.month + 4)
|
368
|
-
expect(next_time.day).to eql(current_time.day + 21)
|
369
|
-
expect(next_time.hour).to eql(current_time.hour + 17)
|
370
|
-
expect(next_time.min).to eql(current_time.min + 35)
|
371
|
-
expect(next_time.sec).to eql(current_time.sec)
|
372
|
-
end
|
373
|
-
end
|
374
|
-
|
375
|
-
context 'In a leap year' do
|
376
|
-
let(:current_time) { Time.new(0) }
|
377
|
-
let(:time_seconds) { object.time_in_seconds(time_str) }
|
378
|
-
let(:next_time) { current_time + time_seconds }
|
379
|
-
it 'returns expected values' do
|
380
|
-
allow(Time).to receive(:now).and_return(Time.new(0))
|
381
|
-
|
382
|
-
# 1 Day less for the same string
|
383
|
-
expect(next_time.year).to eql(current_time.year + 443)
|
384
|
-
expect(next_time.month).to eql(current_time.month + 4)
|
385
|
-
expect(next_time.day).to eql(current_time.day + 20)
|
386
|
-
expect(next_time.hour).to eql(current_time.hour + 17)
|
387
|
-
expect(next_time.min).to eql(current_time.min + 35)
|
388
|
-
expect(next_time.sec).to eql(current_time.sec)
|
389
|
-
end
|
390
|
-
end
|
391
|
-
end
|
392
|
-
end
|