Skip to content
Browse files

Initial code dump

  • Loading branch information...
0 parents commit 3c7d6902e4f06dcbe6bdf76a72018cb2c2a00b9b @farski committed
9 TODO
@@ -0,0 +1,9 @@
+[ ] It doesn't seem like there's a TZ setup in Rails for Hawaiian-Aleutian time, but I could be wrong
+[ ] The following prefixes all have disparate children, and need to be further defined
+ 32, 340, 37, 38
+ 40, 41, 42, 46, 47, 48, 49
+ 57, 58
+ 66, 67, 68, 69
+ 85, 86
+ 962, 963, 964, 965, 966, 969, 97
+
14 lib/tzip.rb
@@ -0,0 +1,14 @@
+require 'tzip/base'
+require 'tzip/values/zone_names'
+require 'tzip/values/zonings'
+require 'tzip/values/eastern'
+require 'tzip/values/central'
+require 'tzip/values/mountain'
+require 'tzip/values/arizona'
+require 'tzip/values/pacific'
+require 'tzip/values/alaska'
+require 'tzip/values/hawaii'
+require 'tzip/values/unused'
+require 'tzip/mapping'
+
+ActiveSupport::TimeZone.send(:include, TZip::ClassMethods) if Object.const_defined?("ActiveSupport")
10 lib/tzip/base.rb
@@ -0,0 +1,10 @@
+module TZip
+ module ClassMethods
+ def self.find_by_zipcode(zipcode)
+ [5,4,3,2,1].each do |i|
+ return MAPPING[zipcode.to_s[0,i]] if MAPPING.has_key?(zipcode.to_s[0,i])
+ end
+ return nil
+ end
+ end
+end
8 lib/tzip/mapping.rb
@@ -0,0 +1,8 @@
+module TZip
+ MAPPING = {}
+ ZONINGS.each do |zone, prefixes|
+ prefixes.each do |prefix|
+ MAPPING[prefix] = ((zone == :unused) ? nil : ZONE_NAMES[zone])
+ end
+ end
+end
3 lib/tzip/values/alaska.rb
@@ -0,0 +1,3 @@
+module TZip
+ ZONINGS[:alaska] = %w{995 996 996 998 999}
+end
3 lib/tzip/values/arizona.rb
@@ -0,0 +1,3 @@
+module TZip
+ ZONINGS[:arizona] = %w{0 1 2}
+end
6 lib/tzip/values/central.rb
@@ -0,0 +1,6 @@
+module TZip
+ ZONINGS[:central] = %w{35 36 39}
+ ZONINGS[:central] += %w{50 51 52 53 54 55 56}
+ ZONINGS[:central] += %w{60 61 62 63 64 65}
+ ZONINGS[:central] += %w{7}
+end
6 lib/tzip/values/eastern.rb
@@ -0,0 +1,6 @@
+module TZip
+ ZONINGS[:eastern] = %w{0 1 2}
+ ZONINGS[:eastern] += %w{30 31 33 34 398 399}
+ ZONINGS[:eastern] += %w{43 44 45}
+ ZONINGS[:eastern] += %w{569}
+end
3 lib/tzip/values/hawaii.rb
@@ -0,0 +1,3 @@
+module TZip
+ ZONINGS[:hawaii] = %w{967 968}
+end
5 lib/tzip/values/mountain.rb
@@ -0,0 +1,5 @@
+module TZip
+ ZONINGS[:mountain] = %w{59}
+ ZONINGS[:mountain] += %w{798 799}
+ ZONINGS[:mountain] += %w{80 81 82 83 831 84 87 88}
+end
4 lib/tzip/values/pacific.rb
@@ -0,0 +1,4 @@
+module TZip
+ ZONINGS[:pacific] = %w{835 838 889 89}
+ ZONINGS[:pacific] += %w{90 91 92 93 94 95 960 961 98 990 991 992 993 994}
+end
11 lib/tzip/values/unused.rb
@@ -0,0 +1,11 @@
+module TZip
+ ZONINGS[:unused] = %w{000 002 003 004 099}
+ ZONINGS[:unused] += %w{213 269}
+ ZONINGS[:unused] += %w{343 348 353}
+ ZONINGS[:unused] += %w{419 429}
+ ZONINGS[:unused] += %w{517 518 519 529 533 536 552 568 578 579 589}
+ ZONINGS[:unused] += %w{621 632 642 643 659 663 682 694 695 696 697 698 699}
+ ZONINGS[:unused] += %w{702 709 715 732 742 771}
+ ZONINGS[:unused] += %w{817 818 819 839 848 849 854 858 861 862 866 867 868 869 876 886 887 888 892 896 899}
+ ZONINGS[:unused] += %w{909 929 987}
+end
11 lib/tzip/values/zone_names.rb
@@ -0,0 +1,11 @@
+module TZip
+ ZONE_NAMES = {
+ :hawaii => "Hawaii",
+ :alaska => "Alaska",
+ :pacific => "Pacific Time (US & Canada)",
+ :mountain => "Mountain Time (US & Canada)",
+ :arizona => "Arizona",
+ :central => "Central Time (US & Canada)",
+ :eastern => "Eastern Time (US & Canada)"
+ }
+end
3 lib/tzip/values/zonings.rb
@@ -0,0 +1,3 @@
+module TZip
+ ZONINGS = {}
+end
7 readme.md
@@ -0,0 +1,7 @@
+# TZip #
+
+TZip makes it a little bit easier to set TimeZones in a rails app, since it can figure out the appropriate identifier from a ZIP code.
+
+## Usage ##
+
+ config.time_zone = ActiveSupport::TimeZone.find_by_zipcode('90210')

0 comments on commit 3c7d690

Please sign in to comment.
Something went wrong with that request. Please try again.