Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/appfolio/dynamic_time_zone
Dynamically set the offset from UTC from timezone identifier
https://github.com/appfolio/dynamic_time_zone
Last synced: about 2 months ago
JSON representation
Dynamically set the offset from UTC from timezone identifier
- Host: GitHub
- URL: https://github.com/appfolio/dynamic_time_zone
- Owner: appfolio
- Created: 2020-07-31T00:40:09.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-09-10T11:55:07.000Z (over 2 years ago)
- Last Synced: 2024-04-25T17:43:39.811Z (8 months ago)
- Language: Ruby
- Size: 32.2 KB
- Stars: 0
- Watchers: 62
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# DynamicTimeZone
Create a time zone that contains any offset from UTC. This gem assumes you use ActiveSupport
## Usage
Add this to your Gemfile
```
gem 'dynamic_time_zone'
```Enable the dynamic time zone
```
DynamicTimeZone.enabled = true
```Setup the time zone source
```
TZInfo::DataSource.set(DynamicTimeZone::TimeZoneDataSource.new)
```Use dynamic time zone
```
Time.zone = 'DynamicTimeZone/+360000' # 100 hours ahead of UTC
Time.zone = 'DynamicTimeZone/-360000' # 100 hours behind UTC
```To validate time zone string to match this format
```
DynamicTimeZone::Validator.new.valid?('DynamicTimeZone/+360000') # valid
DynamicTimeZone::Validator.new.valid?('DynamicTimeZone/360000') # invalid
```## Development
To run test: `bundle exec rspec`
To run test in all appraisals: `bundle exec appraisal install && bundle exec appraisal rspec`