ActiveSupport Time拡張

- [Time](http://api.rubyonrails.org/classes/Time.html)

## all\_〜

- Rangeオブジェクトを返す

```rb
Time.now
 # => 2013-01-23 19:41:24 +0900
```

```rb
Time.now.all_day
 # => 2013-01-23 00:00:00 +0900..2013-01-23 23:59:59 +0900
```

```rb
Time.now.all_week
 # => 2013-01-21 00:00:00 +0900..2013-01-27 23:59:59 +0900
```

```rb
Time.now.all_month
 # => 2013-01-01 00:00:00 +0900..2013-01-31 23:59:59 +0900
```

```rb
Time.now.all_quarter
 # => 2013-01-01 00:00:00 +0900..2013-03-31 23:59:59 +0900
```

```rb
Time.now.all_year
 # => 2013-01-01 00:00:00 +0900..2013-12-31 23:59:59 +0900
```

## 〜\_ago

- 指定された過去の日時を返す

```rb
Time.now
 # => 2013-01-23 19:45:18 +0900
```

```rb
Time.now.weeks_ago(1)
 # => 2013-01-16 19:44:42 +0900
```

```rb
Time.now.months_ago(1)
 # => 2012-12-23 19:46:08 +0900
```

```rb
Time.now.years_ago(1)
 # => 2012-01-23 19:46:16 +0900
```

```rb
Time.now.ago(1.week)
 # => 2013-01-16 19:46:57 +0900
```

## 〜\_since

- 指定された未来の日時を返す

```rb
Time.now
 # => 2013-01-23 19:47:54 +0900
```

```rb
Time.now.months_since(1)
 # => 2013-02-23 19:48:19 +0900
```

```rb
Time.now.years_since(1)
 # => 2014-01-23 19:48:42 +0900
```

```rb
Time.now.since(1.month)
 # => 2013-02-23 19:49:08 +0900
```

## beginning\_of\_〜

- 指定された日時の始めの日時を返す

```rb
Time.now
 # => 2013-01-23 19:53:31 +0900
```

```rb
Time.now.beginning_of_hour
 # => 2013-01-23 19:00:00 +0900
```

```rb
Time.now.beginning_of_day
 # => 2013-01-23 00:00:00 +0900
```

```rb
Time.now.beginning_of_week
 # => 2013-01-21 00:00:00 +0900
```

```rb
Time.now.beginning_of_month
 # => 2013-01-01 00:00:00 +0900
```

```rb
Time.now.beginning_of_quarter
 # => 2013-01-01 00:00:00 +0900
```

```rb
Time.now.beginning_of_year
 # => 2013-01-01 00:00:00 +0900
```

## end\_of\_〜

- 指定された日時の終わりの日時を返す

```rb
Time.now
 # => 2013-01-01 00:00:00 +0900
```

```rb
Time.now.end_of_hour
 # => 2013-01-23 19:59:59 +0900
```

```rb
Time.now.end_of_day
 # => 2013-01-23 19:56:25 +0900
```

```rb
Time.now.end_of_week
 # => 2013-01-27 23:59:59 +0900
```

```rb
Time.now.end_of_month
 # => 2013-01-31 23:59:59 +0900
```

```rb
Time.now.end_of_quarter
 # => 2013-03-31 23:59:59 +0900
```

```rb
Time.now.end_of_year
 # => 2013-12-31 23:59:59 +0900
```

## next\_〜

- 指定された日時の次の日時を返す

```rb
Time.now
 # => 2013-01-23 20:00:30 +0900
```

```rb
Time.now.next_week
 # => 2013-01-28 00:00:00 +0900
```

```rb
Time.now.next_month
 # => 2013-02-23 20:00:45 +0900
```

```rb
Time.now.next_year
 # => 2014-01-23 20:00:53 +0900
```

## prev\_〜

- 指定された日時の前の日時を返す

```rb
Time.now
 # => 2013-01-23 20:02:05 +0900
```

```rb
Time.now.prev_week
 # => 2013-01-14 00:00:00 +0900
```

```rb
Time.now.prev_month
 # => 2012-12-23 20:02:59 +0900
```

```rb
Time.now.prev_year
 # => 2012-01-23 20:03:05 +0900
```

## その他

- 過去判定

```rb
Time.now.past?
 # => true
```

```rb
Time.now.since(1.day).past?
 # => false
```

```rb
Time.now.ago(1.day).past?
 # => true
```

- 今日判定

```rb
Time.now.today?
 # => true
```

```rb
Time.now.ago(1.day).today?
 # => false
```

```rb
Time.now.since(1.day).today?
 # => false
```

- 月の日数を返す

[days_in_month](http://api.rubyonrails.org/classes/Time.html#method-c-days_in_month)

```rb
Time.days_in_month( 2, 2012 )
 # => 29
```

```rb
Time.days_in_month( 2, 2013 )
 # => 28
```

※yearは省略可能

```rb
Time.days_in_month( 2 )
 # => 28
```