eztime 1.0.0 → 2.0.0

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.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NDdjMWM5MDM5ODYzMDI3NTQ0Nzk0ODQ4YzEzMjk2MzBkZGQyZGViNA==
5
+ data.tar.gz: !binary |-
6
+ ZDZiMDNmYjJlOTA5YzZiODg0MGMxYmNhODY4YTc0ZmQ1OTFiZTY3NQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NzhkZDg5MDc4YmEzMzg3NTViZDE1Y2VkYWU4ODZmNjAwZTllNjI1MzMxMDA3
10
+ MGIyZmNlYjU2ZDNlZTdhMGI3OWE2MDU1MjA2OGY1MTAxNjliNjUyMzUyM2My
11
+ YmExNDI3OWFkMDk4ZGE5YTA5OGEyYzlkYWRiZGE5NzEyZGYyNmY=
12
+ data.tar.gz: !binary |-
13
+ YzhlNjU1MmIyMDNmMWRjNzg2ZmNmMTgyYTRjNTRmMTNjNzQ3MDg5YjM5ZTRj
14
+ ODQ1ZDMxNzlmNGY2ZGJmYjdmN2ZmOGI3ZDA3N2ZkMGQ5ZGU4MjE2NDk4YzZm
15
+ NjZiNDZjNTEwMzBmMTkwNTlmODg0OWVmZWQ5MjliMmQ0ZmFiNTA=
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 2.0.0
data/eztime.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{eztime}
8
- s.version = "1.0.0"
8
+ s.version = "2.0.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Chris Scharf"]
12
- s.date = %q{2012-07-05}
12
+ s.date = %q{2015-02-27}
13
13
  s.description = %q{Easier date/time manipulation}
14
14
  s.email = %q{scharfie@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -17,8 +17,6 @@ Gem::Specification.new do |s|
17
17
  "README.textile"
18
18
  ]
