overtime 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in overtime.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 kimoto
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # What is this
2
+ Time#parse parsable overtime time format: example '2012/01/01 26:30:00'
3
+
4
+ # Install
5
+ gem install 'overtime'
6
+
7
+ # Usage
8
+ require 'overtime'
9
+ Time.parse("2012/01/01 25:00:00 UTC")
10
+ => 2012-01-02 01:00:00 UTC
11
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,13 @@
1
+ require 'overtime'
2
+
3
+ p Time.parse "2012/01/01 10:00:00"
4
+ #2012-01-01 10:00:00 +0900
5
+
6
+ p Time.parse "2012/01/01 24:00:00"
7
+ #2012-01-02 00:00:00 +0900
8
+
9
+ p Time.parse "2012/01/01 25:00:00"
10
+ #2012-01-02 01:00:00 +0900
11
+
12
+ p Time.parse "2012/01/01 30:30:00"
13
+ #2012-01-02 06:30:00 +0900
@@ -0,0 +1,3 @@
1
+ module Overtime
2
+ VERSION = "1.0.0"
3
+ end
data/lib/overtime.rb ADDED
@@ -0,0 +1,80 @@
1
+ require "overtime/version"
2
+ require 'date'
3
+ require 'time'
4
+
5
+ class Time
6
+ class << Time
7
+ CONST_DAY_HOURS=24
8
+ def parse(str, now=self.now)
9
+ comp = !block_given?
10
+ d = Date._parse(str)
11
+ if !d[:year] && !d[:mon] && !d[:mday] && !d[:hour] && !d[:min] && !d[:sec] && !d[:sec_fraction]
12
+ raise ArgumentError, "no time information in #{date.inspect}"
13
+ end
14
+
15
+ year = d[:year]
16
+ year = yield(year) if year && !comp
17
+
18
+ if d[:hour]
19
+ (add_day, mod_hour) = (d[:hour]).divmod(CONST_DAY_HOURS)
20
+ else
21
+ (add_day, mod_hour) = [0, nil]
22
+ end
23
+
24
+ make_time(year, d[:mon], d[:mday], mod_hour, d[:min], d[:sec], d[:sec_fraction], d[:zone], now) + (add_day * 24 * 60 * 60)
25
+ end
26
+ end
27
+ end
28
+
29
+ module Overtime
30
+ end
31
+
32
+ if $0 == __FILE__
33
+ require 'test/unit'
34
+
35
+ class TC_BSTTime < Test::Unit::TestCase
36
+ def setup
37
+ end
38
+
39
+ def test_time_bst_parse
40
+ assert_bst_time_pairs [
41
+ ["2009/01/01 10:00:00", "2009/01/01 10:00:00"],
42
+ ["2009/01/01 11:00:00", "2009/01/01 11:00:00"],
43
+
44
+ ["2009/01/01 23:59:59", "2009/01/01 23:59:59"],
45
+ ["2009/01/01 24:00:00", "2009/01/02 00:00:00"],
46
+ ["2009/01/01 24:00:01", "2009/01/02 00:00:01"],
47
+
48
+ ["2009/01/01 47:59:59", "2009/01/02 23:59:59"],
49
+ ["2009/01/01 48:00:00", "2009/01/03 00:00:00"],
50
+ ["2009/01/01 48:00:01", "2009/01/03 00:00:01"],
51
+
52
+ ["2009/01/01", "2009/01/01 00:00:00"],
53
+ ["2009/01", "2009/01/01 00:00:00"],
54
+ ["2009-01-01 01:02:03", "2009/01/01 01:02:03"],
55
+
56
+ ["3000/01/01 48:00:01", "3000/01/03 00:00:01"],
57
+
58
+ ["2000/12/31 23:59:59", "2000/12/31 23:59:59"],
59
+ ["2000/12/31 24:00:00", "2001/01/01 00:00:00"],
60
+
61
+ ["1900/01/01 00:00:00", "1900/01/01 00:00:00"],
62
+ ["0001/01/01 00:00:00", "0001/01/01 00:00:00"],
63
+ ]
64
+ end
65
+
66
+ def assert_bst_time_pairs(pairs_list)
67
+ pairs_list.each{ |pairs|
68
+ assert_bst_time(pairs.last, pairs.first)
69
+ }
70
+ end
71
+
72
+ def assert_bst_time(true_time, bst_time)
73
+ assert_time true_time, Time.parse(bst_time)
74
+ end
75
+
76
+ def assert_time(true_time, time)
77
+ assert_equal(true_time, time.strftime("%Y/%m/%d %H:%M:%S"))
78
+ end
79
+ end
80
+ end
data/overtime.gemspec ADDED
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/overtime/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["kimoto"]
6
+ gem.email = ["sub+peerler@gmail.com"]
7
+ gem.description = %q{Time.parse can parse 'overtime' time format}
8
+ gem.summary = %q{Time.parse can parse 'overtime' time format}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "overtime"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Overtime::VERSION
17
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: overtime
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - kimoto
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-26 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Time.parse can parse 'overtime' time format
15
+ email:
16
+ - sub+peerler@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE
24
+ - README.md
25
+ - Rakefile
26
+ - examples/standard.rb
27
+ - lib/overtime.rb
28
+ - lib/overtime/version.rb
29
+ - overtime.gemspec
30
+ homepage: ''
31
+ licenses: []
32
+ post_install_message:
33
+ rdoc_options: []
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirements: []
49
+ rubyforge_project:
50
+ rubygems_version: 1.8.24
51
+ signing_key:
52
+ specification_version: 3
53
+ summary: Time.parse can parse 'overtime' time format
54
+ test_files: []