time_rounder 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -1
- data/README.md +2 -2
- data/bin/console +0 -0
- data/bin/setup +0 -0
- data/lib/time_rounder/load_schedule.rb +19 -0
- data/lib/time_rounder/rounded_time.rb +6 -10
- data/lib/time_rounder/rounded_time_from_seconds.rb +7 -18
- data/lib/time_rounder/schedule/fifteen_minute.rb +26 -0
- data/lib/time_rounder/schedule_not_found.rb +7 -0
- data/lib/time_rounder/version.rb +1 -1
- data/lib/time_rounder.rb +1 -0
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22d760e156469ae8f078b5d45951feb0067ae102
|
4
|
+
data.tar.gz: c9bafa2190e085fd76b232e86219c7cee24d5c4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 570fe67ea8e998b9d2c0c38af813b6239851b7498601116292556bf8e0be7c4bcc8bbc2a786127e06a3cacfcbb46583421ce3785b58ace9840fd1b5ea3ecb7f8
|
7
|
+
data.tar.gz: fd548c15fe22302c8d69f8d568c4b76bf6db281cc253f6ffbcd87f6034adcb4411c99b58f8e8a5b119fdbb69492a31587a142f96c0b2d808c4cdac6fbfc4db6c
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -23,13 +23,13 @@ Or install it yourself as:
|
|
23
23
|
TimeRounder has simple methods to access internal classes that calculate the total hours to the nearest quarter hours in a given number of seconds.
|
24
24
|
|
25
25
|
```ruby
|
26
|
-
TimeRounder.seconds_to_hours(seconds)
|
26
|
+
TimeRounder.seconds_to_hours(seconds) #seconds is the total seconds to be rounded into quarter hours
|
27
27
|
```
|
28
28
|
|
29
29
|
TimeRounder can also take a DateTime/Time object and round it to the nearest quarter hour
|
30
30
|
|
31
31
|
```ruby
|
32
|
-
TimeRounder.rounded_time(
|
32
|
+
TimeRounder.rounded_time(date) #date is DateTime/Time object
|
33
33
|
```
|
34
34
|
|
35
35
|
## Development
|
data/bin/console
CHANGED
File without changes
|
data/bin/setup
CHANGED
File without changes
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'time_rounder/schedule/fifteen_minute'
|
2
|
+
|
3
|
+
module TimeRounder
|
4
|
+
##
|
5
|
+
# Handles loading of the proper schedule
|
6
|
+
module LoadSchedule
|
7
|
+
|
8
|
+
##
|
9
|
+
# loads the proper schedule based what minute is passed
|
10
|
+
def get_schedule(minutes)
|
11
|
+
case minutes
|
12
|
+
when 15
|
13
|
+
self.class.send(:include, TimeRounder::Schedule::FifteenMinute)
|
14
|
+
else
|
15
|
+
raise TimeRounder::ScheduleNotFound
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,8 +1,11 @@
|
|
1
|
+
require "time_rounder/load_schedule"
|
2
|
+
|
1
3
|
##
|
2
4
|
# Round a Time/DateTime object to Quarter Hours 0, 15, 30, 45
|
3
5
|
|
4
6
|
module TimeRounder
|
5
7
|
class RoundedTime
|
8
|
+
include TimeRounder::LoadSchedule
|
6
9
|
|
7
10
|
##
|
8
11
|
# returns the DateTime/Time object on the correct quarter hour
|
@@ -18,15 +21,16 @@ module TimeRounder
|
|
18
21
|
##
|
19
22
|
# initailize the object with a date/time object
|
20
23
|
|
21
|
-
def initialize(time)
|
24
|
+
def initialize(time, schedule=15)
|
22
25
|
@@time = time
|
26
|
+
get_schedule(schedule)
|
23
27
|
end
|
24
28
|
|
25
29
|
##
|
26
30
|
# The number of seconds to add to the time to get to the nearest quarter hour
|
27
31
|
|
28
32
|
def magic_number
|
29
|
-
|
33
|
+
minutes_to_closest_partial[minutes] * 60
|
30
34
|
end
|
31
35
|
|
32
36
|
##
|
@@ -36,13 +40,5 @@ module TimeRounder
|
|
36
40
|
@@time.strftime('%M').to_i
|
37
41
|
end
|
38
42
|
|
39
|
-
##
|
40
|
-
# hash of minutes and the number of minutes to add to get to the nearest quarter hour
|
41
|
-
|
42
|
-
def minutes_hash
|
43
|
-
{0 => 0, 1 => -1, 2 => -2, 3 => -3, 4 => -4, 5 => -5, 6 => -6, 7 => -7, 8 => 7, 9 => 6, 10 => 5, 11 => 4, 12 => 3, 13 => 2, 14 => 1, 15 => 0, 16 => -1, 17 => -2, 18 => -3, 19 => -4, 20 => -5, 21 => -6, 22 => -7, 23 => 7, 24 => 6, 25 => 5, 26 => 4, 27 => 3, 28 => 2, 29 => 1, 30 => 0, 31 => -1, 32 => -2, 33 => -3, 34 => -4, 35 => -5, 36 => -6, 37 => -7, 38 => 7, 39 => 6, 40 => 5, 41 => 4, 42 => 3, 43 => 2, 44 => 1, 45 => 0, 46 => -1, 47 => -2, 48 => -3, 49 => -4, 50 => -5, 51 => -6, 52 => -7, 53 => 7, 54 => 6, 55 => 5, 56 => 4, 57 => 3, 58 => 2, 59 => 1}
|
44
|
-
end
|
45
|
-
|
46
|
-
|
47
43
|
end
|
48
44
|
end
|
@@ -1,8 +1,11 @@
|
|
1
|
+
require "time_rounder/load_schedule"
|
2
|
+
|
1
3
|
##
|
2
4
|
# Takes seconds and returns a decimal of hours and partial hours.
|
3
5
|
|
4
6
|
module TimeRounder
|
5
7
|
class RoundedTimeFromSeconds
|
8
|
+
include TimeRounder::LoadSchedule
|
6
9
|
|
7
10
|
##
|
8
11
|
# Returns the total rounded hours in the number of seconds
|
@@ -14,15 +17,16 @@ module TimeRounder
|
|
14
17
|
|
15
18
|
private
|
16
19
|
|
17
|
-
def initialize(seconds)
|
20
|
+
def initialize(seconds, schedule=15)
|
18
21
|
@@seconds = seconds
|
22
|
+
get_schedule(schedule)
|
19
23
|
end
|
20
24
|
|
21
25
|
##
|
22
26
|
# Determines if an hour needs to be added to total if the partial is rounding up at the end of an hour
|
23
27
|
|
24
28
|
def add_hour?
|
25
|
-
|
29
|
+
add_hours_array.include?(minutes)
|
26
30
|
end
|
27
31
|
|
28
32
|
##
|
@@ -43,23 +47,8 @@ module TimeRounder
|
|
43
47
|
# Takes the number of minutes in the total of seconds after hours are removed, to retrieve the decimal portion of the total.
|
44
48
|
|
45
49
|
def quarter_hours
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
##
|
50
|
-
# This is where the magic happens. This hash contains every minute of an hour and what decimal partial hours it rounds to.
|
51
|
-
# This partial is added to the total.
|
52
|
-
|
53
|
-
def minutes_hash
|
54
|
-
{0 => 0.0, 1 => 0.0, 2 => 0.0, 3 => 0.0, 4 => 0.0, 5 => 0.0, 6 => 0.0, 7 => 0.0, 8 => 0.25, 9 => 0.25, 10 => 0.25, 11 => 0.25, 12 => 0.25, 13 => 0.25, 14 => 0.25, 15 => 0.25, 16 => 0.25, 17 => 0.25, 18 => 0.25, 19 => 0.25, 20 => 0.25, 21 => 0.25, 22 => 0.25, 23 => 0.50, 24 => 0.50, 25 => 0.50, 26 => 0.50, 27 => 0.50, 28 => 0.50, 29 => 0.50, 30 => 0.50, 31 => 0.50, 32 => 0.50, 33 => 0.50, 34 => 0.50, 35 => 0.50, 36 => 0.50, 37 => 0.50, 38 => 0.75, 39 => 0.75, 40 => 0.75, 41 => 0.75, 42 => 0.75, 43 => 0.75, 44 => 0.75, 45 => 0.75, 46 => 0.75, 47 => 0.75, 48 => 0.75, 49 => 0.75, 50 => 0.75, 51 => 0.75, 52 => 0.75, 53 => 0.0, 54 => 0.0, 55 => 0.0, 56 => 0.0, 57 => 0.0, 58 => 0.0, 59 => 0.0}
|
50
|
+
partial_hours_from_minutes[minutes]
|
55
51
|
end
|
56
52
|
|
57
|
-
##
|
58
|
-
# This array is used to determine if it close to the next hour and an hour needs added to the total.
|
59
|
-
# The partial hours will show as zero, and hours is added to correct the total.
|
60
|
-
|
61
|
-
def add_hour_array
|
62
|
-
[53, 54, 55, 56, 57, 58, 59]
|
63
|
-
end
|
64
53
|
end
|
65
54
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module TimeRounder
|
2
|
+
module Schedule
|
3
|
+
##
|
4
|
+
# Schedule to round on 00, 15, 30, 45
|
5
|
+
module FifteenMinute
|
6
|
+
|
7
|
+
##
|
8
|
+
# Array of minutes that will require an hour be added to the total, because the number return from the partial hours has is .00
|
9
|
+
def add_hours_array
|
10
|
+
[53, 54, 55, 56, 57, 58, 59]
|
11
|
+
end
|
12
|
+
|
13
|
+
##
|
14
|
+
# returns the partial hour total based on what the minute is
|
15
|
+
def partial_hours_from_minutes
|
16
|
+
{0 => 0.0, 1 => 0.0, 2 => 0.0, 3 => 0.0, 4 => 0.0, 5 => 0.0, 6 => 0.0, 7 => 0.0, 8 => 0.25, 9 => 0.25, 10 => 0.25, 11 => 0.25, 12 => 0.25, 13 => 0.25, 14 => 0.25, 15 => 0.25, 16 => 0.25, 17 => 0.25, 18 => 0.25, 19 => 0.25, 20 => 0.25, 21 => 0.25, 22 => 0.25, 23 => 0.50, 24 => 0.50, 25 => 0.50, 26 => 0.50, 27 => 0.50, 28 => 0.50, 29 => 0.50, 30 => 0.50, 31 => 0.50, 32 => 0.50, 33 => 0.50, 34 => 0.50, 35 => 0.50, 36 => 0.50, 37 => 0.50, 38 => 0.75, 39 => 0.75, 40 => 0.75, 41 => 0.75, 42 => 0.75, 43 => 0.75, 44 => 0.75, 45 => 0.75, 46 => 0.75, 47 => 0.75, 48 => 0.75, 49 => 0.75, 50 => 0.75, 51 => 0.75, 52 => 0.75, 53 => 0.0, 54 => 0.0, 55 => 0.0, 56 => 0.0, 57 => 0.0, 58 => 0.0, 59 => 0.0}
|
17
|
+
end
|
18
|
+
|
19
|
+
##
|
20
|
+
# returns the number of minutes to get to the closest partial hour
|
21
|
+
def minutes_to_closest_partial
|
22
|
+
{0 => 0, 1 => -1, 2 => -2, 3 => -3, 4 => -4, 5 => -5, 6 => -6, 7 => -7, 8 => 7, 9 => 6, 10 => 5, 11 => 4, 12 => 3, 13 => 2, 14 => 1, 15 => 0, 16 => -1, 17 => -2, 18 => -3, 19 => -4, 20 => -5, 21 => -6, 22 => -7, 23 => 7, 24 => 6, 25 => 5, 26 => 4, 27 => 3, 28 => 2, 29 => 1, 30 => 0, 31 => -1, 32 => -2, 33 => -3, 34 => -4, 35 => -5, 36 => -6, 37 => -7, 38 => 7, 39 => 6, 40 => 5, 41 => 4, 42 => 3, 43 => 2, 44 => 1, 45 => 0, 46 => -1, 47 => -2, 48 => -3, 49 => -4, 50 => -5, 51 => -6, 52 => -7, 53 => 7, 54 => 6, 55 => 5, 56 => 4, 57 => 3, 58 => 2, 59 => 1}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/time_rounder/version.rb
CHANGED
data/lib/time_rounder.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: time_rounder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Condron
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -69,8 +69,11 @@ files:
|
|
69
69
|
- bin/console
|
70
70
|
- bin/setup
|
71
71
|
- lib/time_rounder.rb
|
72
|
+
- lib/time_rounder/load_schedule.rb
|
72
73
|
- lib/time_rounder/rounded_time.rb
|
73
74
|
- lib/time_rounder/rounded_time_from_seconds.rb
|
75
|
+
- lib/time_rounder/schedule/fifteen_minute.rb
|
76
|
+
- lib/time_rounder/schedule_not_found.rb
|
74
77
|
- lib/time_rounder/version.rb
|
75
78
|
- time_rounder.gemspec
|
76
79
|
homepage: https://github.com/rebelweb/time_rounder
|
@@ -93,8 +96,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
96
|
version: '0'
|
94
97
|
requirements: []
|
95
98
|
rubyforge_project:
|
96
|
-
rubygems_version: 2.
|
99
|
+
rubygems_version: 2.2.3
|
97
100
|
signing_key:
|
98
101
|
specification_version: 4
|
99
102
|
summary: Round time with ease
|
100
103
|
test_files: []
|
104
|
+
has_rdoc:
|