Skip to content

Commit

Permalink
To year should use timezone.
Browse files Browse the repository at this point in the history
  • Loading branch information
gaspard committed Feb 1, 2012
1 parent 7ccc951 commit 20a16e7
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 19 deletions.
1 change: 1 addition & 0 deletions History.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* Fixed ajax bugs with dom_ids in nested partials.
* Better Acl display, comments on relations.
* Support for 'to_date' on time object with proper timezone translation. <===== TODO: Document
* Time to 'year' should use timezone.

== 1.1.3 2011-11-09

Expand Down
3 changes: 2 additions & 1 deletion config/gems.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ open4:
daemons: # upload progress
gem_plugin: # upload progress
simple_xlsx_writer: # spreadsheet
lib: 'simple_xlsx'

querybuilder: '= 1.1.0'
yamltest: '= 0.7.0'
rubyless: '= 0.8.6'
property: '= 2.2.0'
versions: '= 0.3.1'
zafu: '= 0.8.5'
zafu: '= 0.8.6'

jeweler:

Expand Down
6 changes: 4 additions & 2 deletions lib/zena.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ def config_gems(config)
gem_configuration.each do |gem_name, gem_config|
if gem_config
conf = gem_config.symbolize_keys
conf[:version].gsub!(/\A=\s*/,'')
if conf[:version]
conf[:version].gsub!(/\A=\s*/,'')
end
if conf[:optional]
if brick = conf[:brick]
if Bricks::CONFIG[brick]
Expand Down Expand Up @@ -462,4 +464,4 @@ def make_hashes(h)
Zena.add_load_paths
Zena.gems_setup
Zena.load_custom_extensions
require 'rubyless'
require 'rubyless'
25 changes: 20 additions & 5 deletions lib/zena/use/dates.rb
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,19 @@ def strftime_tz(format, tz = nil)
''
end

def year_tz(tz = nil)
if tz.blank?
tz = visitor.tz
elsif tz.kind_of?(String)
tz = TZInfo::Timezone.get(tz)
end
tz.utc_to_local(self).year
rescue TZInfo::InvalidTimezoneIdentifier
0
rescue TZInfo::AmbiguousTime
0
end

def to_date_tz(tz = nil)
if tz.blank?
tz = visitor.tz
Expand All @@ -319,12 +332,14 @@ module ZafuMethods
:minutes => Number,
:seconds => Number}] => Time
safe_method_for Time, :to_i => {:class => Number, :pre_processor => true}
safe_method_for Time, :year => {:class => Number, :pre_processor => true}
safe_method_for Time, [:strftime, String] => {:class => String, :pre_processor => true, :method => 'strftime_tz'}
safe_method_for Time, [:strftime, String, String] => {:class => String, :pre_processor => true, :method => 'strftime_tz'}
safe_method_for Time, :year => {:class => Number, :pre_processor => true, :method => 'year_tz'}
safe_method_for Time, [:year, String] => {:class => Number, :pre_processor => true, :method => 'year_tz'}
safe_method_for Time, [:year, TZInfo::Timezone] => {:class => Number, :pre_processor => true, :method => 'year_tz'}
safe_method_for Time, [:strftime, String] => {:class => String, :pre_processor => true, :method => 'strftime_tz'}
safe_method_for Time, [:strftime, String, String] => {:class => String, :pre_processor => true, :method => 'strftime_tz'}
safe_method_for Time, [:strftime, String, TZInfo::Timezone] => {:class => String, :pre_processor => true, :method => 'strftime_tz'}
safe_method_for Time, :to_date => {:class => Date, :pre_processor => true, :method => 'to_date_tz'}
safe_method_for Time, [:to_date, String] => {:class => Date, :pre_processor => true, :method => 'to_date_tz'}
safe_method_for Time, :to_date => {:class => Date, :pre_processor => true, :method => 'to_date_tz'}
safe_method_for Time, [:to_date, String] => {:class => Date, :pre_processor => true, :method => 'to_date_tz'}
safe_method_for Time, [:to_date, TZInfo::Timezone] => {:class => Date, :pre_processor => true, :method => 'to_date_tz'}
safe_method_for TZInfo::Timezone, :to_s => {:class => String, :pre_processor => true}

Expand Down
15 changes: 14 additions & 1 deletion test/integration/zafu_compiler/dates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,17 @@ format_date_empty_string:

date_empty_value:
src: "<r:input name='created_at' value=''/>"
tem: "<input type='text' name='node[created_at]' value=''/>"
tem: "<input type='text' name='node[created_at]' value=''/>"

time_to_date:
context:
tz: 'US/Pacific'
src: "<b do='created_at.to_date'/> <b do='created_at.to_date(\"UTC\")'/>"
res: "<b>2006-03-09</b> <b>2006-03-10</b>"

time_year:
context:
node: opening
tz: 'US/Pacific'
src: "<r:Post?><b do='this.date.year'/> <b do='this.date.year(\"UTC\")'/></r:Post?>"
res: "<b>2011</b> <b>2012</b>"
6 changes: 0 additions & 6 deletions test/integration/zafu_compiler/safe_definitions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,3 @@ hash_to_params:
src: "<b do='{:q =&gt; params[:q]}' do='to_param'/>"
tem: "<% var1 = {:q => params[:q]} %><b><%= var1.to_param %></b>"
res: '<b>q%5Bone%5D=1&q%5Btwo%5D=2</b>'

