a14z6ch_elapsed_days 0.0.4 → 0.0.5
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/a14z6ch_elapsed_days.gemspec +1 -1
- data/bin/a14z6ch_elapsed_days +1 -1
- data/lib/a14z6ch_elapsed_days.rb +43 -36
- data/lib/a14z6ch_elapsed_days/version.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba51823c1fce6a1d983cd9d5781befcea9f6408b
|
4
|
+
data.tar.gz: 16258c6f1ec3275b0799c60c8dcd4d0dd81dc849
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0496419a457f404bf079e654e0379ce7215ac134b170e404d75eaeaa6c963c7b32ed3e13948bc42a1e6c80f4304c0fafdd47ed8f89b7e92e3dc13550f00496bc
|
7
|
+
data.tar.gz: 799c6334c1f7885eb23efe6a6b4fb27e0ab279f06f982f02c9a0030087bb8eff2447a5e0bb1aafa61cddd882c3ee12b5e9ba480649023c8973418ab4d92d12a9
|
@@ -5,7 +5,7 @@ require 'a14z6ch_elapsed_days/version'
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "a14z6ch_elapsed_days"
|
8
|
-
spec.version =
|
8
|
+
spec.version = A14z6chElapsedDays::VERSION
|
9
9
|
spec.authors = ["Chihiro Hashimoto"]
|
10
10
|
spec.email = ["a14z6ch@aiit.ac.jp"]
|
11
11
|
spec.summary = %q{To calculate days from given date.}
|
data/bin/a14z6ch_elapsed_days
CHANGED
data/lib/a14z6ch_elapsed_days.rb
CHANGED
@@ -10,48 +10,55 @@ I18n.enforce_available_locales = false
|
|
10
10
|
#
|
11
11
|
# To calculate elapsed days.
|
12
12
|
#
|
13
|
-
|
13
|
+
module A14z6chElapsedDays
|
14
|
+
class Cli < Thor
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
# @param from date
|
19
|
-
#
|
20
|
-
def from(date)
|
21
|
-
begin
|
22
|
-
puts "#{calc(date, Time.now.to_s).to_s(:delimited)} days elapsed from the day \"#{date}\" to NOW.".colorize(:light_magenta)
|
23
|
-
rescue ArgumentError => e
|
24
|
-
if e.message.nil?
|
25
|
-
puts "given date is not valid.".colorize(:light_blue)
|
26
|
-
else
|
27
|
-
puts e.message.colorize(:light_blue)
|
28
|
-
end
|
16
|
+
desc "version", "Show version"
|
17
|
+
def version
|
18
|
+
puts "a14z6ch appilication version : #{A14z6chElapsedDays::VERSION}"
|
29
19
|
end
|
30
|
-
end
|
31
20
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
21
|
+
desc "from DATE", "calculate elapsed days from target date."
|
22
|
+
#
|
23
|
+
# calculating method
|
24
|
+
# @param from date
|
25
|
+
#
|
26
|
+
def from(date)
|
27
|
+
begin
|
28
|
+
puts "#{calc(date, Time.now.to_s).to_s(:delimited)} days elapsed from the day \"#{date}\" to NOW.".colorize(:light_magenta)
|
29
|
+
rescue ArgumentError => e
|
30
|
+
if e.message.nil?
|
31
|
+
puts "given date is not valid.".colorize(:light_blue)
|
32
|
+
else
|
33
|
+
puts e.message.colorize(:light_blue)
|
34
|
+
end
|
44
35
|
end
|
45
36
|
end
|
46
|
-
end
|
47
37
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
(
|
38
|
+
desc "between FROM_DATE and TO_DATE", "calculate elapsed days from FROM date to TO date"
|
39
|
+
#
|
40
|
+
#
|
41
|
+
#
|
42
|
+
def between(from, to)
|
43
|
+
begin
|
44
|
+
puts "#{calc(from, to).to_s(:delimited)} days elapsed from the day \"#{from}\" to \"#{to}\".".colorize(:light_magenta)
|
45
|
+
rescue ArgumentError => e
|
46
|
+
if e.message.nil?
|
47
|
+
puts "given date is not valid.".colorize(:light_blue)
|
48
|
+
else
|
49
|
+
puts e.message.colorize(:light_blue)
|
50
|
+
end
|
55
51
|
end
|
56
52
|
end
|
53
|
+
|
54
|
+
private
|
55
|
+
def calc(from, to)
|
56
|
+
elapsed_seconds = Time.parse(to) - Time.parse(from)
|
57
|
+
if elapsed_seconds < 0
|
58
|
+
raise ArgumentError.new("TO DATE must be later than FROM DATE")
|
59
|
+
else
|
60
|
+
(elapsed_seconds / 60 / 60 / 24).to_i
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
57
64
|
end
|
@@ -1,3 +1,3 @@
|
|
1
|
-
module
|
2
|
-
VERSION = "0.0.
|
1
|
+
module A14z6chElapsedDays
|
2
|
+
VERSION = "0.0.5"
|
3
3
|
end
|