All Projects → molybdenum-99 → Tz_offset

molybdenum-99 / Tz_offset

Simple abstraction of a timezone offset

Programming Languages

ruby
36898 projects - #4 most used programming language

Labels

Projects that are alternatives of or similar to Tz offset

simple-location
Adds Basic Location Support to Wordpress
Stars: ✭ 26 (-25.71%)
Mutual labels:  timezone
Zonebie
Zonebie prevents bugs in code that deals with timezones by randomly assigning a zone on every run
Stars: ✭ 382 (+991.43%)
Mutual labels:  timezone
Swiftdate
🐔 Toolkit to parse, validate, manipulate, compare and display dates, time & timezones in Swift.
Stars: ✭ 6,661 (+18931.43%)
Mutual labels:  timezone
gwt-time
Backport of functionality based on JSR-310 to GWT. This is NOT an implementation of JSR-310.
Stars: ✭ 17 (-51.43%)
Mutual labels:  timezone
Spacetime
A lightweight javascript timezone library
Stars: ✭ 3,463 (+9794.29%)
Mutual labels:  timezone
Dateutils
nifty command line date and time utilities; fast date calculations and conversion in the shell
Stars: ✭ 458 (+1208.57%)
Mutual labels:  timezone
intl-format
A wrapper library for PHP to format and internationalize values in messages like sprintf
Stars: ✭ 12 (-65.71%)
Mutual labels:  timezone
Time Zone Proposal
A proposal for accurately computing local time in JavaScript
Stars: ✭ 25 (-28.57%)
Mutual labels:  timezone
Googleapi
C# .NET Core Google Api (Maps, Places, Roads, Search, Translate). Supports all endpoints and requests / responses.
Stars: ✭ 346 (+888.57%)
Mutual labels:  timezone
Geolocator
A utility for getting geo-location information via HTML5 and IP look-ups, geocoding, address look-ups, distance and durations, timezone information and more...
Stars: ✭ 598 (+1608.57%)
Mutual labels:  timezone
tz
🌐 A time zone helper
Stars: ✭ 528 (+1408.57%)
Mutual labels:  timezone
Time4j
Advanced date, time and interval library for Java with sun/moon-astronomy and calendars like Chinese, Coptic, Ethiopian, French Republican, Hebrew, Hijri, Historic Christian, Indian National, Japanese, Julian, Korean, Minguo, Persian, Thai, Vietnamese
Stars: ✭ 328 (+837.14%)
Mutual labels:  timezone
Timezone Boundary Builder
A tool to extract data from Open Street Map (OSM) to build the boundaries of the world's timezones.
Stars: ✭ 469 (+1240%)
Mutual labels:  timezone
nepali-datetime
Python's core datetime inspired nepali datetime (BS date & NPT) package 🇳🇵
Stars: ✭ 36 (+2.86%)
Mutual labels:  timezone
Windows Iana
A small tool to convert Windows time zones to IANA
Stars: ✭ 17 (-51.43%)
Mutual labels:  timezone
ng2-timezone-selector
A simple Angular module to create a timezone selector using moment-timezone.
Stars: ✭ 12 (-65.71%)
Mutual labels:  timezone
Date Fns Tz
Complementary library for date-fns v2 adding IANA time zone support
Stars: ✭ 385 (+1000%)
Mutual labels:  timezone
Event Bot
📣 Discord Bot to make announcements about upcoming sessions for the Fellows using Google Calendar and Calendly
Stars: ✭ 21 (-40%)
Mutual labels:  timezone
Paper Timezone
Polymer based timezone selection component
Stars: ✭ 19 (-45.71%)
Mutual labels:  timezone
Valheim Docker
Valheim Docker powered by Odin. The Valheim dedicated gameserver manager which is designed with resiliency in mind by providing automatic updates, world backup support, and a user friendly cli interface.
Stars: ✭ 525 (+1400%)
Mutual labels:  timezone

TZOffset

Gem Version Dependency Status Build Status

Ever tried to convert your distant friend's or colleague's phrase "OK, let's connect tomorrow at 6 pm my time (GMT+8)" into easily calculatable Ruby code? E.g. what time it would be in your timezone at 18:00 GMT+8? What is your favorite solution? Now it should be that:

TZOffset.parse('GMT+8').local(2016, 10, 20, 18).localtime
# => 2016-10-20 13:00:00 +0300

# or just
TZOffset.parse('+8').local(2016, 10, 20, 18).localtime
# => 2016-10-20 13:00:00 +0300

# Also works with most common timezone abbreviations
TZOffset.parse('CEST').local(2016, 10, 20, 18).localtime
# => 2016-10-20 19:00:00 +0300

In other words, TZOffset is simple, no-magic, incapsulated abstraction of "time offset".

Features and problems

  • Easy-to-use, intuitive, dead simple, OS independent;
  • No brains included: no huge and comprehensive database of historical times, no automatic DST conversion; you just know offset you need, and have it as a near-to-mathematical value;
  • Simple value objects, easily converted to/from YAML (so you can save them to databases, pass to delayed jobs and so on);
  • Knows about all common timezone abbreviations (got them from Wikipedia list);
  • For ambiguous abbreviations, just returns list of all of them:
TZOffset.parse('EET')
# => #<TZOffset +02:00 (EET)>
TZOffset.parse('CDT')
# => [#<TZOffset -05:00 (CDT)>, #<TZOffset -04:00 (CDT)>]
  • For symbolic timezones, provides a description, if available:
TZOffset.parse('CDT').map(&:description)
# => ["Central Daylight Time (North America)", "Cuba Daylight Time"]
TZOffset.parse('CDT').map(&:region)
# => ["Central", "Cuba"]

# NB: Just "Central", "Eastern" and so on is related to North America in timezones nomenclature
  • for DST and non-DST timezones provides dst-flag and counterpart timezone, if available:
eet = TZOffset.parse('EET')
# => #<TZOffset +02:00 (EET)>
eet.dst?
# => false
eet.opposite
# => #<TZOffset +03:00 (EEST)>
[eet.description, eet.opposite.description]
# => ["Eastern European Time", "Eastern European Summer Time"]

Installation

Do your usual routine with gem named tz_offset (e.g. gem install tz_offset or add gem "tz_offset to your Gemfile).

Usage

Most of it is already shown above!

require 'tz_offset'

off = TZOffset.parse('-02:30')
# => #<TZOffset -02:30>
off.now
# => 2016-10-25 16:07:55 -0230
off.local(2016, 10, 1)
# => 2016-10-01 00:00:00 -0230

eet = TZOffset.parse('EET')
# => #<TZOffset +02:00 (EET)>
eet.now
# => 2016-10-25 20:29:03 +0200
eet.description
# => "Eastern European Time"
eet.region
# => "Eastern European"
eet.opposite
# => #<TZOffset +03:00 (EEST)>
eet.opposite.now
# => 2016-10-25 21:39:26 +0300

# Parsing time string into desired timezone
off = TZOffset.parse('-02:30')
off.parse('2014-10-01 12:30')
# => 2014-10-01 12:30:00 -0230
off.parse('12:30')
# => 2016-10-26 12:30:00 -0230

Author

Victor Shepelev -- extracted from reality project.

License

MIT.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].