datizzle 0.1.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.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Jessica Suttles
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.
@@ -0,0 +1,21 @@
1
+ = datizzle
2
+
3
+ Usage:
4
+
5
+ dt = DateTime.now
6
+
7
+ puts dt.format(%weekday%, %month% %month.day%, %year% %hour%:%minute% %ampm%)
8
+
9
+ == Note on Patches/Pull Requests
10
+
11
+ * Fork the project.
12
+ * Make your feature addition or bug fix.
13
+ * Add tests for it. This is important so I don't break it in a
14
+ future version unintentionally.
15
+ * Commit, do not mess with rakefile, version, or history.
16
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
17
+ * Send me a pull request. Bonus points for topic branches.
18
+
19
+ == Copyright
20
+
21
+ Copyright (c) 2010 Jessica Suttles. See LICENSE for details.
@@ -0,0 +1,45 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "datizzle"
8
+ gem.summary = %Q{Ruby DateTime formatting made legible.}
9
+ gem.description = %Q{Ruby DateTime formatting made legible.}
10
+ gem.email = "jlsuttles@gmail.com"
11
+ gem.homepage = "http://github.com/jlsuttles/datizzle"
12
+ gem.authors = ["Jessica Suttles"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'spec/rake/spectask'
22
+ Spec::Rake::SpecTask.new(:spec) do |spec|
23
+ spec.libs << 'lib' << 'spec'
24
+ spec.spec_files = FileList['spec/**/*_spec.rb']
25
+ end
26
+
27
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
28
+ spec.libs << 'lib' << 'spec'
29
+ spec.pattern = 'spec/**/*_spec.rb'
30
+ spec.rcov = true
31
+ end
32
+
33
+ task :spec => :check_dependencies
34
+
35
+ task :default => :spec
36
+
37
+ require 'rake/rdoctask'
38
+ Rake::RDocTask.new do |rdoc|
39
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
+
41
+ rdoc.rdoc_dir = 'rdoc'
42
+ rdoc.title = "datizzle #{version}"
43
+ rdoc.rdoc_files.include('README*')
44
+ rdoc.rdoc_files.include('lib/**/*.rb')
45
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,7 @@
1
+ require 'date'
2
+ require 'lib/datizzle/instance_methods'
3
+
4
+ module Datizzle
5
+ end
6
+
7
+ DateTime.send(:include, Datizzle::InstanceMethods)
@@ -0,0 +1,41 @@
1
+ module Datizzle
2
+ module InstanceMethods
3
+
4
+ TOKENS = { 'datetime' => '%c',
5
+ 'date' => '%x',
6
+ 'time' => '%X',
7
+ 'weekday' => '%A',
8
+ 'weekday.abbr' => '%a',
9
+ 'weekday.number' => '%w',
10
+ 'month' => '%B',
11
+ 'month.abbr' => '%b',
12
+ 'month.number' => '%m',
13
+ 'month.day' => '%d',
14
+ 'month.day.abbr' => '%e',
15
+ 'year' => '%Y',
16
+ 'year.abbr' => '%y',
17
+ 'year.day' => '%j',
18
+ 'year.week' => '%U',
19
+ 'year.week.sunday'=> '%U',
20
+ 'year.week.monday'=> '%W',
21
+ 'hour' => '%I',
22
+ 'hour.12' => '%I',
23
+ 'hour.24' => '%H',
24
+ 'minute' => '%M',
25
+ 'second' => '%S',
26
+ 'AMPM' => '%P',
27
+ 'ampm' => '%p',
28
+ 'timezone' => '%Z',
29
+ 'percent' => '%%'
30
+ }
31
+
32
+ def format string
33
+ strftime( replace_tokens string )
34
+ end
35
+
36
+ def replace_tokens string
37
+ string.gsub(/%([^%]*)%/) { |match| TOKENS[$1] }
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,158 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Datizzle" do
4
+ let(:dt) { DateTime.now }
5
+
6
+ ###
7
+ ### DATES
8
+ ###
9
+
10
+ it "should show the preferred representation for the date alone, no time" do
11
+ dt.format("%date%").should == dt.strftime("%x")
12
+ end
13
+
14
+ it "should show the full weekday name ( 'Sunday' )" do
15
+ dt.format("%weekday%").should == dt.strftime("%A")
16
+ end
17
+
18
+ it "should show the abbreviated weekday name ( 'Sun' )" do
19
+ dt.format("%weekday.abbr%").should == dt.strftime("%a")
20
+ end
21
+
22
+ it "should show the numbered weekday where Sunday is the first weekday ( 0..6 )" do
23
+ dt.format("%weekday.number%").should == dt.strftime("%w")
24
+ end
25
+
26
+ it "should show the full month name ( 'January' )" do
27
+ dt.format("%month%").should == dt.strftime("%B")
28
+ end
29
+
30
+ it "should show the abbreviated month name ( 'Jan' )" do
31
+ dt.format("%month.abbr%").should == dt.strftime("%b")
32
+ end
33
+
34
+ it "should show the numbered month ( 01..12 )" do
35
+ dt.format("%month.number%").should == dt.strftime("%m")
36
+ end
37
+
38
+ it "should show the month day with leading zero ( 01..31 )" do
39
+ dt.format("%month.day%").should == dt.strftime("%d")
40
+ end
41
+
42
+ it "should show the month day without leading zero ( 1..31 )" do
43
+ dt.format("%month.day.abbr%").should == dt.strftime("%e")
44
+ end
45
+
46
+ it "should show the year with century" do
47
+ dt.format("%year%").should == dt.strftime("%Y")
48
+ end
49
+
50
+ it "should show the year without century ( 00..99 )" do
51
+ dt.format("%year.abbr%").should == dt.strftime("%y")
52
+ end
53
+
54
+ it "should show the day number of the year ( 001..366 )" do
55
+ dt.format("%year.day%").should == dt.strftime("%j")
56
+ end
57
+
58
+ it "should show the week number of the year with the first Sunday as the first day of the week ( 00..53 )" do
59
+ dt.format("%year.week%").should == dt.strftime("%U")
60
+ end
61
+
62
+ it "should show the week number of the year with the first Sunday as the first day of the week ( 00..53 )" do
63
+ dt.format("%year.week.sunday%").should == dt.strftime("%U")
64
+ end
65
+
66
+ it "should show the week number of the year with the first Monday as the first day of the week ( 00..53 )" do
67
+ dt.format("%year.week.monday%").should == dt.strftime("%W")
68
+ end
69
+
70
+ ###
71
+ ### TIMES
72
+ ###
73
+
74
+ it "should show the preferred representation for the time alone, no date" do
75
+ dt.format("%time%").should == dt.strftime("%X")
76
+ end
77
+
78
+ it "should show the hour of the day on a 12 hour clock ( 01..12 )" do
79
+ dt.format("%hour%").should == dt.strftime("%I")
80
+ end
81
+
82
+ it "should show the hour of the day on a 12 hour clock ( 01..12 )" do
83
+ dt.format("%hour.12%").should == dt.strftime("%I")
84
+ end
85
+
86
+ it "should show the hour of the day on a 21 hour clock ( 00..23 )" do
87
+ dt.format("%hour.24%").should == dt.strftime("%H")
88
+ end
89
+
90
+ it "should show the minute of the hour ( 00..59 )" do
91
+ dt.format("%minute%").should == dt.strftime("%M")
92
+ end
93
+
94
+ it "should show the second of the minute ( 00..60 )" do
95
+ dt.format("%second%").should == dt.strftime("%S")
96
+ end
97
+
98
+ it "should show the uppercase meridian indicator ( 'AM' or 'PM' )" do
99
+ dt.format("%AMPM%").should == dt.strftime("%P")
100
+ end
101
+
102
+ it "should show the lowercase meridian indicator ( 'am' or 'pm' )" do
103
+ dt.format("%ampm%").should == dt.strftime("%p")
104
+ end
105
+
106
+ it "should show the the time zone name" do
107
+ dt.format("%timezone%").should == dt.strftime("%Z")
108
+ end
109
+
110
+ ###
111
+ ### MISC
112
+ ###
113
+
114
+ it "should show the preferred local date and time representation" do
115
+ dt.format("%datetime%").should == dt.strftime("%c")
116
+ end
117
+
118
+ it "should show the literal '%' character" do
119
+ dt.format("%percent%").should == dt.strftime("%%")
120
+ end
121
+
122
+ ###
123
+ ### COMMON FORMATS
124
+ ###
125
+
126
+ it "should look like 'Friday, January 1, 2010 12:00 am'" do
127
+ dt.format("%weekday%, %month% %month.day.abbr%, %year% %hour%:%minute% %ampm%").should == dt.strftime("%A, %B %e, %Y %I:%M %p")
128
+ end
129
+
130
+ it "should look like 'Friday, January 1, 2010'" do
131
+ dt.format("%weekday%, %month% %month.day.abbr%, %year%").should == dt.strftime("%A, %B %e, %Y")
132
+ end
133
+
134
+ it "should look like 'Fri, Jan 1, 2010'" do
135
+ dt.format("%weekday.abbr%, %month.abbr% %month.day.abbr%, %year%").should == dt.strftime("%a, %b %e, %Y")
136
+ end
137
+
138
+ it "should look like '01/01/2010'" do
139
+ dt.format("%month.number%/%month.day%/%year%").should == dt.strftime("%m/%d/%Y")
140
+ end
141
+
142
+ it "should look like '2010 Jan 1'" do
143
+ dt.format("%year% %month.abbr% %month.day%").should == dt.strftime("%Y %b %e")
144
+ end
145
+
146
+ it "should look like '2010-01-01'" do
147
+ dt.format("%year%-%month.number%-%month.day%").should == dt.strftime("%Y-%m-%d")
148
+ end
149
+
150
+ it "should look like '00:00:00 AM'" do
151
+ dt.format("%hour.24%:%minute%:%second% %AMPM%").should == dt.strftime("%H:%M:%S %P")
152
+ end
153
+
154
+ it "should look like '12:00 am'" do
155
+ dt.format("%hour.12%:%minute% %ampm%").should == dt.strftime("%I:%M %p")
156
+ end
157
+
158
+ end
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,7 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'datizzle'
4
+
5
+ Spec::Runner.configure do |config|
6
+
7
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: datizzle
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
+ - Jessica Suttles
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-10-17 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 13
30
+ segments:
31
+ - 1
32
+ - 2
33
+ - 9
34
+ version: 1.2.9
35
+ type: :development
36
+ version_requirements: *id001
37
+ description: Ruby DateTime formatting made legible.
38
+ email: jlsuttles@gmail.com
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files:
44
+ - LICENSE
45
+ - README.rdoc
46
+ files:
47
+ - .document
48
+ - .gitignore
49
+ - LICENSE
50
+ - README.rdoc
51
+ - Rakefile
52
+ - VERSION
53
+ - lib/datizzle.rb
54
+ - lib/datizzle/instance_methods.rb
55
+ - spec/datizzle_spec.rb
56
+ - spec/spec.opts
57
+ - spec/spec_helper.rb
58
+ has_rdoc: true
59
+ homepage: http://github.com/jlsuttles/datizzle
60
+ licenses: []
61
+
62
+ post_install_message:
63
+ rdoc_options:
64
+ - --charset=UTF-8
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ hash: 3
82
+ segments:
83
+ - 0
84
+ version: "0"
85
+ requirements: []
86
+
87
+ rubyforge_project:
88
+ rubygems_version: 1.3.7
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: Ruby DateTime formatting made legible.
92
+ test_files:
93
+ - spec/datizzle_spec.rb
94
+ - spec/spec_helper.rb