Skip to content
This repository has been archived by the owner on Sep 18, 2021. It is now read-only.

Commit

Permalink
First commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan Weaver committed Feb 25, 2011
0 parents commit 5a37949
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
@@ -0,0 +1,2 @@

v0.1. First release.
13 changes: 13 additions & 0 deletions 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 changes: 10 additions & 0 deletions 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 changes: 8 additions & 0 deletions 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 changes: 8 additions & 0 deletions 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 changes: 14 additions & 0 deletions 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 changes: 14 additions & 0 deletions 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.