circa 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Rakefile +5 -0
- data/lib/circa.rb +9 -0
- data/lib/circa/date.rb +21 -0
- data/lib/circa/time.rb +19 -0
- data/lib/circa/util.rb +3 -0
- data/lib/circa/version.rb +1 -1
- data/spec/circa/date_spec.rb +1 -1
- data/spec/circa/time_spec.rb +1 -1
- data/spec/circa_spec.rb +1 -1
- data/spec/spec_helper.rb +3 -0
- metadata +16 -25
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8c96a7be7dbfc6799b76fb01492897d79ea09a3a
|
4
|
+
data.tar.gz: 4ced0fb59c9d6e8aa4fcdd3c1924768aa202f6e6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e7ad0307a6212212c173fb246acc73ebeb7fdea0e390eb285187c7763a1f299e7365c481720062d46254d12fe92e77bcfff8a10fa5dc0c44866b056dd0364bb1
|
7
|
+
data.tar.gz: 9e8861a92cf222e219eb3cab238c147d3bde5a73fb6b3ea71256a6c1d9eb059b3c4c1fb36e0bfc42515b3030a63ce7910c2260a4075538b2348f0d6430aee8f1
|
data/Rakefile
CHANGED
data/lib/circa.rb
CHANGED
@@ -1,8 +1,17 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
1
3
|
require 'circa/version'
|
2
4
|
require 'circa/date'
|
3
5
|
require 'circa/time'
|
4
6
|
|
5
7
|
module Circa
|
8
|
+
# Convenience method to create a new {Circa::Date} or {Circa::Time}
|
9
|
+
# @param [String] input_string
|
10
|
+
# A string in format %Y-%m-%d or %Y-%m-%d %H:%M:%S
|
11
|
+
# @return [Circa::Date/Circa::Time]
|
12
|
+
# A new {Circa::Date} or {Circa::Time} depending on input
|
13
|
+
# @raise [ArgumentError]
|
14
|
+
# If an invalid input string is given
|
6
15
|
def circa(input_string)
|
7
16
|
if match_date(input_string)
|
8
17
|
Date.new(input_string)
|
data/lib/circa/date.rb
CHANGED
@@ -1,13 +1,28 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
+
require 'date'
|
3
4
|
require_relative 'util'
|
4
5
|
|
5
6
|
module Circa
|
7
|
+
# Manage partial dates.
|
8
|
+
# @!attribute [r] valid_parts
|
9
|
+
# @return [Hash]
|
10
|
+
# A hash of valid parts in the date,
|
11
|
+
# with keys [:year, :month, :day] where applicable,
|
12
|
+
# and according values
|
6
13
|
class Date
|
7
14
|
include Util
|
15
|
+
|
16
|
+
# Match partial dates in format %Y-%m-%d
|
8
17
|
REGEX = /^(\d{4})(?:-(0[0-9]|1[0-2])(?:-([0-2][0-9]|3[0-1])))$/
|
18
|
+
|
9
19
|
attr_reader :valid_parts
|
10
20
|
|
21
|
+
# Create a new {Circa::Date}
|
22
|
+
# @param [String] date_string
|
23
|
+
# A string in format %Y-%m-%d
|
24
|
+
# @raise [ArgumentError]
|
25
|
+
# If an invalid string is given
|
11
26
|
def initialize(date_string)
|
12
27
|
@year = '0000'
|
13
28
|
@month = '00'
|
@@ -18,10 +33,16 @@ module Circa
|
|
18
33
|
end
|
19
34
|
end
|
20
35
|
|
36
|
+
# Get the date as a string
|
37
|
+
# @return [String]
|
38
|
+
# A string in format %Y-%m-%d
|
21
39
|
def to_s
|
22
40
|
"#{@year}-#{@month}-#{@day}"
|
23
41
|
end
|
24
42
|
|
43
|
+
# Get the date as a {::Date}
|
44
|
+
# @return [::Date]
|
45
|
+
# A {::Date}
|
25
46
|
def to_date
|
26
47
|
return nil if valid_parts.empty?
|
27
48
|
parts = [:year, :month, :day]
|
data/lib/circa/time.rb
CHANGED
@@ -4,10 +4,18 @@ require_relative 'date'
|
|
4
4
|
require_relative 'util'
|
5
5
|
|
6
6
|
module Circa
|
7
|
+
# Manage partial times.
|
7
8
|
class Time
|
8
9
|
include Util
|
10
|
+
|
11
|
+
# Match times in format %H:%M:%S
|
9
12
|
REGEX = /^([0-1][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])Z?$/
|
10
13
|
|
14
|
+
# Create a new {Circa::Time}
|
15
|
+
# @param [String] time_string
|
16
|
+
# A string in format %Y-%m-%d %H:%M:%S
|
17
|
+
# @raise [ArgumentError]
|
18
|
+
# If an invalid string is given
|
11
19
|
def initialize(time_string)
|
12
20
|
parts = time_string.split(/T|\s/)
|
13
21
|
@date = Date.new(parts[0])
|
@@ -20,15 +28,26 @@ module Circa
|
|
20
28
|
end
|
21
29
|
end
|
22
30
|
|
31
|
+
# Get the time as a string
|
32
|
+
# @return [String]
|
33
|
+
# {Circa::Date#to_s} plus the time in format %H:%M:%S
|
23
34
|
def to_s
|
24
35
|
"#{@date.to_s} #{@hour}:#{@minute}:#{@second}"
|
25
36
|
end
|
26
37
|
|
38
|
+
# Get the valid parts of the time
|
39
|
+
# @return [Hash]
|
40
|
+
# A hash with keys [:year, :month, :day, :hour, :minute, :second]
|
41
|
+
# where each of those keys is valid in the time,
|
42
|
+
# and values per the keys
|
27
43
|
def valid_parts
|
28
44
|
time_parts = { hour: @hour, minute: @minute, second: @second }
|
29
45
|
@date.valid_parts.merge(time_parts)
|
30
46
|
end
|
31
47
|
|
48
|
+
# Get the time as a {::DateTime}
|
49
|
+
# @return [DateTime]
|
50
|
+
# A {::DateTime}
|
32
51
|
def to_time
|
33
52
|
parts = [:year, :month, :day, :hour, :minute, :second]
|
34
53
|
args = valid_parts_as_args(parts)
|
data/lib/circa/util.rb
CHANGED
data/lib/circa/version.rb
CHANGED
data/spec/circa/date_spec.rb
CHANGED
data/spec/circa/time_spec.rb
CHANGED
data/spec/circa_spec.rb
CHANGED
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: circa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Robert Dallas Gray
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-03 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: bundler
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ~>
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,23 +27,20 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rake
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: m
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
45
|
- - ~>
|
52
46
|
- !ruby/object:Gem::Version
|
@@ -54,7 +48,6 @@ dependencies:
|
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
52
|
- - ~>
|
60
53
|
- !ruby/object:Gem::Version
|
@@ -62,33 +55,29 @@ dependencies:
|
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: guard
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - '>='
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '1.8'
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - '>='
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '1.8'
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: guard-minitest
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
|
-
- -
|
73
|
+
- - '>='
|
84
74
|
- !ruby/object:Gem::Version
|
85
75
|
version: '0'
|
86
76
|
type: :development
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
|
-
- -
|
80
|
+
- - '>='
|
92
81
|
- !ruby/object:Gem::Version
|
93
82
|
version: '0'
|
94
83
|
description: Utilities for working with MySQL-style partial dates
|
@@ -113,32 +102,34 @@ files:
|
|
113
102
|
- spec/circa/date_spec.rb
|
114
103
|
- spec/circa/time_spec.rb
|
115
104
|
- spec/circa_spec.rb
|
105
|
+
- spec/spec_helper.rb
|
116
106
|
homepage: ''
|
117
107
|
licenses:
|
118
108
|
- MIT
|
109
|
+
metadata: {}
|
119
110
|
post_install_message:
|
120
111
|
rdoc_options: []
|
121
112
|
require_paths:
|
122
113
|
- lib
|
123
114
|
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
-
none: false
|
125
115
|
requirements:
|
126
|
-
- -
|
116
|
+
- - '>='
|
127
117
|
- !ruby/object:Gem::Version
|
128
118
|
version: '0'
|
129
119
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
-
none: false
|
131
120
|
requirements:
|
132
|
-
- -
|
121
|
+
- - '>='
|
133
122
|
- !ruby/object:Gem::Version
|
134
123
|
version: '0'
|
135
124
|
requirements: []
|
136
125
|
rubyforge_project:
|
137
|
-
rubygems_version:
|
126
|
+
rubygems_version: 2.0.2
|
138
127
|
signing_key:
|
139
|
-
specification_version:
|
128
|
+
specification_version: 4
|
140
129
|
summary: Utilities for working with MySQL-style partial dates
|
141
130
|
test_files:
|
142
131
|
- spec/circa/date_spec.rb
|
143
132
|
- spec/circa/time_spec.rb
|
144
133
|
- spec/circa_spec.rb
|
134
|
+
- spec/spec_helper.rb
|
135
|
+
has_rdoc:
|