unichron 0.2.0 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a0f46d716012dabcde580a23c4e9bd1c1e450de1393616b96687a576848d6de8
4
- data.tar.gz: 27a66fa54b2a393f2edd322bfb0f53a1f9101bb505afc40b3033151e0777f3ec
3
+ metadata.gz: 4c869f9865684c9593e42e0b035e17c41edbe7b7d791a99f03066fdc1b0510ee
4
+ data.tar.gz: 39a5f3c6fb4db90a3fd9f923d508533d3ac34ac2369e1a1211724e8ab14c1e66
5
5
  SHA512:
6
- metadata.gz: 96d3457abcaf00fcf92844bcc263028f477e9c13ab14c9c928aa2cd43d7362c613c055e867bb01b093d79e0351773883d095387f636d1f4bcad8f6dfabaf7140
7
- data.tar.gz: ffd54644c6fa5f44be13b90cec43e2c39309e6dbce21328827ba7842218a1a3f3a9dc6375377e775e01147509ea97e382bf45721e12ff07081bee22e61b1239c
6
+ metadata.gz: 24d780ca006f8fd981ed4a10f6682ea1d02726f1294825cf00c06adf6ae412ae2d266808fee76f606dd0576fad45ab8258e9e14526913f4269e25b8a742238d7
7
+ data.tar.gz: 4b1fc261191ed29aae6f323ebf2decf042ee133311caeacad7048e8e11e841acbbb2cfaad251a84e83cf1d1300a9dcc6dc9593738087c8ed407cc4c35245497c
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/lib/unichron.rb CHANGED
@@ -2,24 +2,52 @@
2
2
 
3
3
  # file: unichron.rb
4
4
 
5
+ require 'subunit'
5
6
  require 'chronic_cron'
7
+ require 'christian_calendar'
6
8
 
7
9
 
8
10
  class Unichron
9
11
 
10
12
  attr_reader :r
11
13
 
12
- def initialize(obj)
14
+ def initialize(obj, debug: false)
13
15
 
16
+ @debug = debug
14
17
  @r = select_method(obj)
18
+
19
+ end
20
+
21
+ # Returns the elapsed time in a humanized format
22
+ # e.g. elapsed(Time.now - 4000) #=> 1h
23
+ # note: An elapsed time more than a day is returned as a calendar date
24
+ #
25
+ def elapsed()
26
+
27
+ elapsed = Time.now - @r
28
+
29
+ relative_time = if elapsed < Time.now - (Date.today - 1).to_time then
30
+ Subunit.seconds(elapsed).strfunit("%s")
31
+ else
32
+ @r.strftime("%b %d")
33
+ end
34
+
15
35
  end
16
36
 
17
37
  def to_seconds
18
38
  @r
19
39
  end
40
+
41
+ def to_date
42
+ @r.to_date if valid?
43
+ end
20
44
 
21
45
  def to_time
22
- @r.to_time
46
+ @r.to_time if valid?
47
+ end
48
+
49
+ def valid?
50
+ @r.respond_to? :to_time
23
51
  end
24
52
 
25
53
  private
@@ -30,16 +58,26 @@ class Unichron
30
58
 
31
59
  s = obj
32
60
  r = Chronic.parse(s)
61
+ puts 'r1: ' + r.inspect if @debug
33
62
  return r if r
34
63
 
35
64
  r = ChronicCron.new s
65
+ puts 'r2: ' + r.inspect if @debug
36
66
  return r if r.valid?
37
67
 
38
68
  r = ChronicDuration.parse s
69
+ puts 'r3: ' + r.inspect if @debug
70
+ return r if r
71
+
72
+ r = ChristianCalendar.new.query(obj)
73
+ puts 'r4 ' + r.inspect if @debug
39
74
  return r if r
40
75
 
76
+
41
77
  return nil
42
78
 
79
+ else
80
+ obj
43
81
  end
44
82
  end
45
83
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unichron
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -35,8 +35,28 @@ cert_chain:
35
35
  vPngqdMCuVEkZm+YuLTXph0I590TF5EmMRQMILYYtjV6ClWHIEa5WlToyO2Fk1OL
36
36
  aagRjWlkRSoGiE7602v0Wo/u
37
37
  -----END CERTIFICATE-----
38
- date: 2020-11-18 00:00:00.000000000 Z
38
+ date: 2021-04-04 00:00:00.000000000 Z
39
39
  dependencies:
40
+ - !ruby/object:Gem::Dependency
41
+ name: subunit
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '0.8'
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 0.8.3
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '0.8'
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 0.8.3
40
60
  - !ruby/object:Gem::Dependency
41
61
  name: chronic_cron
42
62
  requirement: !ruby/object:Gem::Requirement
@@ -46,7 +66,7 @@ dependencies:
46
66
  version: '0.6'
47
67
  - - ">="
48
68
  - !ruby/object:Gem::Version
49
- version: 0.6.1
69
+ version: 0.6.2
50
70
  type: :runtime
51
71
  prerelease: false
52
72
  version_requirements: !ruby/object:Gem::Requirement
@@ -56,9 +76,29 @@ dependencies:
56
76
  version: '0.6'
57
77
  - - ">="
58
78
  - !ruby/object:Gem::Version
59
- version: 0.6.1
79
+ version: 0.6.2
80
+ - !ruby/object:Gem::Dependency
81
+ name: christian_calendar
82
+ requirement: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - "~>"
85
+ - !ruby/object:Gem::Version
86
+ version: '0.1'
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 0.1.7
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.1'
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: 0.1.7
60
100
  description:
61
- email: james@jamesrobertson.eu
101
+ email: digital.robertson@gmail.com
62
102
  executables: []
63
103
  extensions: []
64
104
  extra_rdoc_files: []
@@ -83,7 +123,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
123
  - !ruby/object:Gem::Version
84
124
  version: '0'
85
125
  requirements: []
86
- rubygems_version: 3.0.3
126
+ rubyforge_project:
127
+ rubygems_version: 2.7.10
87
128
  signing_key:
88
129
  specification_version: 4
89
130
  summary: A universal chron tool.
metadata.gz.sig CHANGED
Binary file