to_xl 0.0.2 → 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/lib/from_xl.rb +42 -0
- data/lib/to_xl.rb +40 -40
- metadata +5 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7beb140aa852858d8ec9ea0fc274d0541442ca0b
|
|
4
|
+
data.tar.gz: 1b7f7a42403050e4642ff031df9c3b2099c453fe
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 54d87268d2891bf03b28aa4e965de3fb5ee52f3c873f3e0083ce90ca60f5d7a6fbb0071c5bfaae88f6720f0bd8ae54ba8e2b7c1a9c7cbcc567aac9d9ef3fdd92
|
|
7
|
+
data.tar.gz: 283db88e21fda0465567834c114362f5189eb6d992e20494906d73b8279e3866360fa57fa6fd3818b7333b18def1e80bc78aa1d90f4d049a6fe186048e9c7d6c
|
data/lib/from_xl.rb
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
require 'time' unless defined? Time
|
|
2
|
+
require 'date' unless defined? Date
|
|
3
|
+
require 'datetime' unless defined? DateTime
|
|
4
|
+
|
|
5
|
+
class Float
|
|
6
|
+
|
|
7
|
+
def from_excel
|
|
8
|
+
seconds_in_day ||= 24.0 * 60.0 * 60.0
|
|
9
|
+
excel_days_offset ||= 25569.0
|
|
10
|
+
gmt_offset = (((Time.now.hour.to_f - Time.now.gmtime.hour.to_f)/24.0) * -1) + (0.5 / seconds_in_day) # Have to compensate for GMT offsets since Excel does by default, and then we add half a second to make sure it has the correct day (and not 23:59:59 of the previous day)
|
|
11
|
+
val = self
|
|
12
|
+
val += gmt_offset
|
|
13
|
+
new_date = Time.at((val - excel_days_offset) * seconds_in_day)
|
|
14
|
+
end
|
|
15
|
+
alias_method :from_xl, :from_excel
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
# if defined?(Date)
|
|
21
|
+
class Integer
|
|
22
|
+
|
|
23
|
+
def from_excel
|
|
24
|
+
self.to_f.from_excel
|
|
25
|
+
end
|
|
26
|
+
alias_method :from_xl, :from_excel
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
# end
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
# if defined?(DateTime)
|
|
33
|
+
class Fixnum
|
|
34
|
+
|
|
35
|
+
def from_excel
|
|
36
|
+
self.to_f.from_excel
|
|
37
|
+
end
|
|
38
|
+
alias_method :from_xl, :from_excel
|
|
39
|
+
|
|
40
|
+
end
|
|
41
|
+
# end
|
|
42
|
+
|
data/lib/to_xl.rb
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
require 'time'
|
|
2
|
-
|
|
3
|
-
class Time
|
|
4
|
-
|
|
5
|
-
def to_excel
|
|
6
|
-
@seconds_in_day ||= 24 * 60 * 60
|
|
7
|
-
@excel_days_offset ||= 25569
|
|
8
|
-
@offset_gmt = (self.hour > self.gmtime.hour) ? true : false # Excel dates are on GMT time, so we have to go back a day if this is calculated on one day in our time zone and another on GMT.
|
|
9
|
-
excel_date = (self.to_i/@seconds_in_day) + @excel_days_offset
|
|
10
|
-
excel_date -= 1 if @offset_gmt # Excel dates are on GMT time, so we have to go back a day if this is calculated on one day in our time zone and another on GMT.
|
|
11
|
-
excel_date
|
|
12
|
-
end
|
|
13
|
-
alias_method :to_xl, :to_excel
|
|
14
|
-
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if defined?(Date)
|
|
19
|
-
class Date
|
|
20
|
-
|
|
21
|
-
def to_excel
|
|
22
|
-
self.to_time.to_excel
|
|
23
|
-
end
|
|
24
|
-
alias_method :to_xl, :to_excel
|
|
25
|
-
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if defined?(DateTime)
|
|
31
|
-
class DateTime
|
|
32
|
-
|
|
33
|
-
def to_excel
|
|
34
|
-
self.to_time.to_excel
|
|
35
|
-
end
|
|
36
|
-
alias_method :to_xl, :to_excel
|
|
37
|
-
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
|
|
1
|
+
require 'time'
|
|
2
|
+
|
|
3
|
+
class Time
|
|
4
|
+
|
|
5
|
+
def to_excel
|
|
6
|
+
@seconds_in_day ||= 24 * 60 * 60
|
|
7
|
+
@excel_days_offset ||= 25569
|
|
8
|
+
@offset_gmt = (self.hour > self.gmtime.hour) ? true : false # Excel dates are on GMT time, so we have to go back a day if this is calculated on one day in our time zone and another on GMT.
|
|
9
|
+
excel_date = (self.to_i/@seconds_in_day) + @excel_days_offset
|
|
10
|
+
excel_date -= 1 if @offset_gmt # Excel dates are on GMT time, so we have to go back a day if this is calculated on one day in our time zone and another on GMT.
|
|
11
|
+
excel_date
|
|
12
|
+
end
|
|
13
|
+
alias_method :to_xl, :to_excel
|
|
14
|
+
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
if defined?(Date)
|
|
19
|
+
class Date
|
|
20
|
+
|
|
21
|
+
def to_excel
|
|
22
|
+
self.to_time.to_excel
|
|
23
|
+
end
|
|
24
|
+
alias_method :to_xl, :to_excel
|
|
25
|
+
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
if defined?(DateTime)
|
|
31
|
+
class DateTime
|
|
32
|
+
|
|
33
|
+
def to_excel
|
|
34
|
+
self.to_time.to_excel
|
|
35
|
+
end
|
|
36
|
+
alias_method :to_xl, :to_excel
|
|
37
|
+
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
metadata
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: to_xl
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: '2.0'
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Brian Egan
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2017-05-16 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: A simple gem to convert Time, Date, and DateTime instances to Excel date
|
|
14
|
-
integers.
|
|
14
|
+
integers. And to convert Excel date integers/decimals to Ruby dates.
|
|
15
15
|
email: brianegan@outlook.com
|
|
16
16
|
executables: []
|
|
17
17
|
extensions: []
|
|
18
18
|
extra_rdoc_files: []
|
|
19
19
|
files:
|
|
20
|
+
- lib/from_xl.rb
|
|
20
21
|
- lib/to_xl.rb
|
|
21
22
|
homepage: https://github.com/Brian-Egan/to_xl
|
|
22
23
|
licenses:
|
|
@@ -38,7 +39,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
38
39
|
version: '0'
|
|
39
40
|
requirements: []
|
|
40
41
|
rubyforge_project:
|
|
41
|
-
rubygems_version: 2.
|
|
42
|
+
rubygems_version: 2.5.1
|
|
42
43
|
signing_key:
|
|
43
44
|
specification_version: 4
|
|
44
45
|
summary: To Excel
|