date_time-smart 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/ChangeLog +4 -0
- data/README +38 -0
- data/Rakefile +135 -0
- data/lib/date_time/smart.rb +76 -0
- data/spec/date_time-smart_spec.rb +62 -0
- data/spec/spec_helper.rb +4 -0
- metadata +72 -0
data/ChangeLog
ADDED
data/README
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
|
2
|
+
= date_time-smart
|
3
|
+
|
4
|
+
== Synopsis
|
5
|
+
|
6
|
+
require 'date_time-duration'
|
7
|
+
require 'date_time-smart'
|
8
|
+
|
9
|
+
DateTime::Smart.new(1984, 12, 26).add(years => 1).subtract(:day => 1).to_s
|
10
|
+
#=> "1985-12-25T00:00:00"
|
11
|
+
dt = DateTime::Smart.new(2007, 12, 25)
|
12
|
+
birth = DateTime::Smart.new(1984, 12, 26)
|
13
|
+
# if you subtract DateTime from DateTime::Smart instance, you got DateTime::Duration instance.
|
14
|
+
( dt - birth ).years
|
15
|
+
#=> 22
|
16
|
+
|
17
|
+
== Description
|
18
|
+
|
19
|
+
wrapper of date_time using datetime-duration.
|
20
|
+
|
21
|
+
== Installation
|
22
|
+
|
23
|
+
=== Archive Installation
|
24
|
+
|
25
|
+
rake install
|
26
|
+
|
27
|
+
=== Gem Installation
|
28
|
+
|
29
|
+
gem install date_time-smart
|
30
|
+
|
31
|
+
== Features/Problems
|
32
|
+
|
33
|
+
|
34
|
+
== Copyright
|
35
|
+
|
36
|
+
Author:: Keiji, Yoshimi <walf443 at gmail.com>
|
37
|
+
Copyright:: Copyright (c) 2007 Keiji, Yoshimi
|
38
|
+
License:: you can redistribute it and/or modify it under the same terms as Ruby itself.
|
data/Rakefile
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/clean'
|
4
|
+
require 'rake/testtask'
|
5
|
+
require 'rake/packagetask'
|
6
|
+
require 'rake/gempackagetask'
|
7
|
+
require 'rake/rdoctask'
|
8
|
+
require 'rake/contrib/rubyforgepublisher'
|
9
|
+
require 'rake/contrib/sshpublisher'
|
10
|
+
require 'fileutils'
|
11
|
+
include FileUtils
|
12
|
+
|
13
|
+
NAME = "date_time-smart"
|
14
|
+
AUTHOR = "Keiji, Yoshimi"
|
15
|
+
EMAIL = "walf443 at gmail.com"
|
16
|
+
DESCRIPTION = "wrapper of date_time using date_time-duration"
|
17
|
+
RUBYFORGE_PROJECT = "akasakarb"
|
18
|
+
RUBYFORGE_PROJECT_ID = 4314
|
19
|
+
RUBYFORGE_PACKAGE_ID = 6502
|
20
|
+
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
|
21
|
+
BIN_FILES = %w( )
|
22
|
+
VERS = "0.0.1"
|
23
|
+
|
24
|
+
REV = File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
|
25
|
+
CLEAN.include ['**/.*.sw?', '*.gem', '.config']
|
26
|
+
RDOC_OPTS = [
|
27
|
+
'--title', "#{NAME} documentation",
|
28
|
+
"--charset", "utf-8",
|
29
|
+
"--opname", "index.html",
|
30
|
+
"--line-numbers",
|
31
|
+
"--main", "README",
|
32
|
+
"--inline-source",
|
33
|
+
]
|
34
|
+
|
35
|
+
task :default => [:test]
|
36
|
+
task :package => [:clean]
|
37
|
+
|
38
|
+
Rake::TestTask.new("test") do |t|
|
39
|
+
t.libs << "spec"
|
40
|
+
t.pattern = "spec/**/*_spec.rb"
|
41
|
+
t.verbose = true
|
42
|
+
end
|
43
|
+
|
44
|
+
spec = Gem::Specification.new do |s|
|
45
|
+
s.name = NAME
|
46
|
+
s.version = VERS
|
47
|
+
s.platform = Gem::Platform::RUBY
|
48
|
+
s.has_rdoc = true
|
49
|
+
s.extra_rdoc_files = ["README", "ChangeLog"]
|
50
|
+
s.rdoc_options += RDOC_OPTS + ['--exclude', '^(examples|extras)/']
|
51
|
+
s.summary = DESCRIPTION
|
52
|
+
s.description = DESCRIPTION
|
53
|
+
s.author = AUTHOR
|
54
|
+
s.email = EMAIL
|
55
|
+
s.homepage = HOMEPATH
|
56
|
+
s.executables = BIN_FILES
|
57
|
+
s.rubyforge_project = RUBYFORGE_PROJECT
|
58
|
+
s.bindir = "bin"
|
59
|
+
s.require_path = "lib"
|
60
|
+
s.autorequire = ""
|
61
|
+
s.test_files = Dir["spec/*_spec.rb"]
|
62
|
+
|
63
|
+
#s.add_dependency('activesupport', '>=1.3.1')
|
64
|
+
#s.required_ruby_version = '>= 1.8.2'
|
65
|
+
s.add_dependency('date_time-duration', '>= 0.0.1')
|
66
|
+
|
67
|
+
s.files = %w(README ChangeLog Rakefile) +
|
68
|
+
Dir.glob("{bin,doc,spec,test,lib,templates,generator,extras,website,script}/**/*") +
|
69
|
+
Dir.glob("ext/**/*.{h,c,rb}") +
|
70
|
+
Dir.glob("examples/**/*.rb") +
|
71
|
+
Dir.glob("tools/*.rb")
|
72
|
+
|
73
|
+
s.extensions = FileList["ext/**/extconf.rb"].to_a
|
74
|
+
end
|
75
|
+
|
76
|
+
Rake::GemPackageTask.new(spec) do |p|
|
77
|
+
p.need_tar = true
|
78
|
+
p.gem_spec = spec
|
79
|
+
end
|
80
|
+
|
81
|
+
task :install do
|
82
|
+
name = "#{NAME}-#{VERS}.gem"
|
83
|
+
sh %{rake package}
|
84
|
+
sh %{sudo gem install pkg/#{name}}
|
85
|
+
end
|
86
|
+
|
87
|
+
task :uninstall => [:clean] do
|
88
|
+
sh %{sudo gem uninstall #{NAME}}
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
Rake::RDocTask.new do |rdoc|
|
93
|
+
rdoc.rdoc_dir = 'html'
|
94
|
+
rdoc.options += RDOC_OPTS
|
95
|
+
rdoc.template = "resh"
|
96
|
+
#rdoc.template = "#{ENV['template']}.rb" if ENV['template']
|
97
|
+
if ENV['DOC_FILES']
|
98
|
+
rdoc.rdoc_files.include(ENV['DOC_FILES'].split(/,\s*/))
|
99
|
+
else
|
100
|
+
rdoc.rdoc_files.include('README', 'ChangeLog')
|
101
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
102
|
+
rdoc.rdoc_files.include('ext/**/*.c')
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
desc "Publish to RubyForge"
|
107
|
+
task :rubyforge => [:rdoc, :package] do
|
108
|
+
require 'rubyforge'
|
109
|
+
Rake::RubyForgePublisher.new(RUBYFORGE_PROJECT, 'yoshimi').upload
|
110
|
+
end
|
111
|
+
|
112
|
+
desc 'Package and upload the release to rubyforge.'
|
113
|
+
task :release => [:clean, :package] do |t|
|
114
|
+
require 'rubyforge'
|
115
|
+
v = ENV["VERSION"] or abort "Must supply VERSION=x.y.z"
|
116
|
+
abort "Versions don't match #{v} vs #{VERS}" unless v == VERS
|
117
|
+
pkg = "pkg/#{NAME}-#{VERS}"
|
118
|
+
|
119
|
+
rf = RubyForge.new
|
120
|
+
puts "Logging in"
|
121
|
+
rf.login
|
122
|
+
|
123
|
+
c = rf.userconfig
|
124
|
+
# c["release_notes"] = description if description
|
125
|
+
# c["release_changes"] = changes if changes
|
126
|
+
c["preformatted"] = true
|
127
|
+
|
128
|
+
files = [
|
129
|
+
"#{pkg}.tgz",
|
130
|
+
"#{pkg}.gem"
|
131
|
+
].compact
|
132
|
+
|
133
|
+
puts "Releasing #{NAME} v. #{VERS}"
|
134
|
+
rf.add_release RUBYFORGE_PROJECT_ID, RUBYFORGE_PACKAGE_ID, VERS, *files
|
135
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'date_time/duration'
|
4
|
+
|
5
|
+
class DateTime
|
6
|
+
class Smart < DateTime
|
7
|
+
module Shared
|
8
|
+
|
9
|
+
def +(n)
|
10
|
+
case n
|
11
|
+
when DateTime::Duration
|
12
|
+
return self.class.new!(@ajd + n.days, @of, @sg)
|
13
|
+
end
|
14
|
+
return super
|
15
|
+
end
|
16
|
+
|
17
|
+
def add n
|
18
|
+
case n
|
19
|
+
when Hash
|
20
|
+
return self + DateTime::Duration.new2(self, n)
|
21
|
+
end
|
22
|
+
__send__ :+, n
|
23
|
+
end
|
24
|
+
|
25
|
+
def -(n)
|
26
|
+
case n
|
27
|
+
when DateTime::Duration
|
28
|
+
return self.class.new!(@ajd - n.days, @of, @sg)
|
29
|
+
when self.class
|
30
|
+
return DateTime::Duration.new(n, self)
|
31
|
+
end
|
32
|
+
return super
|
33
|
+
end
|
34
|
+
|
35
|
+
def subtract n
|
36
|
+
case n
|
37
|
+
when Hash
|
38
|
+
return self - DateTime::Duration.new2(self, n)
|
39
|
+
end
|
40
|
+
__send__ :-, n
|
41
|
+
end
|
42
|
+
|
43
|
+
def inspect
|
44
|
+
"#<#{self.class}: #{self.to_s}, #{self.ajd}, #{self.offset}, #{self.sg}>"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
module SharedClassMethods
|
49
|
+
def now(sg = Date::ITALY)
|
50
|
+
dt = DateTime.now(sg)
|
51
|
+
|
52
|
+
new!(dt.ajd, dt.offset, dt.sg)
|
53
|
+
end
|
54
|
+
|
55
|
+
def today(sg = Date::ITALY)
|
56
|
+
dt = Date.today(sg)
|
57
|
+
|
58
|
+
new!(dt.ajd, dt.offset, dt.sg)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
alias original_add +
|
63
|
+
alias original_subtract -
|
64
|
+
include Shared
|
65
|
+
extend SharedClassMethods
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
class Date::Smart < Date
|
70
|
+
alias original_add +
|
71
|
+
alias original_subtract -
|
72
|
+
|
73
|
+
include DateTime::Smart::Shared
|
74
|
+
extend DateTime::Smart::SharedClassMethods
|
75
|
+
end
|
76
|
+
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
require 'date_time/smart'
|
3
|
+
|
4
|
+
describe DateTime::Smart do
|
5
|
+
before do
|
6
|
+
@birth = DateTime::Smart.new(1984,12,26)
|
7
|
+
@birth_after_a_year_before_a_day = DateTime::Smart.new(1985,12,25)
|
8
|
+
@dd = DateTime::Duration.new(@birth, @birth_after_a_year_before_a_day)
|
9
|
+
end
|
10
|
+
|
11
|
+
it %{ should add Numeric and return new object } do
|
12
|
+
(@birth + 30).should == DateTime::Smart.new(1985, 1, 25)
|
13
|
+
end
|
14
|
+
|
15
|
+
it %{should add DateTime::Duration and return new object} do
|
16
|
+
( @birth + @dd ).should == @birth_after_a_year_before_a_day
|
17
|
+
end
|
18
|
+
|
19
|
+
it %{ should subtract DateTime::Smart and return DateTime::Duration instance} do
|
20
|
+
(@birth_after_a_year_before_a_day - @birth).should be_kind_of(DateTime::Duration)
|
21
|
+
end
|
22
|
+
|
23
|
+
it %{should subtract DateTime::Duration and return new object } do
|
24
|
+
( @birth_after_a_year_before_a_day - @dd ).should == @birth
|
25
|
+
end
|
26
|
+
|
27
|
+
it %{should add with DateTime::Duration.new2} do
|
28
|
+
@birth.add(:days => 364).should == @birth_after_a_year_before_a_day
|
29
|
+
@birth.add(:months => 11, :days => 30).should == @birth_after_a_year_before_a_day
|
30
|
+
@birth.add(:years => 1).subtract(:days => 1).should == @birth_after_a_year_before_a_day
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe Date::Smart do
|
35
|
+
before do
|
36
|
+
@birth = Date::Smart.new(1984,12,26)
|
37
|
+
@birth_after_a_year_before_a_day = Date::Smart.new(1985,12,25)
|
38
|
+
@dd = DateTime::Duration.new(@birth, @birth_after_a_year_before_a_day)
|
39
|
+
end
|
40
|
+
|
41
|
+
it %{ should add Numeric and return new object } do
|
42
|
+
(@birth + 30).should == DateTime::Smart.new(1985, 1, 25)
|
43
|
+
end
|
44
|
+
|
45
|
+
it %{should add DateTime::Duration and return new object} do
|
46
|
+
( @birth + @dd ).should == @birth_after_a_year_before_a_day
|
47
|
+
end
|
48
|
+
|
49
|
+
it %{ should subtract DateTime::Smart and return DateTime::Duration instance} do
|
50
|
+
(@birth_after_a_year_before_a_day - @birth).should be_kind_of(DateTime::Duration)
|
51
|
+
end
|
52
|
+
|
53
|
+
it %{should subtract DateTime::Duration and return new object } do
|
54
|
+
( @birth_after_a_year_before_a_day - @dd ).should == @birth
|
55
|
+
end
|
56
|
+
|
57
|
+
it %{should add with DateTime::Duration.new2} do
|
58
|
+
@birth.add(:days => 364).should == @birth_after_a_year_before_a_day
|
59
|
+
@birth.add(:months => 11, :days => 30).should == @birth_after_a_year_before_a_day
|
60
|
+
@birth.add(:years => 1).subtract(:days => 1).should == @birth_after_a_year_before_a_day
|
61
|
+
end
|
62
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.4
|
3
|
+
specification_version: 1
|
4
|
+
name: date_time-smart
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.0.1
|
7
|
+
date: 2007-12-29 00:00:00 +09:00
|
8
|
+
summary: wrapper of date_time using date_time-duration
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: walf443 at gmail.com
|
12
|
+
homepage: http://akasakarb.rubyforge.org
|
13
|
+
rubyforge_project: akasakarb
|
14
|
+
description: wrapper of date_time using date_time-duration
|
15
|
+
autorequire: ""
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Keiji, Yoshimi
|
31
|
+
files:
|
32
|
+
- README
|
33
|
+
- ChangeLog
|
34
|
+
- Rakefile
|
35
|
+
- spec/date_time-smart_spec.rb
|
36
|
+
- spec/spec_helper.rb
|
37
|
+
- lib/date_time
|
38
|
+
- lib/date_time/smart.rb
|
39
|
+
test_files:
|
40
|
+
- spec/date_time-smart_spec.rb
|
41
|
+
rdoc_options:
|
42
|
+
- --title
|
43
|
+
- date_time-smart documentation
|
44
|
+
- --charset
|
45
|
+
- utf-8
|
46
|
+
- --opname
|
47
|
+
- index.html
|
48
|
+
- --line-numbers
|
49
|
+
- --main
|
50
|
+
- README
|
51
|
+
- --inline-source
|
52
|
+
- --exclude
|
53
|
+
- ^(examples|extras)/
|
54
|
+
extra_rdoc_files:
|
55
|
+
- README
|
56
|
+
- ChangeLog
|
57
|
+
executables: []
|
58
|
+
|
59
|
+
extensions: []
|
60
|
+
|
61
|
+
requirements: []
|
62
|
+
|
63
|
+
dependencies:
|
64
|
+
- !ruby/object:Gem::Dependency
|
65
|
+
name: date_time-duration
|
66
|
+
version_requirement:
|
67
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: 0.0.1
|
72
|
+
version:
|