time_to_date:
context:
tz: 'US/Pacific'
src: "<b do='created_at.to_date'/> <b do='created_at.to_date(\"UTC\")'/>"
res: "<b>2006-03-09</b> <b>2006-03-10</b>"
7 changes: 7 additions & 0 deletions test/integration/zafu_compiler_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -356,5 +356,12 @@ def test_relations_same_name_as_class
yt_do_test('relations', 'same_name_as_class')
end

def test_dates_time_year
login(:lion)
node = secure(Node) { nodes(:opening) }
node.update_attributes!(:date => Time.utc(2012,1,1,0,0))
yt_do_test('dates', 'time_year')
end

yt_make
end
14 changes: 10 additions & 4 deletions zena.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Gem::Specification.new do |s|

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Gaspard Bucher"]
s.date = %q{2012-01-26}
s.date = %q{2012-01-30}
s.default_executable = %q{zena}
s.description = %q{zena is a Ruby on Rails CMS (content managment system) with a focus on usability, ease of customization and web 2.0 goodness (application like behaviour).}
s.email = %q{gaspard@teti.ch}
Expand Down Expand Up @@ -1983,6 +1983,9 @@ Gem::Specification.new do |s|
"test/selenium/Edit/edit4.rsel",
"test/selenium/Edit/edit5.rsel",
"test/selenium/Edit/edit6.rsel",
"test/selenium/Filter/0setup.rsel",
"test/selenium/Filter/filter1.rsel",
"test/selenium/Filter/filter2.rsel",
"test/selenium/Form/0setup.rsel",
"test/selenium/Form/form1.rsel",
"test/selenium/Form/form2.rsel",
Expand Down Expand Up @@ -2165,11 +2168,12 @@ Gem::Specification.new do |s|
s.add_runtime_dependency(%q<tzinfo>, [">= 0"])
s.add_runtime_dependency(%q<rails>, ["= 2.3.11"])
s.add_runtime_dependency(%q<httparty>, ["= 0.7.8"])
s.add_runtime_dependency(%q<simple_xlsx_writer>, [">= 0"])
s.add_runtime_dependency(%q<rubyless>, ["= 0.8.6"])
s.add_runtime_dependency(%q<property>, ["= 2.2.0"])
s.add_runtime_dependency(%q<uuidtools>, ["= 2.0.0"])
s.add_runtime_dependency(%q<authlogic>, ["= 2.1.3"])
s.add_runtime_dependency(%q<zafu>, ["= 0.8.5"])
s.add_runtime_dependency(%q<zafu>, ["= 0.8.6"])
s.add_runtime_dependency(%q<shoulda>, ["= 2.10.3"])
s.add_runtime_dependency(%q<fast_gettext>, ["~> 0.4.16"])
s.add_runtime_dependency(%q<syntax>, ["= 1.0.0"])
Expand All @@ -2191,11 +2195,12 @@ Gem::Specification.new do |s|
s.add_dependency(%q<tzinfo>, [">= 0"])
s.add_dependency(%q<rails>, ["= 2.3.11"])
s.add_dependency(%q<httparty>, ["= 0.7.8"])
s.add_dependency(%q<simple_xlsx_writer>, [">= 0"])
s.add_dependency(%q<rubyless>, ["= 0.8.6"])
s.add_dependency(%q<property>, ["= 2.2.0"])
s.add_dependency(%q<uuidtools>, ["= 2.0.0"])
s.add_dependency(%q<authlogic>, ["= 2.1.3"])
s.add_dependency(%q<zafu>, ["= 0.8.5"])
s.add_dependency(%q<zafu>, ["= 0.8.6"])
s.add_dependency(%q<shoulda>, ["= 2.10.3"])
s.add_dependency(%q<fast_gettext>, ["~> 0.4.16"])
s.add_dependency(%q<syntax>, ["= 1.0.0"])
Expand All @@ -2218,11 +2223,12 @@ Gem::Specification.new do |s|
s.add_dependency(%q<tzinfo>, [">= 0"])
s.add_dependency(%q<rails>, ["= 2.3.11"])
s.add_dependency(%q<httparty>, ["= 0.7.8"])
s.add_dependency(%q<simple_xlsx_writer>, [">= 0"])
s.add_dependency(%q<rubyless>, ["= 0.8.6"])
s.add_dependency(%q<property>, ["= 2.2.0"])
s.add_dependency(%q<uuidtools>, ["= 2.0.0"])
s.add_dependency(%q<authlogic>, ["= 2.1.3"])
s.add_dependency(%q<zafu>, ["= 0.8.5"])
s.add_dependency(%q<zafu>, ["= 0.8.6"])
s.add_dependency(%q<shoulda>, ["= 2.10.3"])
s.add_dependency(%q<fast_gettext>, ["~> 0.4.16"])
s.add_dependency(%q<syntax>, ["= 1.0.0"])
Expand Down

0 comments on commit 20a16e7

Please sign in to comment.