virtual_time_zone_rails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0c08ae8400875a35c877a64569f9e4d9237c1b88
4
+ data.tar.gz: d53a2eb70e1be6f547ea34d33541c965fa5107d0
5
+ SHA512:
6
+ metadata.gz: 09d2f7919c03cbfe1c4e86461aaa52b28e377ae317e72f6d3a63de4572c4040172038b7aa877d5e3cd6c77cf647164d0c89f72a8dd2445fa4f8a23d5993017fb
7
+ data.tar.gz: 05601691a8f0b3c5ddd469cd6de3a15a9698827c0fddc8acac2686f58b977f9ee09acffa6f99fe8f2d65aea8cf66af57087729050e3252c695373b6e9b894ade
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.16.0
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in virtual_time_zone_rails.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Nobuiko Sawai
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # VirtualTimeZoneRails
2
+
3
+ Updates the original behaviour of ActiveSupport::TimeZone
4
+ to ignore daylight savings and keep consistent offset
5
+ when initialized with Numeric or ActiveSupport::Duration.
6
+
7
+ (Similar behaviour to the [Swift3 TimeZone](https://developer.apple.com/documentation/foundation/timezone/2293718-init#discussion))
8
+
9
+ ```ruby
10
+ zone = ActiveSupport::TimeZone.new(-28800)
11
+ time = zone.parse('2017-08-01') # => Tue, 01 Aug 2017 00:00:00 VirtualTimeZone -08:00
12
+ time.utc_offset # => -28800
13
+ ```
14
+
15
+ The original behaviour was like this.
16
+ ```ruby
17
+ zone = ActiveSupport::TimeZone.new(-28800)
18
+ time = zone.parse('2017-08-01') # => Tue, 01 Aug 2017 00:00:00 PDT -07:00
19
+ time.utc_offset # => -25200, not -28800
20
+ ```
21
+
22
+ This gem does not change the behaviour if the _real_ time zone is given.
23
+
24
+ ```ruby
25
+ zone = ActiveSupport::TimeZone.new("America/New_York")
26
+ zone.parse('2017-08-01') # => Tue, 01 Aug 2017 00:00:00 EDT -04:00
27
+ time.utc_offset # => -14400
28
+ ```
29
+
30
+ ## Installation
31
+
32
+ Add this line to your application's Gemfile:
33
+
34
+ ```ruby
35
+ gem 'virtual_time_zone_rails'
36
+ ```
37
+
38
+ And then execute:
39
+
40
+ $ bundle
41
+
42
+ Or install it yourself as:
43
+
44
+ $ gem install virtual_time_zone_rails
45
+
46
+ ## Usage
47
+
48
+ Just include to the Gemfile of your rails project.
49
+
50
+ ## Development
51
+
52
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
53
+
54
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
55
+
56
+ ## Contributing
57
+
58
+ Bug reports and pull requests are welcome on GitHub at https://github.com/nobuhikosawai/virtual_time_zone_rails.
59
+
60
+ ## License
61
+
62
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ task default: :test
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.libs << 'test'
8
+ t.pattern = 'test/**/*_test.rb'
9
+ t.warning = true
10
+ t.verbose = true
11
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "virtual_time_zone_rails"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,30 @@
1
+ module TZInfo
2
+ class VirtualTimezone < Timezone
3
+ def self.new(seconds_from_gmt)
4
+ vt = super()
5
+ vt.send(:setup, seconds_from_gmt)
6
+ vt
7
+ end
8
+
9
+ # Returns the TimezonePeriod based on the given seconds from GMT.
10
+ def period_for_utc(_utc)
11
+ TimezonePeriod.new(nil, nil, @offset)
12
+ end
13
+
14
+ # Returns the array of TimezonePeriod based on the given seconds from GMT.
15
+ def periods_for_local(_local)
16
+ [TimezonePeriod.new(nil, nil, @offset)]
17
+ end
18
+
19
+ def identifier
20
+ "secondsFromGMT##{@seconds_from_gmt}"
21
+ end
22
+
23
+ private
24
+
25
+ def setup(seconds_from_gmt)
26
+ @seconds_from_gmt = seconds_from_gmt
27
+ @offset = TimezoneOffset.new(@seconds_from_gmt, 0, :VirtualTimeZone)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ module VirtualTimeZoneRails
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,17 @@
1
+ require 'tzinfo/virtual_timezone'
2
+ require 'active_support/values/time_zone'
3
+
4
+ ActiveSupport::TimeZone.class_eval do
5
+ class << self
6
+ alias_method :square_brackets, :[]
7
+ def [](arg)
8
+ case arg
9
+ when Numeric, ActiveSupport::Duration
10
+ tzinfo = TZInfo::VirtualTimezone.new(arg)
11
+ @lazy_zones_map[arg] ||= create(tzinfo.name, nil, tzinfo)
12
+ else
13
+ square_brackets(arg)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,29 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "virtual_time_zone_rails/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "virtual_time_zone_rails"
8
+ spec.version = VirtualTimeZoneRails::VERSION
9
+ spec.authors = ["Nobuiko Sawai"]
10
+ spec.email = ["nobuhiko.sawai@gmail.com"]
11
+
12
+ spec.summary = %q{Virtual TimeZone}
13
+ spec.description = %q{Virtual TimeZone}
14
+ spec.homepage = "http://github.com/nobuhikosawai/virtual_time_zone_rails"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_dependency "activesupport", "~> 5.0"
25
+ spec.add_dependency "tzinfo", "~> 1.1"
26
+ spec.add_development_dependency "bundler", "~> 1.16"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "minitest", "~>5.1"
29
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: virtual_time_zone_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nobuiko Sawai
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-01-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: tzinfo
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.1'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.1'
83
+ description: Virtual TimeZone
84
+ email:
85
+ - nobuhiko.sawai@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - bin/console
97
+ - bin/setup
98
+ - lib/tzinfo/virtual_timezone.rb
99
+ - lib/virtual_time_zone_rails.rb
100
+ - lib/virtual_time_zone_rails/version.rb
101
+ - virtual_time_zone_rails.gemspec
102
+ homepage: http://github.com/nobuhikosawai/virtual_time_zone_rails
103
+ licenses:
104
+ - MIT
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.6.13
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Virtual TimeZone
126
+ test_files: []