datetimespan 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest +3 -0
- data/Rakefile +12 -0
- data/datetimespan.gemspec +30 -0
- data/lib/datetimespan.rb +56 -0
- metadata +74 -0
data/Manifest
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
Echoe.new('datetimespan', '0.1.0') do |p|
|
5
|
+
p.description = 'Render a date/time span according to an strftime pattern. Only works with sensibly ordered date-formats (so not US!)'
|
6
|
+
p.url = "http://github.com/Yoomee/datetimespan"
|
7
|
+
p.author = 'Si Wilkins'
|
8
|
+
p.email = 'si@yoomee.com'
|
9
|
+
p.ignore_pattern = "tmp/*", "script/*"
|
10
|
+
p.development_dependencies = []
|
11
|
+
end
|
12
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{datetimespan}
|
5
|
+
s.version = "0.1.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Si Wilkins"]
|
9
|
+
s.date = %q{2010-11-22}
|
10
|
+
s.description = %q{Render a date/time span according to an strftime pattern. Only works with sensibly ordered date-formats (so not US!)}
|
11
|
+
s.email = %q{si@yoomee.com}
|
12
|
+
s.extra_rdoc_files = ["lib/datetimespan.rb"]
|
13
|
+
s.files = ["Rakefile", "lib/datetimespan.rb", "Manifest", "datetimespan.gemspec"]
|
14
|
+
s.homepage = %q{http://github.com/Yoomee/datetimespan}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Datetimespan"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{datetimespan}
|
18
|
+
s.rubygems_version = %q{1.3.7}
|
19
|
+
s.summary = %q{Render a date/time span according to an strftime pattern. Only works with sensibly ordered date-formats (so not US!)}
|
20
|
+
|
21
|
+
if s.respond_to? :specification_version then
|
22
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
|
+
s.specification_version = 3
|
24
|
+
|
25
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
26
|
+
else
|
27
|
+
end
|
28
|
+
else
|
29
|
+
end
|
30
|
+
end
|
data/lib/datetimespan.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
class DateTimeSpan
|
2
|
+
|
3
|
+
attr_writer :format, :separator
|
4
|
+
|
5
|
+
class << self
|
6
|
+
|
7
|
+
attr_accessor :default_format, :default_separator
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(start_dt, end_dt, format = nil, separator = nil)
|
12
|
+
raise ArgumentError("Start date/time must be before end date/time") if end_dt < start_dt
|
13
|
+
@start_dt, @end_dt = start_dt, end_dt
|
14
|
+
@format = format || self.class::default_format
|
15
|
+
@separator = separator || self.class::default_separator
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_s(format = nil, separator = nil)
|
19
|
+
@format = format unless format.nil?
|
20
|
+
@separator = separator unless separator.nil?
|
21
|
+
from = ''
|
22
|
+
to = ''
|
23
|
+
differing = false
|
24
|
+
parts.reverse.each do |part|
|
25
|
+
if part[0, 1]
|
26
|
+
from_part = @start_dt.strftime(part)
|
27
|
+
to_part = @end_dt.strftime(part)
|
28
|
+
if from_part != to_part || differing
|
29
|
+
differing = true
|
30
|
+
from.prepend(from_part)
|
31
|
+
end
|
32
|
+
to.prepend(to_part)
|
33
|
+
else
|
34
|
+
to.prepend(part)
|
35
|
+
from.prepend(part) if differing
|
36
|
+
end
|
37
|
+
end
|
38
|
+
"#{from}#{@separator}#{to}"
|
39
|
+
end
|
40
|
+
|
41
|
+
def parts
|
42
|
+
@format.scan(/(%\w|[^%])/).flatten
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
DateTimeSpan.default_format = "%A %e %B %Y"
|
48
|
+
DateTimeSpan.default_separator = ' - '
|
49
|
+
|
50
|
+
class String
|
51
|
+
|
52
|
+
def prepend(str)
|
53
|
+
insert(0, str)
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: datetimespan
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Si Wilkins
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-11-22 00:00:00 +00:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: Render a date/time span according to an strftime pattern. Only works with sensibly ordered date-formats (so not US!)
|
23
|
+
email: si@yoomee.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files:
|
29
|
+
- lib/datetimespan.rb
|
30
|
+
files:
|
31
|
+
- Rakefile
|
32
|
+
- lib/datetimespan.rb
|
33
|
+
- Manifest
|
34
|
+
- datetimespan.gemspec
|
35
|
+
has_rdoc: true
|
36
|
+
homepage: http://github.com/Yoomee/datetimespan
|
37
|
+
licenses: []
|
38
|
+
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options:
|
41
|
+
- --line-numbers
|
42
|
+
- --inline-source
|
43
|
+
- --title
|
44
|
+
- Datetimespan
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
hash: 3
|
53
|
+
segments:
|
54
|
+
- 0
|
55
|
+
version: "0"
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 11
|
62
|
+
segments:
|
63
|
+
- 1
|
64
|
+
- 2
|
65
|
+
version: "1.2"
|
66
|
+
requirements: []
|
67
|
+
|
68
|
+
rubyforge_project: datetimespan
|
69
|
+
rubygems_version: 1.3.7
|
70
|
+
signing_key:
|
71
|
+
specification_version: 3
|
72
|
+
summary: Render a date/time span according to an strftime pattern. Only works with sensibly ordered date-formats (so not US!)
|
73
|
+
test_files: []
|
74
|
+
|