motion-yaml 1.4.6 → 1.5

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
  SHA1:
3
- metadata.gz: 85a71212a012ab0f2d3c9fbc2213c1854238a416
4
- data.tar.gz: 77054707517eca66a0c79363f0913ff3e52b40e0
3
+ metadata.gz: 3edda00f9eb55537a0f5cf71a03c7556372995ba
4
+ data.tar.gz: f58d2501ae71cd243148cccca72340621fb6bbf4
5
5
  SHA512:
6
- metadata.gz: 69ceb11e351750fc50f453c6473a99d944e30d0716a354b2f1a23b9797f14cb40a16d9670d6e3668ae2ea8711ce20b369ff3358e7021f6d31abe8ebc84f05abb
7
- data.tar.gz: e19c0154477ad9cc9722e1a6d3cca2b46a5334ec0041265934e15b713efb105581700edf3bf70bcbd41cee5135dfc3401f538c41ae846aa85f9ce1d943c659f8
6
+ metadata.gz: a51f7fd60f44e9b9de393fca9ce74456e1875002c3ab6a0efe039a7058e6e78e80bdcc3ab04023b6d9e2ae70218621db6b011bc62e4b3649bd6739c6a0bf13f3
7
+ data.tar.gz: f280cff468f089dd803c118ffe53903f3be82a43eb7882d859da744648d8ca7686b3918c0ae024ad2d87cc0e3cab45e56d7cbeb5d0761ccfe7521df06951eecf
Binary file
Binary file
@@ -22,7 +22,11 @@
22
22
  # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
23
23
  # POSSIBILITY OF SUCH DAMAGE.
24
24
 
25
+ # Special thanks to https://github.com/tenderlove/psych
25
26
  class YAMLKitScanner
27
+ # http://yaml.org/type/timestamp.html
28
+ TIME = /^-?\d{4}-\d{1,2}-\d{1,2}(?:[Tt]|\s+)\d{1,2}:\d\d:\d\d(?:\.\d*)?(?:\s*(?:Z|[-+]\d{1,2}:?(?:\d\d)?))?$/
29
+
26
30
  # http://yaml.org/type/float.html
27
31
  FLOAT = /^(?:[-+]?([0-9][0-9_,]*)?\.[0-9]*([eE][-+][0-9]+)?(?# base 10)
28
32
  |[-+]?[0-9][0-9_,]*(:[0-5]?[0-9])+\.[0-9_]*(?# base 60)
@@ -57,6 +61,8 @@ class YAMLKitScanner
57
61
  Integer(string.gsub(/_/, ''))
58
62
  when FLOAT
59
63
  Float(string.gsub(/_/, ''))
64
+ when TIME
65
+ self.parse_time(string)
60
66
  when /^(yes|y|true|on)$/i
61
67
  true
62
68
  when /^(no|n|false|off)$/i
@@ -65,4 +71,30 @@ class YAMLKitScanner
65
71
  nil
66
72
  end
67
73
  end
74
+
75
+ def self.parse_time string
76
+ date, time = *(string.split(/[ tT]/, 2))
77
+ (yy, m, dd) = date.match(/^(-?\d{4})-(\d{1,2})-(\d{1,2})/).captures.map { |x| x.to_i }
78
+ md = time.match(/(\d+:\d+:\d+)(?:\.(\d*))?\s*(Z|[-+]\d+(:\d\d)?)?/)
79
+
80
+ (hh, mm, ss) = md[1].split(':').map { |x| x.to_i }
81
+ us = (md[2] ? Rational("0.#{md[2]}") : 0) * 1000000
82
+
83
+ time = Time.utc(yy, m, dd, hh, mm, ss, us)
84
+
85
+ return time if 'Z' == md[3]
86
+ return Time.at(time.to_i, us) unless md[3]
87
+
88
+ tz = md[3].match(/^([+\-]?\d{1,2})\:?(\d{1,2})?$/)[1..-1].compact.map { |digit| Integer(digit, 10) }
89
+ offset = tz.first * 3600
90
+
91
+ if offset < 0
92
+ offset -= ((tz[1] || 0) * 60)
93
+ else
94
+ offset += ((tz[1] || 0) * 60)
95
+ end
96
+
97
+ Time.at((time - offset).to_i, us)
98
+ end
99
+
68
100
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: motion-yaml
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.6
4
+ version: '1.5'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Laurent Sansonetti