public
Description: A RESTful Blog API written in Merb
Homepage: http://pmpknpi.com/
Clone URL: git://github.com/sintaxi/pmpknpi.git
very crude but effective timezone support


git-svn-id: https://pmpknpi.googlecode.com/svn/trunk@64 
8b0ec7b7-bd45-0410-8a4e-3563a9e70f90
brockwhitten (author)
Wed Apr 09 02:11:23 -0700 2008
commit  5eb17b63c5b33112ad0b4e8bd01264e77d803222
tree    2583b9f9202448aefbd847ad397e61226ccaeb2c
parent  2f64817528fc498299754b25612c5e8b6730cd0c
...
27
28
29
 
 
 
 
 
 
 
 
30
...
27
28
29
30
31
32
33
34
35
36
37
38
0
@@ -27,3 +27,11 @@ end
0
 ##############################################################################
0
 # ADD YOUR CUSTOM TASKS BELOW
0
 ##############################################################################
0
+
0
+desc "calculate timezoze offset"
0
+task :timezone_offset do
0
+ offset = Time.now.hour - Time.now.utc.hour
0
+ puts "calculating offset...\n\n"
0
+ puts " * Your timezone is #{offset} hours off UTC"
0
+ puts " * In config/settings.yml set 'timezone_offset: #{offset}'\n\n"
0
+end
0
\ No newline at end of file
...
1
 
2
3
4
...
10
11
12
13
 
14
15
16
...
34
35
36
37
 
38
39
40
...
1
2
3
4
5
...
11
12
13
 
14
15
16
17
...
35
36
37
 
38
39
40
41
0
@@ -1,4 +1,5 @@
0
 class Article < ActiveRecord::Base
0
+ include GlobalMixin
0
   
0
   # ASSOCIATIONS
0
   has_many :comments
0
@@ -10,7 +11,7 @@ class Article < ActiveRecord::Base
0
   # CALLBACKS
0
   before_save :create_permalink
0
   before_save :draft_check
0
- #after_validation :convert_to_utc
0
+ after_validation :convert_to_utc
0
   
0
   # PLUGINS
0
   merb_can_filter :body, :excerpt
0
@@ -34,7 +35,7 @@ class Article < ActiveRecord::Base
0
   end
0
   
0
   def convert_to_utc
0
- self.published_at = published_at.utc if published_at
0
+ self.published_at = local_to_utc(published_at) if published_at
0
   end
0
   
0
   def create_permalink
...
22
23
24
25
 
26
27
...
22
23
24
 
25
26
27
0
@@ -22,5 +22,5 @@
0
   </li>
0
   
0
   <li class="small" id="publish_on"><label>Publish on</label>
0
- <%= datetime_control :published_at, :start_year => (@article.published_at || Time.now.utc).year-1, :end_year => (Time.now.utc.year + 4), :order => [:month, :day, :year] %></li>
0
+ <%= datetime_control :published_at, :datetime => utc_to_local(Time.now.utc), :start_year => (@article.published_at || Time.now.utc).year-1, :end_year => (Time.now.utc.year + 4), :order => [:month, :day, :year] %></li>
0
 </ul>
0
\ No newline at end of file
...
6
7
8
9
 
10
11
12
...
6
7
8
 
9
10
11
12
0
@@ -6,7 +6,7 @@
0
         <%= link_to article.title, "/articles/#{article.to_param}" %></h1>
0
       <h2 class="created_at"><%#= time_ago_in_words(article.published_at) + ' ago' unless article.published_at.nil? %>
0
         <%= article.published_at.nil? ? 'unpublished' : time_ago_in_words(article.published_at) + ' ago' %> /
0
- <%= pluralize article.comments.count, 'Comment' %>
0
+ <%= pluralize article.comments_count, 'Comment' %>
0
       </h2>
0
 
0
       <div class="body">
...
1
2
3
4
5
6
...
10
11
12
13
14
15
16
17
...
27
28
29
30
31
32
33
...
38
39
40
41
42
43
44
45
46
47
48
49
50
 
51
52
53
54
55
56
...
68
69
70
71
72
73
74
 
75
76
77
78
79
80
81
82
 
 
...
 
 
 
1
2
3
...
7
8
9
 
 
10
11
12
...
22
23
24
 
