keyword_arg_time 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +43 -0
- data/Rakefile +6 -0
- data/keyword_arg_time.gemspec +25 -0
- data/lib/keyword_arg_time.rb +8 -0
- data/lib/keyword_arg_time/core_ext/date.rb +25 -0
- data/lib/keyword_arg_time/core_ext/date_time.rb +32 -0
- data/lib/keyword_arg_time/core_ext/time.rb +30 -0
- data/lib/keyword_arg_time/version.rb +3 -0
- data/spec/lib/keyword_arg_time/core_ext/date_spec.rb +20 -0
- data/spec/lib/keyword_arg_time/core_ext/date_time_spec.rb +26 -0
- data/spec/lib/keyword_arg_time/core_ext/time_spec.rb +26 -0
- data/spec/lib/keyword_arg_time_spec.rb +7 -0
- data/spec/spec_helper.rb +12 -0
- metadata +123 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: dd621c37e3abacbd0b697c6049902a3484438ff6
|
4
|
+
data.tar.gz: 0ecb248a3a84e4344e2191f5686b7140d794c7df
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 02bdbec31de52a215be3090b5d420d2b1648eb6d24ff45ef5c5f9411d1c0ef0623525ef2f04fcaaf9b7ef30ed8a66c172ab0eec2cff2ab3fb78b01bb844c8000
|
7
|
+
data.tar.gz: 53a1a072e4cbb703201a861cd5d18393620a0fcbdad4aeea1f95b8f35dd677ef1dfe86a848c30480e31b5ab295fbf6a5be92e65472dfeed4b5fda8fb45e2a244
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 joker1007
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# KeywordArgTime
|
2
|
+
[![Build Status](https://travis-ci.org/joker1007/keyword_arg_time.png?branch=master)](https://travis-ci.org/joker1007/keyword_arg_time)
|
3
|
+
[![Coverage Status](https://coveralls.io/repos/joker1007/keyword_arg_time/badge.png?branch=master)](https://coveralls.io/r/joker1007/keyword_arg_time?branch=master)
|
4
|
+
|
5
|
+
Time or Date object constructer by keyword arguments
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'keyword_arg_time'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install keyword_arg_time
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require 'keyword_arg_time'
|
25
|
+
|
26
|
+
Time.now(hour: 10, min: 15, sec: 0) # => 2014-01-10 10:15:00 +0900
|
27
|
+
|
28
|
+
time = Time.local(2014, 1, 10) # => 2014-01-10 00:00:00 +0900
|
29
|
+
time.copy(hour: 10, min: 15) # => 2014-01-10 10:15:00 +0900
|
30
|
+
|
31
|
+
Date.today(mon: 3) # => <Date: 2014-03-10 ((2456727j,0s,0n),+0s,2299161j)>
|
32
|
+
|
33
|
+
date = Date.new(2014, 1, 10) # => <Date: 2014-01-10 ((2456668j,0s,0n),+0s,2299161j)>
|
34
|
+
date.copy(day: 25) # => <Date: 2014-01-25 ((2456683j,0s,0n),+0s,2299161j)>
|
35
|
+
```
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
1. Fork it ( http://github.com/<my-github-username>/keyword_arg_time/fork )
|
40
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
41
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
42
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
43
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'keyword_arg_time/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "keyword_arg_time"
|
8
|
+
spec.version = KeywordArgTime::VERSION
|
9
|
+
spec.authors = ["joker1007"]
|
10
|
+
spec.email = ["kakyoin.hierophant@gmail.com"]
|
11
|
+
spec.summary = %q{Time or Date object constructer by keyword arguments}
|
12
|
+
spec.description = %q{Time or Date object constructer by keyword arguments}
|
13
|
+
spec.homepage = "https://github.com/joker1007/keyword_arg_time"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency "coveralls"
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
class Date
|
4
|
+
class << self
|
5
|
+
alias_method :__origin_today__, :today
|
6
|
+
|
7
|
+
def today(start = Date::ITALY, year: nil, mon: nil, day: nil)
|
8
|
+
t = __origin_today__(start)
|
9
|
+
|
10
|
+
new(
|
11
|
+
year || t.year,
|
12
|
+
mon || t.mon,
|
13
|
+
day || t.day,
|
14
|
+
)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def copy(year: nil, mon: nil, day: nil)
|
19
|
+
self.class.new(
|
20
|
+
year || self.year,
|
21
|
+
mon || self.mon,
|
22
|
+
day || self.day,
|
23
|
+
)
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
class DateTime
|
4
|
+
class << self
|
5
|
+
alias_method :__origin_now__, :now
|
6
|
+
|
7
|
+
def now(start = Date::ITALY, year: nil, mon: nil, day: nil, hour: nil, min: nil, sec: nil)
|
8
|
+
n = __origin_now__(start)
|
9
|
+
new(
|
10
|
+
year || n.year,
|
11
|
+
mon || n.mon,
|
12
|
+
day || n.day,
|
13
|
+
hour || n.hour,
|
14
|
+
min || n.min,
|
15
|
+
sec || n.sec,
|
16
|
+
start
|
17
|
+
)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def copy(start = Date::ITALY, year: nil, mon: nil, day: nil, hour: nil, min: nil, sec: nil)
|
22
|
+
self.class.new(
|
23
|
+
year || self.year,
|
24
|
+
mon || self.mon,
|
25
|
+
day || self.day,
|
26
|
+
hour || self.hour,
|
27
|
+
min || self.min,
|
28
|
+
sec || self.sec,
|
29
|
+
start
|
30
|
+
)
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class Time
|
2
|
+
class << self
|
3
|
+
alias_method :__origin_now__, :now
|
4
|
+
|
5
|
+
def now(year: nil, mon: nil, day: nil, hour: nil, min: nil, sec: nil, usec: nil)
|
6
|
+
n = __origin_now__
|
7
|
+
local(
|
8
|
+
year || n.year,
|
9
|
+
mon || n.mon,
|
10
|
+
day || n.day,
|
11
|
+
hour || n.hour,
|
12
|
+
min || n.min,
|
13
|
+
sec || n.sec,
|
14
|
+
usec || n.usec,
|
15
|
+
)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def copy(year: nil, mon: nil, day: nil, hour: nil, min: nil, sec: nil, usec: nil)
|
20
|
+
self.class.local(
|
21
|
+
year || self.year,
|
22
|
+
mon || self.mon,
|
23
|
+
day || self.day,
|
24
|
+
hour || self.hour,
|
25
|
+
min || self.min,
|
26
|
+
sec || self.sec,
|
27
|
+
usec || self.usec,
|
28
|
+
)
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Date do
|
4
|
+
describe ".today" do
|
5
|
+
let(:today) { Date.today }
|
6
|
+
subject { Date.today(mon: 10) }
|
7
|
+
|
8
|
+
it { should eq Date.new(today.year, 10, today.day) }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#copy" do
|
12
|
+
let(:date) { Date.new(2013, 10, 1) }
|
13
|
+
|
14
|
+
context "given {mon: 2}" do
|
15
|
+
subject { date.copy(mon: 2) }
|
16
|
+
|
17
|
+
it { should eq Date.new(2013, 2, 1) }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DateTime do
|
4
|
+
describe ".now" do
|
5
|
+
let(:now) { DateTime.now }
|
6
|
+
subject { DateTime.now(hour: 10, min: 0, sec: 5) }
|
7
|
+
|
8
|
+
it { should eq DateTime.new(now.year, now.mon, now.day, 10, 0, 5) }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#copy" do
|
12
|
+
let(:time) { DateTime.new(2012, 4, 1, 10, 0, 0) }
|
13
|
+
|
14
|
+
context "given {hour: 12}" do
|
15
|
+
subject { time.copy(hour: 12) }
|
16
|
+
|
17
|
+
it { should eq DateTime.new(2012, 4, 1, 12, 0, 0) }
|
18
|
+
end
|
19
|
+
|
20
|
+
context "given {hour: 12, sec: 10}" do
|
21
|
+
subject { time.copy(hour: 12, sec: 10) }
|
22
|
+
|
23
|
+
it { should eq DateTime.new(2012, 4, 1, 12, 0, 10) }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Time do
|
4
|
+
describe ".now" do
|
5
|
+
let(:now) { Time.now }
|
6
|
+
subject { Time.now(hour: 10, min: 0, sec: 5, usec: 0) }
|
7
|
+
|
8
|
+
it { should eq Time.local(now.year, now.mon, now.day, 10, 0, 5, 0) }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#copy" do
|
12
|
+
let(:time) { Time.local(2012, 4, 1, 10, 0, 0, 0) }
|
13
|
+
|
14
|
+
context "given {hour: 12}" do
|
15
|
+
subject { time.copy(hour: 12) }
|
16
|
+
|
17
|
+
it { should eq Time.local(2012, 4, 1, 12, 0, 0, 0) }
|
18
|
+
end
|
19
|
+
|
20
|
+
context "given {hour: 12, sec: 10}" do
|
21
|
+
subject { time.copy(hour: 12, sec: 10) }
|
22
|
+
|
23
|
+
it { should eq Time.local(2012, 4, 1, 12, 0, 10, 0) }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'coveralls'
|
2
|
+
Coveralls.wear!
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
6
|
+
config.run_all_when_everything_filtered = true
|
7
|
+
config.filter_run :focus
|
8
|
+
|
9
|
+
config.order = 'random'
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'keyword_arg_time'
|
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: keyword_arg_time
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- joker1007
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: coveralls
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Time or Date object constructer by keyword arguments
|
70
|
+
email:
|
71
|
+
- kakyoin.hierophant@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- keyword_arg_time.gemspec
|
84
|
+
- lib/keyword_arg_time.rb
|
85
|
+
- lib/keyword_arg_time/core_ext/date.rb
|
86
|
+
- lib/keyword_arg_time/core_ext/date_time.rb
|
87
|
+
- lib/keyword_arg_time/core_ext/time.rb
|
88
|
+
- lib/keyword_arg_time/version.rb
|
89
|
+
- spec/lib/keyword_arg_time/core_ext/date_spec.rb
|
90
|
+
- spec/lib/keyword_arg_time/core_ext/date_time_spec.rb
|
91
|
+
- spec/lib/keyword_arg_time/core_ext/time_spec.rb
|
92
|
+
- spec/lib/keyword_arg_time_spec.rb
|
93
|
+
- spec/spec_helper.rb
|
94
|
+
homepage: https://github.com/joker1007/keyword_arg_time
|
95
|
+
licenses:
|
96
|
+
- MIT
|
97
|
+
metadata: {}
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
requirements: []
|
113
|
+
rubyforge_project:
|
114
|
+
rubygems_version: 2.2.0
|
115
|
+
signing_key:
|
116
|
+
specification_version: 4
|
117
|
+
summary: Time or Date object constructer by keyword arguments
|
118
|
+
test_files:
|
119
|
+
- spec/lib/keyword_arg_time/core_ext/date_spec.rb
|
120
|
+
- spec/lib/keyword_arg_time/core_ext/date_time_spec.rb
|
121
|
+
- spec/lib/keyword_arg_time/core_ext/time_spec.rb
|
122
|
+
- spec/lib/keyword_arg_time_spec.rb
|
123
|
+
- spec/spec_helper.rb
|