Permalink
Browse files

First commit.

  • Loading branch information...
0 parents commit 5a37949f28eae03d2243409c2bdfe4054a02c589 Evan Weaver committed Feb 25, 2011
Showing with 69 additions and 0 deletions.
  1. +2 −0 CHANGELOG
  2. +13 −0 LICENSE
  3. +10 −0 Manifest
  4. +8 −0 README
  5. +8 −0 Rakefile
  6. +14 −0 lib/time_constants.rb
  7. +14 −0 test/unit/time_constants_test.rb
2 CHANGELOG
@@ -0,0 +1,2 @@
+
+v0.1. First release.
13 LICENSE
@@ -0,0 +1,13 @@
+TimeConstants is Copyright (C) 2011 Twitter, Inc.
+
+Licensed under the Apache License, Version 2.0 (the "License"); you may not
+use this work except in compliance with the License. You may obtain a copy of
+the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+License for the specific language governing permissions and limitations under
+the License.
10 Manifest
@@ -0,0 +1,10 @@
+CHANGELOG
+ext/ccsv.c
+ext/ccsv.h
+ext/extconf.rb
+LICENSE
+Manifest
+README
+test/data.csv
+test/data_small.csv
+test/unit/test_ccsv.rb
8 README
@@ -0,0 +1,8 @@
+
+TimeConstants
+
+Time constants, in seconds, so you don't have to use slow ActiveSupport helpers.
+
+== License
+
+Copyright 2011 Twitter, Inc. Licensed under the Apache 2 license. See the included LICENSE file.
8 Rakefile
@@ -0,0 +1,8 @@
+require 'echoe'
+
+Echoe.new("time_constants") do |p|
+ p.author = "Evan Weaver"
+ p.project = "twitter"
+ p.summary = "Time constants, in seconds, so you don't have to use slow ActiveSupport helpers."
+end
+
14 lib/time_constants.rb
@@ -0,0 +1,14 @@
+class Time
+ def self.set_time_constant(number, unit, seconds)
+ Object.const_set(constant = "T_#{number}_#{unit}#{number > 1 ? 'S' : ''}", seconds)
+ end
+end
+
+101.times { |i| Time.set_time_constant(i, "SECOND", i) }
+101.times { |i| Time.set_time_constant(i, "MINUTE", i * T_60_SECONDS) }
+101.times { |i| Time.set_time_constant(i, "HOUR", i * T_60_MINUTES) }
+501.times { |i| Time.set_time_constant(i, "DAY", i * T_24_HOURS) }
+101.times { |i| Time.set_time_constant(i, "WEEK", i * T_7_DAYS) }
+101.times { |i| Time.set_time_constant(i, "MONTH", i * T_30_DAYS) }
+101.times { |i| Time.set_time_constant(i, "YEAR", i * (T_365_DAYS + T_6_HOURS)) }
+101.times { |i| Time.set_time_constant(i, "SOLAR_YEAR", i * 31558150) }
14 test/unit/time_constants_test.rb
@@ -0,0 +1,14 @@
+
+require 'test/unit'
+require 'time_constants'
+require 'rubygems'
+require 'activesupport'
+
+class TestTimeConstants < Test::Unit::TestCase
+ def test_accuracy
+ assert_equal 1.hour.to_i, T_1_HOUR
+ assert_equal 3.days.to_i, T_3_DAYS
+ assert_equal 2.months.to_i, T_2_MONTHS
+ assert_equal 20.years.to_i, T_20_YEARS
+ end
+end

0 comments on commit 5a37949

Please sign in to comment.