Skip to content

Commit

Permalink
Merge pull request #44 from basecamp/better-tz-parsing
Browse files Browse the repository at this point in the history
Improve time zone parsing
  • Loading branch information
javan committed Aug 30, 2015
2 parents cf0ce2f + 821ab7d commit 6e74840
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 26 deletions.
36 changes: 19 additions & 17 deletions .blade.yml
@@ -1,27 +1,29 @@
framework: qunit

load_paths:
- app/assets/javascripts
- test/javascripts/src
- test/javascripts/vendor
- test/javascripts/fixtures


logical_paths:
- local_time.js
- test.js

ci:
plugins:
sauce_labs:
browsers:
- name: "Google Chrome"
platforms: ["Mac", "Windows"]
- name: "Safari"
platforms: ["Mac"]
- name: "Firefox"
platforms: ["Mac", "Windows"]
- name: "Internet Explorer"
platforms: ["Windows"]
test_config:
time_zone: "Central"
plugins:
sauce_labs:
test_config:
time_zone: Central
browsers:
chrome:
version: -2
os: Mac, Windows, Linux
firefox:
version: -2
os: Mac, Windows, Linux
safari:
version: -2
ie:
version: -3
iphone:
version: -2
android:
version: -2
6 changes: 0 additions & 6 deletions Gemfile
@@ -1,8 +1,2 @@
source 'https://rubygems.org'
gemspec

group :development do
gem 'blade_runner', github: 'javan/blade_runner'
gem 'blade_runner-qunit_adapter', github: 'javan/blade_runner-qunit_adapter'
gem 'blade_runner-sauce_labs_plugin', github: 'javan/blade_runner-sauce_labs_plugin'
end
12 changes: 11 additions & 1 deletion app/assets/javascripts/local_time.js.coffee
Expand Up @@ -22,11 +22,21 @@ months = "January February March April May June July August September October
pad = (num) -> ('0' + num).slice -2

parseTimeZone = (time) ->
if name = time.toString().match(/\(([\w\s]+)\)$/)?[1]
string = time.toString()
# Sun Aug 30 2015 10:22:57 GMT-0400 (NAME)
if name = string.match(/\(([\w\s]+)\)$/)?[1]
if /\s/.test(name)
# Sun Aug 30 2015 10:22:57 GMT-0400 (Eastern Daylight Time)
name.match(/\b(\w)/g).join("")
else
# Sun Aug 30 2015 10:22:57 GMT-0400 (EDT)
name
# Sun Aug 30 10:22:57 EDT 2015
else if name = string.match(/(\w{3,4})\s\d{4}$/)?[1]
name
# "Sun Aug 30 10:22:57 UTC-0400 2015"
else if name = string.match(/(UTC[\+\-]\d+)/)?[1]
name
else
""

Expand Down
2 changes: 1 addition & 1 deletion bin/blade
Expand Up @@ -13,4 +13,4 @@ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
require 'rubygems'
require 'bundler/setup'

load Gem.bin_path('blade_runner', 'blade')
load Gem.bin_path('blade', 'blade')
2 changes: 2 additions & 0 deletions local_time.gemspec
Expand Up @@ -13,4 +13,6 @@ Gem::Specification.new do |s|

s.add_development_dependency "rails"
s.add_development_dependency "rails-dom-testing"
s.add_development_dependency "blade", "~> 0.3.0"
s.add_development_dependency "blade-sauce_labs_plugin", "~> 0.3.0"
end
2 changes: 1 addition & 1 deletion test/javascripts/src/strftime_test.js.coffee
Expand Up @@ -44,4 +44,4 @@ for day in [0..30] by 6
run()

text = getText el
ok /^\w{3,4}$/.test(text), "#{text} doesn't look like a timezone"
ok /^(\w{3,4}|UTC[\+\-]\d+)$/.test(text), "'#{text}' doesn't look like a timezone. System date: '#{new Date}'"

0 comments on commit 6e74840

Please sign in to comment.