unichron 0.2.0 → 0.2.1

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: 54ad0e31bbd08f680742522a9d0e85b90d1f8c93947013f99252b4f86bdd01d3
4
+ data.tar.gz: 4cc8586ce8945eaad576d942e3a52268bf025b4717aa81a2796fd0645f668f2a
5
5
  SHA512:
6
- metadata.gz: 96d3457abcaf00fcf92844bcc263028f477e9c13ab14c9c928aa2cd43d7362c613c055e867bb01b093d79e0351773883d095387f636d1f4bcad8f6dfabaf7140
7
- data.tar.gz: ffd54644c6fa5f44be13b90cec43e2c39309e6dbce21328827ba7842218a1a3f3a9dc6375377e775e01147509ea97e382bf45721e12ff07081bee22e61b1239c
6
+ metadata.gz: c28c5b0c6775dddd75b489103e12f6bbf3e378703fbb5d4890a5e97ce0ccc45e80500010d4662ad74dd9566133c9dcdc42a3708aaed249ee135e977932b90960
7
+ data.tar.gz: f937791e08da31fe0c201ab35a84cd9750fd5f7e4e0afaae7eec82fa8728bdad5024ff1300e6da2be6c2ef11a144259ad11fb7c7ea675e4f8e62b57f43059e66
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/lib/unichron.rb CHANGED
@@ -3,23 +3,50 @@
3
3
  # file: unichron.rb
4
4
 
5
5
  require 'chronic_cron'
6
+ require 'christian_calendar'
6
7
 
7
8
 
8
9
  class Unichron
9
10
 
10
11
  attr_reader :r
11
12
 
12
- def initialize(obj)
13
+ def initialize(obj, debug: false)
13
14
 
15
+ @debug = debug
14
16
  @r = select_method(obj)
17
+
18
+ end
19
+
20
+ # Returns the elapsed time in a humanized format
21
+ # e.g. elapsed(Time.now - 4000) #=> 1h
22
+ # note: An elapsed time more than a day is returned as a calendar date
23
+ #
24
+ def elapsed()
25
+
26
+ elapsed = Time.now - @r
27
+
28
+ relative_time = if elapsed < Time.now - (Date.today - 1).to_time then
29
+ Subunit.seconds(elapsed).strfunit("%s")
30
+ else
31
+ t2.strftime("%b %d")
32
+ end
33
+
15
34
  end
16
35
 
17
36
  def to_seconds
18
37
  @r
19
38
  end
39
+
40
+ def to_date
41
+ @r.to_date if valid?
42
+ end
20
43
 
21
44
  def to_time
22
- @r.to_time
45
+ @r.to_time if valid?
46
+ end
47
+
48
+ def valid?
49
+ @r.respond_to? :to_time
23
50
  end
24
51
 
25
52
  private
@@ -30,16 +57,26 @@ class Unichron
30
57
 
31
58
  s = obj
32
59
  r = Chronic.parse(s)
60
+ puts 'r1: ' + r.inspect if @debug
33
61
  return r if r
34
62
 
35
63
  r = ChronicCron.new s
64
+ puts 'r2: ' + r.inspect if @debug
36
65
  return r if r.valid?
37
66
 
38
67
  r = ChronicDuration.parse s
68
+ puts 'r3: ' + r.inspect if @debug
69
+ return r if r
70
+
71
+ r = ChristianCalendar.new.query(obj)
72
+ puts 'r4 ' + r.inspect if @debug
39
73
  return r if r
40
74
 
75
+
41
76
  return nil
42
77
 
78
+ else
79
+ obj
43
80
  end
44
81
  end
45
82
 
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.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -35,7 +35,7 @@ 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-02-23 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: chronic_cron
@@ -83,7 +83,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
83
  - !ruby/object:Gem::Version
84
84
  version: '0'
85
85
  requirements: []
86
- rubygems_version: 3.0.3
86
+ rubyforge_project:
87
+ rubygems_version: 2.7.10
87
88
  signing_key:
88
89
  specification_version: 4
89
90
  summary: A universal chron tool.
metadata.gz.sig CHANGED
Binary file