ontime 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 58d6ec3b0055f4f525b4e0d42bd39e5f235cec5a
4
+ data.tar.gz: 0cb8d5d4b1d4a5f991cdb66a3be9932a5df7729d
5
+ SHA512:
6
+ metadata.gz: 990dd4a565d5c2ab24aeeda41f27e1322d07bf7874946fd6ed1db33cfcb4e5fdd56a28623a7d63d829e386db3aa9d49cce382be1d4fd287118c3f4537d870e20
7
+ data.tar.gz: 1cf3c1fdcfef23f7c828744536ffbe560f4c3b8031e42a5b309260bae044412d2deac70fecba7bc6254fccacd7e5e0bcd4dd700c1a246767630501073926f926
@@ -0,0 +1,23 @@
1
+ .DS_Store
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+ *.bundle
20
+ *.so
21
+ *.o
22
+ *.a
23
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Nathaniel Wroblewski
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.
@@ -0,0 +1,59 @@
1
+ OnTime
2
+ ===
3
+
4
+ OnTime is a dependency-less, thread-safe, and fluent way to create times in ruby.
5
+
6
+ Installation
7
+ ---
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```rb
12
+ gem 'ontime'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ ```sh
18
+ $ bundle
19
+ ```
20
+
21
+ Or install it yourself as:
22
+
23
+ ```sh
24
+ $ gem install ontime
25
+ ```
26
+
27
+ Usage
28
+ ---
29
+
30
+ ```
31
+ On.January(3.rd)
32
+ On.March(24.th, 2007)
33
+ On.December(2.nd, 2008).at(1).pm
34
+ On.April(1.st).at('2:38').am
35
+ On.August(13.th).at('4:30').pm.and(56.seconds)
36
+ On.the(4.th).of(:July, 2015).at(2).pm.in('US/Pacific')
37
+ On.the(7.th).at(:midnight)
38
+ On.September(19.th).at(:midday).in('UTC')
39
+ ```
40
+
41
+ Method | Description
42
+ ---------|----------
43
+ `to_time`| Converts the resulting `OnTime` object to a native ruby `Time` object
44
+ `month` | Returns the month as an integer (1-12)
45
+ `date` | Returns the day as an integer (1-31)
46
+ `year` | Returns the year as an integer (ex. 2007)
47
+ `hour` | Returns the hour as an integer (0-23)
48
+ `min` | Returns the minutes as an integer (0-59)
49
+ `sec` | Returns the seconds as an integer (0-60)
50
+ `offset` | Returns the timezone offset as a string (+/-HHMM, ex. -0600)
51
+
52
+ Contributing
53
+ ---
54
+
55
+ 1. Fork it (https://github.com/nathanielwroblewski/ontime/fork)
56
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
57
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
58
+ 4. Push to the branch (`git push origin my-new-feature`)
59
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,21 @@
1
+ require 'ontime/version'
2
+ require 'ontime/ordinals'
3
+ require 'ontime/ontime'
4
+
5
+ module On
6
+ MONTHS = %i{
7
+ January February March April May June July August September October November December
8
+ }.freeze
9
+
10
+ MONTHS.each_with_index do |month, index|
11
+ module_eval(
12
+ "def self.#{month}(date=1, year=Time.new.year);" +
13
+ "OnTime.new.set(month: #{index + 1}, date: date.to_i, year: year.to_i);" +
14
+ 'end'
15
+ )
16
+ end
17
+
18
+ def self.the(date=1)
19
+ OnTime.new.set(date: date, month: Time.now.month, year: Time.now.year)
20
+ end
21
+ end
@@ -0,0 +1,67 @@
1
+ require 'date'
2
+
3
+ module On
4
+ class OnTime
5
+ SYSTEM_TIME = "%a %b %d %H:%M:%S %Y %Z"
6
+
7
+ def initialize()
8
+ @state = {}
9
+ end
10
+
11
+ ATTR_READERS = %i{ year month date hour min sec }.freeze
12
+ ATTR_READERS.each do |attr|
13
+ module_eval(
14
+ "def #{attr};" +
15
+ "@state['#{attr}'.to_sym] || Time.now.#{attr === :date ? :day : attr};" +
16
+ "end"
17
+ )
18
+ end
19
+
20
+ def of(month=Time.now.month, year=Time.now.year)
21
+ set(month: MONTHS.index(month.to_sym) + 1, year: year)
22
+ end
23
+
24
+ def at(time=0)
25
+ time = 0 if time == :midnight
26
+ time = 12 if time == :midday
27
+ set(hour: time.to_s.split(':').first.to_i, min: time.to_s.split(':')[1].to_i)
28
+ end
29
+
30
+ def and(given_seconds=0)
31
+ set(sec: given_seconds.to_i)
32
+ end
33
+
34
+ def pm
35
+ set(hour: hour + 12) if hour < 12
36
+ self
37
+ end
38
+
39
+ def am
40
+ set(hour: hour - 12) if hour > 11
41
+ self
42
+ end
43
+
44
+ def to_s
45
+ to_time.to_s
46
+ end
47
+
48
+ def to_time
49
+ Time.new(year, month, date, hour, min, sec, offset)
50
+ end
51
+
52
+ def set(new_state)
53
+ @state = @state.merge(new_state)
54
+ self
55
+ end
56
+
57
+ def in(timezone='UTC')
58
+ system_time = `zdump #{timezone}`.split()[1..-1].join(' ')
59
+
60
+ set(offset: DateTime.strptime(system_time, SYSTEM_TIME).strftime('%Z'))
61
+ end
62
+
63
+ def offset
64
+ @state[:offset]
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,15 @@
1
+ class Fixnum
2
+ ORDINALS = %i{ st nd rd th }
3
+
4
+ ORDINALS.each do |ordinal|
5
+ unless respond_to?(ordinal)
6
+ class_eval("def #{ordinal}; self; end")
7
+ end
8
+ end
9
+
10
+ unless respond_to?(:seconds)
11
+ def seconds
12
+ self
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module On
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ontime/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'ontime'
8
+ spec.version = On::VERSION
9
+ spec.authors = ['Nathaniel Wroblewski']
10
+ spec.email = %w{nathanielwroblewski@gmail.com}
11
+ spec.summary = %q{Create times in ruby.}
12
+ spec.description = %q{OnTime is a dependency-less, thread-safe, and fluent way to create times in ruby.}
13
+ spec.homepage = 'http://github.com/nathanielwroblewski/ontime'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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.6'
22
+ spec.add_development_dependency 'rake', '~> 10.4'
23
+ spec.add_development_dependency 'rspec', '~> 3.3'
24
+ end
@@ -0,0 +1,171 @@
1
+ require 'spec_helper'
2
+
3
+ describe On, '.January' do
4
+ it 'sets the month to 1' do
5
+ expect(On.January.month).to eq 1
6
+ end
7
+ end
8
+
9
+ describe On, '.February' do
10
+ it 'sets the month to 2' do
11
+ expect(On.February.month).to eq 2
12
+ end
13
+ end
14
+
15
+ describe On, '.March' do
16
+ it 'sets the month to 3' do
17
+ expect(On.March.month).to eq 3
18
+ end
19
+ end
20
+
21
+ describe On, '.April' do
22
+ it 'sets the month to 4' do
23
+ expect(On.April.month).to eq 4
24
+ end
25
+ end
26
+
27
+ describe On, '.May' do
28
+ it 'sets the month to 5' do
29
+ expect(On.May.month).to eq 5
30
+ end
31
+ end
32
+
33
+ describe On, '.June' do
34
+ it 'sets the month to 6' do
35
+ expect(On.June.month).to eq 6
36
+ end
37
+ end
38
+
39
+ describe On, '.July' do
40
+ it 'sets the month to 7' do
41
+ expect(On.July.month).to eq 7
42
+ end
43
+ end
44
+
45
+ describe On, '.August' do
46
+ it 'sets the month to 8' do
47
+ expect(On.August.month).to eq 8
48
+ end
49
+ end
50
+
51
+ describe On, '.September' do
52
+ it 'sets the month to 9' do
53
+ expect(On.September.month).to eq 9
54
+ end
55
+ end
56
+
57
+ describe On, '.October' do
58
+ it 'sets the month to 10' do
59
+ expect(On.October.month).to eq 10
60
+ end
61
+ end
62
+
63
+ describe On, '.November' do
64
+ it 'sets the month to 11' do
65
+ expect(On.November.month).to eq 11
66
+ end
67
+ end
68
+
69
+ describe On, '.December' do
70
+ it 'sets the month to 12' do
71
+ expect(On.December.month).to eq 12
72
+ end
73
+ end
74
+
75
+ describe On, '.Month(date)' do
76
+ it 'sets the correct month, date, and year' do
77
+ expect(On.March(22.nd).month).to eq 3
78
+ expect(On.March(22.nd).date).to eq 22
79
+ expect(On.March(22.nd).year).to eq Time.now.year
80
+ end
81
+ end
82
+
83
+ describe On, '.Month(date, year)' do
84
+ it 'sets the correct month, date, and year' do
85
+ expect(On.March(22.nd, 2007).month).to eq 3
86
+ expect(On.March(22.nd, 2007).date).to eq 22
87
+ expect(On.March(22.nd, 2007).year).to eq 2007
88
+ end
89
+ end
90
+
91
+ describe On, '.the(date)' do
92
+ it 'sets the correct month, date, and year' do
93
+ expect(On.the(23.rd).month).to eq Time.now.month
94
+ expect(On.the(23.rd).date).to eq 23
95
+ expect(On.the(23.rd).year).to eq Time.now.year
96
+ end
97
+ end
98
+
99
+ describe On, '.the(date).of(month)' do
100
+ it 'sets the correct month, date, and year' do
101
+ expect(On.the(27.th).of(:January).month).to eq 1
102
+ expect(On.the(27.th).of(:January).date).to eq 27
103
+ expect(On.the(27.th).of(:January).year).to eq Time.now.year
104
+ end
105
+ end
106
+
107
+ describe On, '.the(date).of(month, year)' do
108
+ it 'sets the correct month, date, and year' do
109
+ expect(On.the(27.th).of(:January, 2007).month).to eq 1
110
+ expect(On.the(27.th).of(:January, 2007).date).to eq 27
111
+ expect(On.the(27.th).of(:January, 2007).year).to eq 2007
112
+ end
113
+ end
114
+
115
+ describe On, '.at(hour)' do
116
+ it 'sets the correct hour' do
117
+ expect(On.February(14.th, 2007).at(10).hour).to eq 10
118
+ expect(On.February(14.th, 2007).at(14).hour).to eq 14
119
+ expect(On.February(14.th, 2007).at('12').hour).to eq 12
120
+ end
121
+ end
122
+
123
+ describe On, '.at(:midnight)' do
124
+ it 'sets the correct hour' do
125
+ expect(On.February(14.th, 2007).at(:midnight).hour).to eq 0
126
+ end
127
+ end
128
+
129
+ describe On, '.at(:midday)' do
130
+ it 'sets the correct hour' do
131
+ expect(On.February(14.th, 2007).at(:midday).hour).to eq 12
132
+ end
133
+ end
134
+
135
+ describe On, '.at(hour:minutes)' do
136
+ it 'sets the correct time' do
137
+ expect(On.February(14.th, 2007).at('10:30').hour).to eq 10
138
+ expect(On.February(14.th, 2007).at('10:30').min).to eq 30
139
+ expect(On.February(14.th, 2007).at('14:40').hour).to eq 14
140
+ expect(On.February(14.th, 2007).at('14:40').min).to eq 40
141
+ end
142
+ end
143
+
144
+ describe On, '.am' do
145
+ it 'translates hours over 11' do
146
+ expect(On.February(14.th, 2007).at('12:30').am.hour).to eq 0
147
+ expect(On.February(14.th, 2007).at('14:30').am.hour).to eq 2
148
+ expect(On.February(14.th, 2007).at('10:30').am.hour).to eq 10
149
+ end
150
+ end
151
+
152
+ describe On, '.pm' do
153
+ it 'translates hours under 12' do
154
+ expect(On.February(14.th, 2007).at('1:30').pm.hour).to eq 13
155
+ expect(On.February(14.th, 2007).at('12:30').pm.hour).to eq 12
156
+ expect(On.February(14.th, 2007).at('14:30').pm.hour).to eq 14
157
+ end
158
+ end
159
+
160
+ describe On, '.and(seconds)' do
161
+ it 'sets seconds' do
162
+ expect(On.February(14.th, 2007).at(1).pm.and(21.seconds).sec).to eq 21
163
+ end
164
+ end
165
+
166
+ describe On, '.in(timezone)' do
167
+ it 'sets timezone' do
168
+ On.February(16.th, 2009).at('2:30').pm.in('UTC').offset == '+00:00'
169
+ On.February(16.th, 2009).at('2:30').pm.in('US/Pacific').offset == '-06:00'
170
+ end
171
+ end
@@ -0,0 +1,8 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+
4
+ require 'ontime'
5
+
6
+ RSpec.configure do |config|
7
+ config.color = true
8
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ontime
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Nathaniel Wroblewski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-12 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.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.4'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.3'
55
+ description: OnTime is a dependency-less, thread-safe, and fluent way to create times
56
+ in ruby.
57
+ email:
58
+ - nathanielwroblewski@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - lib/ontime.rb
69
+ - lib/ontime/ontime.rb
70
+ - lib/ontime/ordinals.rb
71
+ - lib/ontime/version.rb
72
+ - ontime.gemspec
73
+ - spec/ontime_spec.rb
74
+ - spec/spec_helper.rb
75
+ homepage: http://github.com/nathanielwroblewski/ontime
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.2.2
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Create times in ruby.
99
+ test_files:
100
+ - spec/ontime_spec.rb
101
+ - spec/spec_helper.rb
102
+ has_rdoc: