night-time 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 [maiha@wota.jp]
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,34 @@
1
+ NAME
2
+ An extension to Time class that supports out of ranged values
3
+
4
+ SYNOPSIS
5
+ Native "mktime" method is too strict.
6
+
7
+ Time.mktime(2010, 1, 10, 26, 40)
8
+ => ArgumentError: argument out of range
9
+
10
+ We the midnight workers want flexible one.
11
+
12
+ require 'night-time'
13
+ Time.mktime(2010, 1, 10, 26, 40)
14
+ => Mon Jan 11 02:40:00 +0900 2010
15
+
16
+ Time.parse('2010-01-10 26:40')
17
+ => Mon Jan 11 02:40:00 +0900 2010
18
+
19
+ w00t!
20
+
21
+ DESCRIPTION
22
+ Modified methods are
23
+
24
+ * Time.mktime
25
+
26
+ Added methods are
27
+
28
+ * Time.parse (use ParseDate)
29
+
30
+ HOMEPAGE
31
+ http://github.com/maiha/night-time
32
+
33
+ AUTHOR
34
+ maiha@wota.jp
data/Rakefile ADDED
@@ -0,0 +1,51 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+
4
+ GEM_NAME = "night-time"
5
+ AUTHOR = "maiha"
6
+ EMAIL = "maiha@wota.jp"
7
+ HOMEPAGE = "http://github.com/maiha/night-time"
8
+ SUMMARY = "An extension to Time class that supports out of ranged values"
9
+ GEM_VERSION = "0.0.1"
10
+
11
+ spec = Gem::Specification.new do |s|
12
+ s.rubyforge_project = 'asakusarb'
13
+ s.executables = []
14
+ s.name = GEM_NAME
15
+ s.version = GEM_VERSION
16
+ s.platform = Gem::Platform::RUBY
17
+ s.has_rdoc = true
18
+ s.extra_rdoc_files = ["README", "MIT-LICENSE"]
19
+ s.summary = SUMMARY
20
+ s.description = s.summary
21
+ s.author = AUTHOR
22
+ s.email = EMAIL
23
+ s.homepage = HOMEPAGE
24
+ s.require_path = 'lib'
25
+ s.files = %w(MIT-LICENSE README Rakefile) + Dir.glob("{lib,spec}/**/*")
26
+ end
27
+
28
+ Rake::GemPackageTask.new(spec) do |pkg|
29
+ pkg.gem_spec = spec
30
+ end
31
+
32
+ desc "Install the gem"
33
+ task :install do
34
+ Merb::RakeHelper.install(GEM_NAME, :version => GEM_VERSION)
35
+ end
36
+
37
+ desc "Uninstall the gem"
38
+ task :uninstall do
39
+ Merb::RakeHelper.uninstall(GEM_NAME, :version => GEM_VERSION)
40
+ end
41
+
42
+ desc "Create a gemspec file"
43
+ task :gemspec do
44
+ File.open("#{GEM_NAME}.gemspec", "w") do |file|
45
+ file.puts spec.to_ruby
46
+ end
47
+ end
48
+
49
+ require 'spec/rake/spectask'
50
+ desc 'Default: run spec examples'
51
+ task :default => 'spec'
data/lib/night-time.rb ADDED
@@ -0,0 +1,37 @@
1
+ require 'parsedate'
2
+
3
+ class Time
4
+ class << self
5
+ def mod_midnight(hour, min, sec)
6
+ extra = 0
7
+
8
+ squeeze = lambda{|val, max, unit, extra|
9
+ num, new_val = val.divmod(max)
10
+ [new_val, extra + max*num*unit]
11
+ }
12
+ sec , extra = squeeze.call(sec.to_i , 60, 1 , extra)
13
+ min , extra = squeeze.call(min.to_i , 60, 60 , extra)
14
+ hour, extra = squeeze.call(hour.to_i, 24, 60*60, extra)
15
+
16
+ return [hour, min, sec, extra]
17
+ end
18
+
19
+
20
+ alias mktime_without_night_time mktime
21
+
22
+ def mktime(*args)
23
+ year, mon, day, hour, min, sec, usec = args
24
+ extra = 0
25
+ if hour.to_i >= 24 or min.to_i >= 60 or sec.to_i > 60
26
+ hour, min, sec, extra = mod_midnight(hour, min, sec)
27
+ end
28
+ mktime_without_night_time(year, mon, day, hour, min, sec, usec) + extra
29
+ end
30
+
31
+ unless respond_to?(:parse)
32
+ def parse(text)
33
+ Time.mktime(*ParseDate.parsedate(text)[0,7])
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,4 @@
1
+
2
+ require 'spec'
3
+
4
+ require File.join(File.dirname(__FILE__), '/../lib/night-time')
data/spec/time_spec.rb ADDED
@@ -0,0 +1,28 @@
1
+
2
+ require File.join(File.dirname(__FILE__), 'spec_helper.rb')
3
+
4
+ describe Time do
5
+ describe ".mktime" do
6
+ it "should treat late night time" do
7
+ Time.mktime(2010,1,10,26,40).should == Time.mktime(2010,1,11,2,40)
8
+ end
9
+
10
+ it "should treat valid time too" do
11
+ Time.mktime(2010,1,10, 2,40).should == Time.mktime(2010,1,10,2,40)
12
+ end
13
+ end
14
+
15
+ it "should provide .parse" do
16
+ Time.should respond_to(:parse)
17
+ end
18
+
19
+ describe ".parse" do
20
+ it "should parse late night time" do
21
+ Time.parse('2010-01-10 26:40').should == Time.mktime(2010,1,11,2,40)
22
+ end
23
+
24
+ it "should treat valid time too" do
25
+ Time.parse('2010-01-10 02:40').should == Time.mktime(2010,1,10,2,40)
26
+ end
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: night-time
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - maiha
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-11 00:00:00 +09:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: An extension to Time class that supports out of ranged values
17
+ email: maiha@wota.jp
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
24
+ - MIT-LICENSE
25
+ files:
26
+ - MIT-LICENSE
27
+ - README
28
+ - Rakefile
29
+ - lib/night-time.rb
30
+ - spec/time_spec.rb
31
+ - spec/spec_helper.rb
32
+ has_rdoc: true
33
+ homepage: http://github.com/maiha/night-time
34
+ licenses: []
35
+
36
+ post_install_message:
37
+ rdoc_options: []
38
+
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ version:
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "0"
52
+ version:
53
+ requirements: []
54
+
55
+ rubyforge_project: asakusarb
56
+ rubygems_version: 1.3.5
57
+ signing_key:
58
+ specification_version: 3
59
+ summary: An extension to Time class that supports out of ranged values
60
+ test_files: []
61
+