teasy 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 54fb405363968ca96e3690d23559425f212a96f5
4
- data.tar.gz: 65ab60376126736884d7a5b4faf3b4fe6e194736
3
+ metadata.gz: 7820bcbbcabd1d9cc89bed4ebc39fc66eda119ab
4
+ data.tar.gz: 0715b6bd76569238bc2355bb63496ebc362b9277
5
5
  SHA512:
6
- metadata.gz: 1dcaa1eb6b607f0061f570c84b8a0de4d4f081fa86f313d953617556749dba4966638341255d3135d132a7c7c5423258dc0567b2a27b78f637a84d3ff742204e
7
- data.tar.gz: 0b432bb95e49c19ace3c6d0f751908be1a930de43e9e266de8b1fc78c61b58451e4d7f3aa6ff0c94f0a069154281e9a42b510b07eb4ddc809c3239ca78699062
6
+ metadata.gz: 94b62ccd762b61290759c432cea9ef5eee1eb10e4fef424e7871971884cf530f311558d89dfb196eb5d55d11d519a01bf2b5c971310f6a345fe320143c316d44
7
+ data.tar.gz: 03cc1ae67cbec69b7ef808e5279ac396e828d0ca0defab607431154bb1c5688df6ba91e55e7f9110a85c0eadf2cbf92061c78391649ab6889aa9d4302c2717c7
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.2
@@ -35,6 +35,18 @@ module Teasy
35
35
  from_time(utc_time, 'UTC').in_time_zone!(zone)
36
36
  end
37
37
 
38
+ def self.parse(string, zone = Teasy.default_zone)
39
+ from_utc(Time.parse(string).utc, zone)
40
+ end
41
+
42
+ def self.iso8601(string, zone = Teasy.default_zone)
43
+ from_utc(Time.iso8601(string).utc, zone)
44
+ end
45
+
46
+ def self.strptime(string, format, zone = Teasy.default_zone)
47
+ new(*DateTime._strptime(string, format).values, 'UTC').in_time_zone!(zone)
48
+ end
49
+
38
50
  def in_time_zone!(zone = Teasy.default_zone)
39
51
  time = utc_time
40
52
  @zone = TZInfo::Timezone.get(zone)
@@ -57,7 +69,7 @@ module Teasy
57
69
  end
58
70
 
59
71
  def utc!
60
- @time = @zone.local_to_utc(@time)
72
+ @time = @zone.local_to_utc(@time, @period.dst?)
61
73
  @zone = TZInfo::Timezone.get('UTC')
62
74
  @period = @zone.period_for_local(@time)
63
75
  self
data/lib/teasy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Teasy
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
data/teasy.gemspec CHANGED
@@ -1,5 +1,5 @@
1
1
  # coding: utf-8
2
- require_relative 'lib/teasy/version'
2
+ require File.expand_path("../lib/teasy/version", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = 'teasy'
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
21
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
22
22
  spec.require_paths = ['lib']
23
+ spec.required_ruby_version = '> 2.0'
23
24
 
24
25
  spec.add_runtime_dependency 'tzinfo', '~> 1.2'
25
26
  spec.add_runtime_dependency 'tzinfo-data', '~> 1.2015.1'
@@ -69,6 +69,13 @@ class TimeWithZoneTest < Minitest::Test
69
69
  refute_equal time.object_id, @timestamptz.in_time_zone('Asia/Calcutta')
70
70
  end
71
71
 
72
+ def test_in_time_zone_at_dst_start
73
+ dst_start = Teasy::TimeWithZone.new(2014, 3, 30, 1)
74
+ .in_time_zone!('Europe/Berlin')
75
+ assert_equal 3, dst_start.hour
76
+ assert dst_start.dst?
77
+ end
78
+
72
79
  def test_raises_on_ambiguous_time
73
80
  dst_end = [2014, 10, 26, 2, 0, 0, 0, 'Europe/Berlin']
74
81
  assert_raises(TZInfo::AmbiguousTime) do
@@ -382,6 +389,17 @@ class TimeWithZoneTest < Minitest::Test
382
389
  assert_equal 1, @timestamptz_berlin.usec
383
390
  end
384
391
 
392
+ def test_utc_at_dst_end
393
+ first_ambiguous_timestamp = Teasy::TimeWithZone.new(2014, 10, 26)
394
+ .in_time_zone 'Europe/Berlin'
395
+ assert_equal 2, first_ambiguous_timestamp.hour
396
+ assert_equal 0, first_ambiguous_timestamp.utc.hour
397
+ last_ambiguous_timestamp = Teasy::TimeWithZone.new(2014, 10, 26, 1)
398
+ .in_time_zone 'Europe/Berlin'
399
+ assert_equal 2, last_ambiguous_timestamp.hour
400
+ assert_equal 1, last_ambiguous_timestamp.utc.hour
401
+ end
402
+
385
403
  def test_utc
386
404
  assert_instance_of Teasy::TimeWithZone, @timestamptz.utc
387
405
  assert_instance_of Teasy::TimeWithZone, @timestamptz_berlin.utc
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: teasy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kai Kuchenbecker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-24 00:00:00.000000000 Z
11
+ date: 2015-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tzinfo
@@ -121,6 +121,7 @@ extra_rdoc_files: []
121
121
  files:
122
122
  - ".gitignore"
123
123
  - ".rubocop.yml"
124
+ - ".ruby-version"
124
125
  - Gemfile
125
126
  - LICENSE.txt
126
127
  - README.md
@@ -144,9 +145,9 @@ require_paths:
144
145
  - lib
145
146
  required_ruby_version: !ruby/object:Gem::Requirement
146
147
  requirements:
147
- - - ">="
148
+ - - ">"
148
149
  - !ruby/object:Gem::Version
149
- version: '0'
150
+ version: '2.0'
150
151
  required_rubygems_version: !ruby/object:Gem::Requirement
151
152
  requirements:
152
153
  - - ">="