github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

rails / rails

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 4,959
    • 829
  • Source
  • Commits
  • Network (829)
  • Downloads (61)
  • Wiki (4)
  • Graphs
  • Branch: 2-2-stable

click here to add a description

click here to add a homepage

  • Branches (6)
    • 1-2-stable
    • 2-0-stable
    • 2-1-stable
    • 2-2-stable ✓
    • 2-3-stable
    • master
  • Tags (61)
    • v3.0.0.beta1
    • v2.3.5
    • v2.3.4
    • v2.3.3.1
    • v2.3.3
    • v2.3.2.1
    • v2.3.2
    • v2.3.1
    • v2.3.0
    • v2.2.3
    • v2.2.2
    • v2.2.1
    • v2.2.0
    • v2.1.2
    • v2.1.1
    • v2.1.0_RC1
    • v2.1.0
    • v2.0.5
    • v2.0.4
    • v2.0.3
    • v2.0.2
    • v2.0.1
    • v2.0.0_RC2
    • v2.0.0_RC1
    • v2.0.0_PR
    • v2.0.0
    • v1.2.6
    • v1.2.5
    • v1.2.4
    • v1.2.3
    • v1.2.2
    • v1.2.1
    • v1.2.0_RC2
    • v1.2.0_RC1
    • v1.2.0
    • v1.1.6
    • v1.1.5
    • v1.1.4
    • v1.1.3
    • v1.1.2
    • v1.1.1
    • v1.1.0_RC1
    • v1.1.0
    • v1.0.0
    • v0.14.4
    • v0.14.3
    • v0.14.2
    • v0.14.1
    • v0.13.1
    • v0.13.0
    • v0.12.0
    • v0.11.1
    • v0.11.0
    • v0.10.1
    • v0.10.0
    • v0.9.5
    • v0.9.4.1
    • v0.9.4
    • v0.9.3
    • v0.9.2
    • v0.9.1
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Ruby on Rails — Read more

  cancel

http://rubyonrails.org

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Make sure strip_tags removes tags which start with a non-printable 
character 
dasil003 (author)
Mon Nov 16 21:17:35 -0800 2009
NZKoz (committer)
Thu Nov 26 16:38:46 -0800 2009
commit  785281ade8c2347614525e9aceb5e62c80eec6f8
tree    1ecddcc99dbc4e761c1cb667e15b4e04f789b54a
parent  a60779f7e69a7045a308844e9464d7d6b9cac94d
rails / activesupport / lib / active_support / core_ext / time / zones.rb activesupport/lib/active_support/core_ext/time/zones.rb
100644 86 lines (79 sloc) 3.853 kb
edit raw blame history
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
module ActiveSupport #:nodoc:
  module CoreExtensions #:nodoc:
    module Time #:nodoc:
      module Zones
        def self.included(base) #:nodoc:
          base.extend(ClassMethods) if base == ::Time # i.e., don't include class methods in DateTime
        end
        
        module ClassMethods
          attr_accessor :zone_default
          
          # Returns the TimeZone for the current request, if this has been set (via Time.zone=).
          # If <tt>Time.zone</tt> has not been set for the current request, returns the TimeZone specified in <tt>config.time_zone</tt>.
          def zone
            Thread.current[:time_zone] || zone_default
          end
 
          # Sets <tt>Time.zone</tt> to a TimeZone object for the current request/thread.
          #
          # This method accepts any of the following:
          #
          # * A Rails TimeZone object.
          # * An identifier for a Rails TimeZone object (e.g., "Eastern Time (US & Canada)", <tt>-5.hours</tt>).
          # * A TZInfo::Timezone object.
          # * An identifier for a TZInfo::Timezone object (e.g., "America/New_York").
          #
          # Here's an example of how you might set <tt>Time.zone</tt> on a per request basis -- <tt>current_user.time_zone</tt>
          # just needs to return a string identifying the user's preferred TimeZone:
          #
          # class ApplicationController < ActionController::Base
          # before_filter :set_time_zone
          #
          # def set_time_zone
          # Time.zone = current_user.time_zone
          # end
          # end
          def zone=(time_zone)
            Thread.current[:time_zone] = get_zone(time_zone)
          end
          
          # Allows override of <tt>Time.zone</tt> locally inside supplied block; resets <tt>Time.zone</tt> to existing value when done.
          def use_zone(time_zone)
            old_zone, ::Time.zone = ::Time.zone, get_zone(time_zone)
            yield
          ensure
            ::Time.zone = old_zone
          end
          
          # Returns <tt>Time.zone.now</tt> when <tt>config.time_zone</tt> is set, otherwise just returns <tt>Time.now</tt>.
          def current
            ::Time.zone_default ? ::Time.zone.now : ::Time.now
          end
          
          private
            def get_zone(time_zone)
              return time_zone if time_zone.nil? || time_zone.is_a?(TimeZone)
              # lookup timezone based on identifier (unless we've been passed a TZInfo::Timezone)
              unless time_zone.respond_to?(:period_for_local)
                time_zone = TimeZone[time_zone] || TZInfo::Timezone.get(time_zone) rescue nil
              end
              # Return if a TimeZone instance, or wrap in a TimeZone instance if a TZInfo::Timezone
              if time_zone
                time_zone.is_a?(TimeZone) ? time_zone : TimeZone.create(time_zone.name, nil, time_zone)
              end
            end
        end
        
        # Returns the simultaneous time in <tt>Time.zone</tt>.
        #
        # Time.zone = 'Hawaii' # => 'Hawaii'
        # Time.utc(2000).in_time_zone # => Fri, 31 Dec 1999 14:00:00 HST -10:00
        #
        # This method is similar to Time#localtime, except that it uses <tt>Time.zone</tt> as the local zone
        # instead of the operating system's time zone.
        #
        # You can also pass in a TimeZone instance or string that identifies a TimeZone as an argument,
        # and the conversion will be based on that zone instead of <tt>Time.zone</tt>.
        #
        # Time.utc(2000).in_time_zone('Alaska') # => Fri, 31 Dec 1999 15:00:00 AKST -09:00
        def in_time_zone(zone = ::Time.zone)
          ActiveSupport::TimeWithZone.new(utc? ? self : getutc, ::Time.__send__(:get_zone, zone))
        end
      end
    end
  end
end
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server