time_rounder 0.1.0 → 0.2.0
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/.gitignore +1 -0
- data/README.md +7 -1
- data/lib/time_rounder/rounded_time.rb +47 -0
- data/lib/time_rounder/version.rb +1 -1
- data/lib/time_rounder.rb +9 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b08ad541c1027826b9b533cc5b2370ee5170dfc
|
4
|
+
data.tar.gz: b1b8801fa7e8e72d3e285fcc97a3ccdf42ca8ee5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75ad18cac49aa4a1e89e357c2a6a40628a95cd406cbd8276ebc36b8020491d465318e5196b34eddaccc943473940fde8c5124eecc2a9461bffdf5b77a51cdd27
|
7
|
+
data.tar.gz: 0c8721ca830615c37748c8e96f5b03a84ba2966c4b695c4a6db3c2f34f1209230e40c14475cf53930a5cd0a9daa9f322ea9a5d2155924d9b483ee83f8fbef12e
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -20,12 +20,18 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
TimeRounder has simple methods to access internal classes that calculate the
|
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
26
|
TimeRounder.seconds_to_hours(seconds)
|
27
27
|
```
|
28
28
|
|
29
|
+
TimeRounder can also take a DateTime/Time object and round it to the nearest quarter hour
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
TimeRounder.rounded_time(seconds)
|
33
|
+
```
|
34
|
+
|
29
35
|
## Development
|
30
36
|
|
31
37
|
TimeRounder will continue to be developed adding features and functionality. Some of those features currently planned are:
|
@@ -0,0 +1,47 @@
|
|
1
|
+
##
|
2
|
+
# Round a Time/DateTime object to Quarter Hours 0, 15, 30, 45
|
3
|
+
|
4
|
+
module TimeRounder
|
5
|
+
class RoundedTime
|
6
|
+
|
7
|
+
##
|
8
|
+
# returns the DateTime/Time object on the correct quarter hour
|
9
|
+
|
10
|
+
def rounded_time
|
11
|
+
@@time += magic_number
|
12
|
+
@@time
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
##
|
18
|
+
# initailize the object with a date/time object
|
19
|
+
|
20
|
+
def initialize(time)
|
21
|
+
@@time = time
|
22
|
+
end
|
23
|
+
|
24
|
+
##
|
25
|
+
# The number of seconds to add to the time to get to the nearest quarter hour
|
26
|
+
|
27
|
+
def magic_number
|
28
|
+
minutes_hash[minutes] * 60
|
29
|
+
end
|
30
|
+
|
31
|
+
##
|
32
|
+
# The minutes of the date/time object
|
33
|
+
|
34
|
+
def minutes
|
35
|
+
@@time.strftime('%M').to_i
|
36
|
+
end
|
37
|
+
|
38
|
+
##
|
39
|
+
# hash of minutes and the number of minutes to add to get to the nearest quarter hour
|
40
|
+
|
41
|
+
def minutes_hash
|
42
|
+
{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}
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
data/lib/time_rounder/version.rb
CHANGED
data/lib/time_rounder.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "time_rounder/version"
|
2
2
|
require "time_rounder/rounded_time_from_seconds"
|
3
|
+
require "time_rounder/rounded_time"
|
3
4
|
|
4
5
|
##
|
5
6
|
# TimeRounder is a library to round time.
|
@@ -12,5 +13,12 @@ module TimeRounder
|
|
12
13
|
def self.seconds_to_hours(seconds)
|
13
14
|
TimeRounder::RoundedTimeFromSeconds.new(seconds).rounded_time
|
14
15
|
end
|
15
|
-
|
16
|
+
|
17
|
+
##
|
18
|
+
# Takes a DateTime/Time object and returns the time to the nearest quarter hour
|
19
|
+
|
20
|
+
def self.rounded_time(time)
|
21
|
+
TimeRounder::RoundedTime.new(time).rounded_time
|
22
|
+
end
|
23
|
+
|
16
24
|
end
|
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.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -69,6 +69,7 @@ files:
|
|
69
69
|
- bin/console
|
70
70
|
- bin/setup
|
71
71
|
- lib/time_rounder.rb
|
72
|
+
- lib/time_rounder/rounded_time.rb
|
72
73
|
- lib/time_rounder/rounded_time_from_seconds.rb
|
73
74
|
- lib/time_rounder/version.rb
|
74
75
|
- time_rounder.gemspec
|