Skip to content
This repository has been archived by the owner on Apr 4, 2018. It is now read-only.

Commit

Permalink
Use timezone helper from collector gem
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Fliri committed Mar 21, 2013
1 parent 10b60d8 commit 0d63c30
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 56 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -9,7 +9,7 @@ gem "bunny"
gem "gli", "1.6.0"
gem "whenever"
gem "datainsight_logging", '0.0.3'
gem "datainsight_collector", "0.0.10", :require => 'timezone_helper'
gem "datainsight_collector", "0.0.10"
gem "tzinfo", "~> 0.3.37"


Expand Down
15 changes: 6 additions & 9 deletions Gemfile.lock
@@ -1,11 +1,3 @@
PATH
remote: ../datainsight_collector
specs:
datainsight_collector (0.0.10)
bunny
datainsight_logging
gli (= 1.6.0)

GEM
remote: http://rubygems.org/
remote: https://BnrJb6FZyzspBboNJzYZ@gem.fury.io/govuk/
Expand All @@ -27,6 +19,11 @@ GEM
ci_reporter (1.7.1)
builder (>= 2.1.2)
connection_pool (0.9.2)
datainsight_collector (0.0.10)
bunny
datainsight_logging
gli (= 1.6.0)
tzinfo (~> 0.3.37)
datainsight_logging (0.0.3)
logging
diff-lcs (1.1.3)
Expand Down Expand Up @@ -100,7 +97,7 @@ DEPENDENCIES
airbrake (= 3.1.5)
bunny
ci_reporter (= 1.7.1)
datainsight_collector (= 0.0.10)!
datainsight_collector (= 0.0.10)
datainsight_logging (= 0.0.3)
fakeweb
gli (= 1.6.0)
Expand Down
1 change: 1 addition & 0 deletions lib/collector.rb
Expand Up @@ -2,6 +2,7 @@
require 'open-uri'
require 'json'
require 'faraday'
require 'timezone_helper'

module Faraday
module Utils
Expand Down
4 changes: 2 additions & 2 deletions lib/response/daily_response.rb
Expand Up @@ -16,8 +16,8 @@ def create_payload(response)
end_at = (start_at+1)

{
:start_at => start_at.to_local_timezone.strftime,
:end_at => end_at.to_local_timezone.strftime,
:start_at => start_at.with_tz_offset("Europe/London").strftime,
:end_at => end_at.with_tz_offset("Europe/London").strftime,
:value => {
@metric => value,
:site => @site
Expand Down
4 changes: 2 additions & 2 deletions lib/response/extract_weekly_dates.rb
@@ -1,9 +1,9 @@
module ExtractWeeklyDates
def extract_start_at(start_date)
DateTime.parse(start_date).to_local_timezone.strftime
DateTime.parse(start_date).with_tz_offset("Europe/London").strftime
end

def extract_end_at(end_date)
(DateTime.parse(end_date)+1).to_local_timezone.strftime
(DateTime.parse(end_date)+1).with_tz_offset("Europe/London").strftime
end
end
2 changes: 1 addition & 1 deletion lib/response/hourly_response.rb
Expand Up @@ -33,7 +33,7 @@ def create_payload(start_date, end_date, row)
end

def format_datetime(date, hour)
DateTime.new(date.year, date.month, date.day, hour).to_local_timezone.strftime
DateTime.new(date.year, date.month, date.day, hour).with_tz_offset("Europe/London").strftime
end

end
Expand Down
5 changes: 0 additions & 5 deletions lib/response/timezone_helper.rb

This file was deleted.

2 changes: 1 addition & 1 deletion spec/unit/response/daily_response_spec.rb
Expand Up @@ -68,6 +68,6 @@ class StubConfig
@response = DailyResponse.new([response_hash], StubConfig)
message = @response.messages[0]

message[:payload][:start_at].should == "2012-10-17T01:00:00+01:00"
message[:payload][:start_at].should == "2012-10-17T00:00:00+01:00"
end
end
14 changes: 7 additions & 7 deletions spec/unit/response/hourly_response_spec.rb
Expand Up @@ -11,7 +11,7 @@
@response = HourlyResponse.new([response_hash], StubConfig)
message = @response.messages[0]

message[:payload][:start_at].should == "2012-10-17T01:00:00+01:00"
message[:payload][:start_at].should == "2012-10-17T00:00:00+01:00"
end

describe "example from 2012-03-25 when the DST timezone change happens" do
Expand All @@ -25,31 +25,31 @@
message = @response.messages[0]

message[:payload][:start_at].should eql("2012-03-25T00:00:00+00:00")
message[:payload][:end_at].should eql("2012-03-25T02:00:00+01:00")
message[:payload][:end_at].should eql("2012-03-25T01:00:00+01:00")
message[:payload][:value][:dummy].should eql(75)
message[:payload][:value][:site].should eql("govuk")
end

it "should contain the tenth hour" do
message = @response.messages[10]

message[:payload][:start_at].should eql("2012-03-25T11:00:00+01:00")
message[:payload][:end_at].should eql("2012-03-25T12:00:00+01:00")
message[:payload][:start_at].should eql("2012-03-25T10:00:00+01:00")
message[:payload][:end_at].should eql("2012-03-25T11:00:00+01:00")
message[:payload][:value][:dummy].should eql(429)
message[:payload][:value][:site].should eql("govuk")
end

it "should contain the last hour" do
message = @response.messages[23]

message[:payload][:start_at].should eql("2012-03-26T00:00:00+01:00")
message[:payload][:end_at].should eql("2012-03-26T01:00:00+01:00")
message[:payload][:start_at].should eql("2012-03-25T23:00:00+01:00")
message[:payload][:end_at].should eql("2012-03-26T00:00:00+01:00")
message[:payload][:value][:dummy].should eql(0)
message[:payload][:value][:site].should eql("govuk")
end
end

describe "example from 2012-02-14 12:07:00+01:00" do
describe "example from 2012-02-14" do
before(:each) do
response_hash = load_json("hourly_unique_visitors_response.json")
@response = HourlyResponse.new([response_hash], DummyConfig)
Expand Down
26 changes: 0 additions & 26 deletions spec/unit/response/timezone_helper_spec.rb

This file was deleted.

4 changes: 2 additions & 2 deletions spec/unit/response/weekly_response_spec.rb
Expand Up @@ -10,7 +10,7 @@
@response = WeeklyResponse.new([response_hash], StubConfig)
message = @response.messages[0]

message[:payload][:start_at].should == "2012-10-17T01:00:00+01:00"
message[:payload][:start_at].should == "2012-10-17T00:00:00+01:00"
end

describe "example when the DST timezone change happens" do
Expand All @@ -23,7 +23,7 @@
message = response.messages.first

message[:payload][:start_at].should eql("2012-03-25T00:00:00+00:00")
message[:payload][:end_at].should eql("2012-04-01T01:00:00+01:00")
message[:payload][:end_at].should eql("2012-04-01T00:00:00+01:00")
end
end

Expand Down

0 comments on commit 0d63c30

Please sign in to comment.