19
19
  s.files = [
20
- "Gemfile",
21
- "Gemfile.lock",
22
20
  "LICENSE.txt",
23
21
  "README.textile",
24
22
  "Rakefile",
@@ -35,20 +33,5 @@ Gem::Specification.new do |s|
35
33
  s.require_paths = ["lib"]
36
34
  s.rubygems_version = %q{1.4.2}
37
35
  s.summary = %q{Easier date/time manipulation}
38
-
39
- if s.respond_to? :specification_version then
40
- s.specification_version = 3
41
-
42
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
43
- s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
44
- s.add_development_dependency(%q<rcov>, [">= 0"])
45
- else
46
- s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
47
- s.add_dependency(%q<rcov>, [">= 0"])
48
- end
49
- else
50
- s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
51
- s.add_dependency(%q<rcov>, [">= 0"])
52
- end
53
36
  end
54
37
 
data/lib/eztime.rb CHANGED
@@ -1,12 +1,13 @@
1
1
  require 'date'
2
+ require 'forwardable'
2
3
 
3
- # The following code was based on work found at:
4
- # http://www.bigbold.com/snippets/user/jswizard#post2368
5
- class Numeric
6
- # Returns the cardinal (number) and ordinal (st, nd, rd, th, etc.)
7
- # Pass include_cardinal as false to only return the ordinal
8
- def ordinal(include_cardinal=true)
9
- cardinal = self.to_i.abs
4
+ module EZTime
5
+ def self.ordinal(number, include_cardinal=false)
6
+ # The following code was based on work found at:
7
+ # http://www.bigbold.com/snippets/user/jswizard#post2368
8
+ # Returns the cardinal (number) and ordinal (st, nd, rd, th, etc.)
9
+ # Pass include_cardinal as false to only return the ordinal
10
+ cardinal = number.to_i.abs
10
11
  if (10...20).include?(cardinal) then
11
12
  include_cardinal ? cardinal.to_s << 'th' : 'th'
12
13
  else
@@ -14,84 +15,103 @@ class Numeric
14
15
  include_cardinal ? cardinal.to_s << ord : ord
15
16
  end
16
17
  end
17
- end
18
18
 
19
- module EZTime
19
+ class FormattedTime
20
+ extend Forwardable
21
+ attr_accessor :time
22
+
23
+ def_delegators :@time,
24
+ :hour,
25
+ :min,
26
+ :sec,
27
+ :day, :wday, :mday,
28
+ :month,
29
+ :year
30
+
31
+ def initialize(time)
32
+ @time = time
33
+ end
34
+
35
+ def format(format_str)
36
+ eval("'" + format_str.gsub(/:([a-z_]{1,}[0-9]{0,2})/, '\' + \1.to_s + \'') + "'")
37
+ end
38
+
20
39
  public
21
- # Returns only the lower two digits of the year
22
- # (i.e. 2006 => 06)
23
- def syear; year.to_s[-2..-1]; end
24
-
25
- # Returns the name of the month
26
- # (January, February, etc.)
27
- def month_name; Date::MONTHNAMES[month]; end
28
-
29
- # Returns the abbreviated name of the month
30
- # (Jan, Feb, etc.)
31
- def month_abbr; Date::ABBR_MONTHNAMES[month]; end
32
-
33
- # Returns the name of the weekday
34
- # (Sunday, Monday, etc.)
35
- def day_name; Date::DAYNAMES[wday]; end
36
-
37
- # Returns the abbreviated name of the weekday
38
- # (Sun, Mon, etc.)
39
- def day_abbr; Date::ABBR_DAYNAMES[wday]; end
40
-
41
- alias :nmonth :month_name
42
- alias :amonth :month_abbr
43
-
44
- alias :nday :day_name
45
- alias :aday :day_abbr
40
+ # Returns only the lower two digits of the year
41
+ # (i.e. 2006 => 06)
42
+ def syear; year.to_s[-2..-1]; end
43
+
44
+ # Returns the name of the month
45
+ # (January, February, etc.)
46
+ def month_name; Date::MONTHNAMES[month]; end
47
+
48
+ # Returns the abbreviated name of the month
49
+ # (Jan, Feb, etc.)
50
+ def month_abbr; Date::ABBR_MONTHNAMES[month]; end
51
+
52
+ # Returns the name of the weekday
53
+ # (Sunday, Monday, etc.)
54
+ def day_name; Date::DAYNAMES[wday]; end
55
+
56
+ # Returns the abbreviated name of the weekday
57
+ # (Sun, Mon, etc.)
58
+ def day_abbr; Date::ABBR_DAYNAMES[wday]; end
59
+
60
+ alias :nmonth :month_name
61
+ alias :amonth :month_abbr
62
+
63
+ alias :nday :day_name
64
+ alias :aday :day_abbr
46
65
 
47
- # Returns the month as a zero-padded string
48
- # (i.e. June => 06)
49
- def zmonth; '%02d' % month; end
50
-
51
- # Returns the day as a zero-padded string
52
- # (5 => 05)
53
- def zday; '%02d' % mday; end
54
-
55
- # Returns the hour as a zero-padded string
56
- # (3 => 03)
57
- def zhour; '%02d' % hour; end
58
-
59
- # Returns the hour in 12-hour format
60
- # (5:00pm => 5)
61
- def hour12; hour % 12 == 0 ? 12 : hour % 12; end
62
-
63
- # Returns the hour in 12-hour format as a zero-padded string
64
- # (5:00pm => 05)
65
- def zhour12; '%02d' % hour12; end
66
-
67
- # Returns the minute as a zero-padded string
68
- # Note: If you need just the minute, use min
69
- def minute; '%02d' % min; end
70
-
71
- # Returns the second as a zero-padded string
72
- # Note: If you need just the second, use sec
73
- def second; '%02d' % sec; end
74
-
75
- # Returns the meridian
76
- # (AM/PM)
77
- def meridian; hour >= 12 ? 'PM' : 'AM'; end
78
-
79
- # Returns the meridian in short form (first letter)
80
- # (A/P)
81
- def smeridian; meridian[0].chr; end
82
-
83
- # Returns the meridian in lowercase
84
- # (am/pm)
85
- def lmeridian; meridian.downcase; end
86
-
87
- # Returns the meridian in lowercase, short form (first letter)
88
- # (a/p)
89
- def lsmeridian; smeridian.downcase; end
90
-
91
- # Returns the ordinal of the day
92
- # (1 => st, 2 => nd, 3 => rd, 4.. => th)
93
- def ordinal; mday.ordinal(false); end
94
- alias :ord :ordinal
66
+ # Returns the month as a zero-padded string
67
+ # (i.e. June => 06)
68
+ def zmonth; '%02d' % month; end
69
+
70
+ # Returns the day as a zero-padded string
71
+ # (5 => 05)
72
+ def zday; '%02d' % mday; end
73
+
74
+ # Returns the hour as a zero-padded string
75
+ # (3 => 03)
76
+ def zhour; '%02d' % hour; end
77
+
78
+ # Returns the hour in 12-hour format
79
+ # (5:00pm => 5)
80
+ def hour12; hour % 12 == 0 ? 12 : hour % 12; end
81
+
82
+ # Returns the hour in 12-hour format as a zero-padded string
83
+ # (5:00pm => 05)
84
+ def zhour12; '%02d' % hour12; end
85
+
86
+ # Returns the minute as a zero-padded string
87
+ # Note: If you need just the minute, use min
88
+ def minute; '%02d' % min; end
89
+
90
+ # Returns the second as a zero-padded string
91
+ # Note: If you need just the second, use sec
92
+ def second; '%02d' % sec; end
93
+
94
+ # Returns the meridian
95
+ # (AM/PM)
96
+ def meridian; hour >= 12 ? 'PM' : 'AM'; end
97
+
98
+ # Returns the meridian in short form (first letter)
99
+ # (A/P)
100
+ def smeridian; meridian[0].chr; end
101
+
102
+ # Returns the meridian in lowercase
103
+ # (am/pm)
104
+ def lmeridian; meridian.downcase; end
105
+
106
+ # Returns the meridian in lowercase, short form (first letter)
107
+ # (a/p)
108
+ def lsmeridian; smeridian.downcase; end
109
+
110
+ # Returns the ordinal of the day
111
+ # (1 => st, 2 => nd, 3 => rd, 4.. => th)
112
+ def ordinal; EZTime.ordinal(mday, false); end
113
+ alias :ord :ordinal
114
+ end
95
115
 
96
116
  # Formats the date/time according to the formatting string format_str
97
117
  # The formatting string consists of any of the methods defined in EZTime
@@ -107,7 +127,7 @@ module EZTime
107
127
  #
108
128
  # Output: 20 December 2003 at 5:30:00 pm
109
129
  def eztime(format_str)
110
- eval("'" + format_str.gsub(/:([a-z_]{1,}[0-9]{0,2})/, '\' + \1.to_s + \'') + "'")
130
+ EZTime::FormattedTime.new(self).format(format_str)
111
131
  end
112
132
  end
113
133
 
@@ -121,4 +141,4 @@ class Date; include EZTime; end
121
141
  # include EZTime
122
142
  # def ordinal; mday.ordinal(false); end
123
143
  # def self.ordinal; mday.ordinal(false); end
124
- # end
144
+ # end
data/test/helper.rb CHANGED
@@ -1,16 +1,17 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- begin
4
- Bundler.setup(:default, :development)
5
- rescue Bundler::BundlerError => e
6
- $stderr.puts e.message
7
- $stderr.puts "Run `bundle install` to install missing gems"
8
- exit e.status_code
9
- end
1
+ # require 'rubygems'
2
+ # require 'bundler'
3
+ # begin
4
+ # Bundler.setup(:default, :development)
5
+ # rescue Bundler::BundlerError => e
6
+ # $stderr.puts e.message
7
+ # $stderr.puts "Run `bundle install` to install missing gems"
8
+ # exit e.status_code
9
+ # end
10
10
  require 'test/unit'
11
11
 
12
12
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
13
13
  $LOAD_PATH.unshift(File.dirname(__FILE__))
14
+ # require File.dirname(__FILE__) . '/../lib/eztime.rb'
14
15
  require 'eztime'
15
16
 
16
17
  class Test::Unit::TestCase
data/test/test_eztime.rb CHANGED
@@ -59,7 +59,10 @@ class EZTimeTest < Test::Unit::TestCase
59
59
  end
60
60
 
61
61
  def test_everything
62
+ assert_equal '00', ('%02d' % 0)
63
+
62
64
  d = DateTime.civil(2000, 1, 1, 0, 0, 0)
65
+
63
66
  0.upto(1440/5) do |min|
64
67
  d += 300 if min > 0
65
68
  assert_equal d.strftime('%I:%M'), d.eztime(':hour12::minute')
@@ -93,7 +96,7 @@ class EZTimeTest < Test::Unit::TestCase
93
96
  end
94
97
 
95
98
  def test_ordinals
96
- assert_equal 'st', @ny.ord
99
+ assert_equal 'st', EZTime.ordinal(1)
97
100
  assert_equal 'January 1st', @ny.eztime(':month_name :day:ord')
98
101
 
99
102
  ordinals = %w{
@@ -108,4 +111,4 @@ class EZTimeTest < Test::Unit::TestCase
108
111
  assert_equal ordinals[mday], d.eztime(':ord'), "Failed on " + d.to_s
109
112
  end
110
113
  end
111
- end
114
+ end
metadata CHANGED
@@ -1,65 +1,23 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: eztime
3
- version: !ruby/object:Gem::Version
4
- hash: 23
5
- prerelease:
6
- segments:
7
- - 1
8
- - 0
9
- - 0
10
- version: 1.0.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Chris Scharf
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2012-07-05 00:00:00 -04:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- prerelease: false
23
- name: jeweler
24
- type: :development
25
- version_requirements: &id001 !ruby/object:Gem::Requirement
26
- none: false
27
- requirements:
28
- - - ~>
29
- - !ruby/object:Gem::Version
30
- hash: 63
31
- segments:
32
- - 1
33
- - 8
34
- - 4
35
- version: 1.8.4
36
- requirement: *id001
37
- - !ruby/object:Gem::Dependency
38
- prerelease: false
39
- name: rcov
40
- type: :development
41
- version_requirements: &id002 !ruby/object:Gem::Requirement
42
- none: false
43
- requirements:
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- hash: 3
47
- segments:
48
- - 0
49
- version: "0"
50
- requirement: *id002
11
+ date: 2015-02-27 00:00:00.000000000 Z
12
+ dependencies: []
51
13
  description: Easier date/time manipulation
52
14
  email: scharfie@gmail.com
53
15
  executables: []
54
-
55
16
  extensions: []
56
-
57
- extra_rdoc_files:
17
+ extra_rdoc_files:
58
18
  - LICENSE.txt
59
19
  - README.textile
60
- files:
61
- - Gemfile
62
- - Gemfile.lock
20
+ files:
63
21
  - LICENSE.txt
64
22
  - README.textile
65
23
  - Rakefile
@@ -70,39 +28,29 @@ files:
70
28
  - lib/eztime.rb
71
29
  - test/helper.rb
72
30
  - test/test_eztime.rb
73
- has_rdoc: true
74
31
  homepage: http://github.com/scharfie/eztime
75
- licenses:
32
+ licenses:
76
33
  - MIT
34
+ metadata: {}
77
35
  post_install_message:
78
36
  rdoc_options: []
79
-
80
- require_paths:
37
+ require_paths:
81
38
  - lib
82
- required_ruby_version: !ruby/object:Gem::Requirement
83
- none: false
84
- requirements:
85
- - - ">="
86
- - !ruby/object:Gem::Version
87
- hash: 3
88
- segments:
89
- - 0
90
- version: "0"
91
- required_rubygems_version: !ruby/object:Gem::Requirement
92
- none: false
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- hash: 3
97
- segments:
98
- - 0
99
- version: "0"
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
100
49
  requirements: []
101
-
102
50
  rubyforge_project:
103
- rubygems_version: 1.4.2
51
+ rubygems_version: 2.2.2
104
52
  signing_key:
105
- specification_version: 3
53
+ specification_version: 4
106
54
  summary: Easier date/time manipulation
107
55
  test_files: []
108
-
56
+ has_rdoc:
data/Gemfile DELETED
@@ -1,11 +0,0 @@
1
- source "http://rubygems.org"
2
- # Add dependencies required to use your gem here.
3
- # Example:
4
- # gem "activesupport", ">= 2.3.5"
5
-
6
- # Add dependencies to develop your gem here.
7
- # Include everything needed to run rake, tests, features, etc.
8
- group :development do
9
- gem "jeweler", "~> 1.8.4"
10
- gem "rcov"
11
- end
data/Gemfile.lock DELETED
@@ -1,21 +0,0 @@
1
- GEM
2
- remote: http://rubygems.org/
3
- specs:
4
- git (1.2.5)
5
- jeweler (1.8.4)
6
- bundler (~> 1.0)
7
- git (>= 1.2.5)
8
- rake
9
- rdoc
10
- json (1.7.3)
11
- rake (0.9.2.2)
12
- rcov (1.0.0)
13
- rdoc (3.12)
14
- json (~> 1.4)
15
-
16
- PLATFORMS
17
- ruby
18
-
19
- DEPENDENCIES
20
- jeweler (~> 1.8.4)
21
- rcov