25
26
27
...
32
33
34
 
 
 
 
 
 
 
 
 
 
35
36
37
 
38
39
40
...
52
53
54
 
 
 
 
55
56
57
58
59
60
61
 
 
62
63
0
@@ -1,6 +1,3 @@
0
-
0
-
0
-
0
 # Make the app's "gems" directory a place where gems are loaded from
0
 Gem.clear_paths
0
 Gem.path.unshift(Merb.root / "gems")
0
@@ -10,8 +7,6 @@ $LOAD_PATH.unshift(Merb.root / "lib")
0
 
0
 
0
 Merb::Config.use do |c|
0
- ### Sets up a custom session id key, if you want to piggyback sessions of other applications
0
- ### with the cookie session store. If not specified, defaults to '_session_id'.
0
   c[:session_id_key] = 'pmpknpi_session_id'
0
   c[:session_secret_key] = '669bed3f14d49f3bfa52530312c225f3753455e1'
0
   c[:session_store] = 'cookie'
0
@@ -27,7 +22,6 @@ use_test :rspec
0
 require 'authenticated_system'
0
 require 'date_and_time_helpers'
0
 require 'global_mixin'
0
-require 'active_record_extension'
0
 require 'BlueCloth'
0
 require 'RedCloth'
0
 
0
@@ -38,19 +32,9 @@ dependencies "rubygems",
0
               "merb-assets",
0
               "merb_can_filter"
0
 
0
-### Add your other dependencies here
0
-
0
-# These are some examples of how you might specify dependencies.
0
-#
0
-# dependencies "RedCloth", "merb_helpers"
0
-# OR
0
-# dependency "RedCloth", "> 3.0"
0
-# OR
0
-# dependencies "RedCloth" => "> 3.0", "ruby-aes-cext" => "= 1.0"
0
-
0
+# FROM merb_has_rails_plugins
0
 Merb::BootLoader.before_app_loads do
0
   if defined?(Merb::Plugins)
0
- puts "Loading Rails plugins from plugins/"
0
     Dir["#{Merb.root}/plugins/*"].each do |dir|
0
       plugin_init = dir / 'init.rb'
0
        plugin_lib = dir / 'lib'
0
@@ -68,15 +52,12 @@ Merb::BootLoader.before_app_loads do
0
 end
0
 
0
 Merb::BootLoader.after_app_loads do
0
- #ActiveRecord::Base.default_timezone = :utc
0
-
0
- ### Add dependencies here that must load after the application loads:
0
- # dependency "magic_admin" # this gem uses the app's model classes
0
+ ActiveRecord::Base.default_timezone = :utc
0
 end
0
 
0
 # YAML FILES
0
 SETTINGS = YAML.load_file("#{Merb.root}/config/settings.yml")[Merb.environment]
0
 
0
 # MIME TYPES
0
-Merb.add_mime_type(:rss, :to_xml, %w[application/rss+xml])
0
-Merb.add_mime_type(:atom, :to_xml, %w[application/atom+xml])
0
+Merb.add_mime_type(:rss, :to_xml, %w[application/rss+xml])
0
+Merb.add_mime_type(:atom, :to_xml, %w[application/atom+xml])
...
6
7
8
 
9
10
11
...
6
7
8
9
10
11
12
0
@@ -6,6 +6,7 @@ defaults: &defaults
0
   author: "Brock Whitten"
0
   password: "foobar"
0
   filter: "Markdown"
0
+ timezone_offset: -7
0
 
0
 development:
0
   <<: *defaults
...
4
5
6
 
 
 
 
 
 
 
 
7
8
9
...
4
5
6
7
8
9
10
11
12
13
14
15
16
17
0
@@ -4,5 +4,13 @@ module GlobalMixin
0
   def viewer_data
0
     @viewer_data ||= "#{request.remote_ip}--#{request.env["HTTP_USER_AGENT"].gsub(',', ';')}"
0
   end
0
+
0
+ def utc_to_local(time, offset=SETTINGS["timezone_offset"])
0
+ time + (offset *3600)
0
+ end
0
+
0
+ def local_to_utc(time, offset =SETTINGS["timezone_offset"])
0
+ time + (offset *-1 *3600)
0
+ end
0
 
0
 end
0
\ No newline at end of file

Comments

    No one has commented yet.