date_helper 1.0.0 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 886c8aa86a73debebd4984a1409bc9c40525e405
4
- data.tar.gz: c5c03e3977ad960beeceb7c149b28e3501a3435d
3
+ metadata.gz: 7f977cb78a18493fcb28e534d2e0f5e30501463f
4
+ data.tar.gz: 8a6264ece452c352e7849a2096dca7208ce4772f
5
5
  SHA512:
6
- metadata.gz: 560f1be171db1b7c53c9952caa8996fd56b2a9cdde97226c00f8484792681abf380a72a52e304162c09a90ccad23dcb262a65fa05bfa0eacd0c9c80c22213cdf
7
- data.tar.gz: f9a6893840b4b7f6b0abbb282bcd7501104475c012697fb185992395e26ce70d3b27ac8cfe267d9bf50392060c6ab503809d1a7787ae0aa43fdafddfdaaeaec3
6
+ metadata.gz: 84e304352391135b5a2547319d6e04165f0dc20fa3b5d9f3c4838c209429d68f287d72ca2f789741292fcb6d52e4a4e7588ecb26f55367f9703e46c36afc148d
7
+ data.tar.gz: 766dde9d476939255ed1eae4b90ace80ca36ec29b73aeea2b85794e227a7008c98c1094bc8a93062a218f1be460efbd66db2fe0521340da58fa98b0f67844a06
data/README.md CHANGED
@@ -1,8 +1,14 @@
1
1
  # DateHelper
2
2
 
3
- Adds `months_between` method to the `Date` class.
3
+ Adds some useful methods to the `Date` class.
4
4
 
5
- `months_between` returns an array of `Date` objects for the first day of each month, inclusive of the starting and ending months.
5
+ ### `months_between`
6
+
7
+ Class method `months_between` returns an array of `Date` objects for the first day of each month, inclusive of the starting and ending months.
8
+
9
+ ### `to_utc_time`
10
+
11
+ Instance method `to_utc_time` converts a given `Date` instance to a `Time` object at 00:00:00 UTC on the given `Date`
6
12
 
7
13
  ## Installation
8
14
 
@@ -24,7 +30,14 @@ xmas = Date.parse("2013-12-25")
24
30
  hksar_establishment_day = Date.parse("2014-07-01")
25
31
 
26
32
  Date.months_between(xmas,hksar_establishment_day)
33
+ => [Sun, 01 Dec 2013, Wed, 01 Jan 2014, Sat, 01 Feb 2014, Sat, 01 Mar 2014, Tue, 01 Apr 2014, Thu, 01 May 2014, Sun, 01 Jun 2014, Tue, 01 Jul 2014]
27
34
  ```
35
+
36
+ ```ruby
37
+ Date.parse("2014-04-27").to_utc_time
38
+ => 2014-04-27 00:00:00 UTC
39
+ ```
40
+
28
41
  ## Contributing
29
42
 
30
43
  1. Fork it
data/date_helper.gemspec CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.version = DateHelper::VERSION
9
9
  spec.authors = ["Larry Salibra"]
10
10
  spec.email = ["larry@pay4bugs.com"]
11
- spec.description = "Adds `months_between` method to the `Date` class."
11
+ spec.description = "Adds some useful methods to the Date class."
12
12
  spec.summary = spec.description
13
13
  spec.homepage = "https://github.com/pay4bugs/date_helper"
14
14
  spec.license = "MIT"
data/lib/date_helper.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'date'
2
2
 
3
3
  module DateHelper
4
- VERSION = "1.0.0"
4
+ VERSION = "1.1.0"
5
5
  end
6
6
 
7
7
  class Date
@@ -24,4 +24,21 @@ class Date
24
24
 
25
25
  months << end_date
26
26
  end
27
+
28
+
29
+ def self.utc_times(dates)
30
+ result = Array.new
31
+ for date in dates
32
+ result << date.to_utc_time
33
+ end
34
+ result
35
+ end
36
+
37
+
38
+ # return a Time object at 00:00:00 UTC on the given Date
39
+ def to_utc_time
40
+ Time.utc(self.year,self.month,self.day)
41
+ end
42
+
43
+
27
44
  end
@@ -85,5 +85,11 @@ describe DateHelper do
85
85
  end
86
86
  end
87
87
  end
88
+
89
+
90
+ it "to_utc_time should convert date to utc time" do
91
+ expect(Date.parse("2014-01-01").to_utc_time).to be == Time.iso8601("2014-01-01T00:00:00Z")
92
+ expect(Date.parse("2014-01-01").to_time).to_not be == Time.iso8601("2014-01-01T00:00:00Z")
93
+ end
88
94
 
89
95
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: date_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Larry Salibra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-26 00:00:00.000000000 Z
11
+ date: 2014-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,7 +52,7 @@ dependencies:
52
52
  - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- description: Adds `months_between` method to the `Date` class.
55
+ description: Adds some useful methods to the Date class.
56
56
  email:
57
57
  - larry@pay4bugs.com
58
58
  executables: []
@@ -90,6 +90,6 @@ rubyforge_project:
90
90
  rubygems_version: 2.1.8
91
91
  signing_key:
92
92
  specification_version: 4
93
- summary: Adds `months_between` method to the `Date` class.
93
+ summary: Adds some useful methods to the Date class.
94
94
  test_files:
95
95
  - spec/lib/date_helper_spec.rb