没有任何数据可供显示
开源项目社区 | 当前位置 : |
|
oss.trustie.net/open_source_projects | 主页 > 开源项目社区 > time-comparisons |
time-comparisons
|
0 | 0 | 5 |
贡献者 | 讨论 | 代码提交 |
Time Comparisons Rails pluginProvides for chronological comparisons between Time, Date and DateTime objects using before?, after? same_time?, same_time_or_before?, same_time_or_after?, within?, outside? and compare_time methods.
This provides a more readable alternative the , =, == and methods for time comparison, and allows for comparing a Time with a Date/DateTime (the built-in methods return an ArgumentError in this case.)
Examples:
past = Time.utc(2007, 6, 7, 4, 30, 29)
present = Time.utc(2007, 6, 7, 4, 30, 30)
future = Time.utc(2007, 6, 7, 4, 30, 31)
- => true
- => true
- => true
- => false
- => true
- => false
- => true
- => false
times = [present, future, past, Date.new(1990), DateTime.civil(2012)]
puts times.sort {|a,b| a.compare_time(b)} # =>
1990-01-01
Fri Jun 08 16:30:29 UTC 2007
Fri Jun 08 16:30:30 UTC 2007
Fri Jun 08 16:30:31 UTC 2007
2012-01-01T00:00:00+00:00COMPATIBILITY NOTE: If you're not running Rails 1.2.3 + Ruby 1.8.6 or Edge Rails >= r6335, uncomment the Time#to_datetime method in this plugin's init.rb file for full compatibility.