File: datetime.rb

package info (click to toggle)
libextlib-ruby 0.9.13-2%2Bdeb6u1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze-lts
  • size: 532 kB
  • ctags: 487
  • sloc: ruby: 7,118; makefile: 3
file content (29 lines) | stat: -rw-r--r-- 741 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
require "date"

class DateTime
  ##
  # Convert to Time object (for DateTime/Time conversion protocol).
  #
  #   DateTime.now.to_time    #=> Wed Nov 19 20:04:51 -0800 2008
  #
  # @return [Time] Time object representing the same moment as receiver
  #
  # @api public
  remove_method :to_time if instance_methods(false).any? { |m| m.to_sym == :to_time }
  def to_time
    Time.parse self.to_s
  end

  ##
  # Return receiver (for DateTime/Time conversion protocol).
  #
  #   DateTime.now.to_datetime    #=> #<DateTime: 212093913977/86400,-1/3,2299161>
  #
  # @return [DateTime] Receiver
  #
  # @api public
  remove_method :to_datetime if instance_methods(false).any? { |m| m.to_sym == :to_datetime }
  def to_datetime
    self
  end
end