~ubuntu-branches/ubuntu/hardy/ruby1.8/hardy-updates

« back to all changes in this revision

Viewing changes to lib/parsedate.rb

  • Committer: Bazaar Package Importer
  • Author(s): akira yamada
  • Date: 2007-03-13 22:11:58 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20070313221158-h3oql37brlaf2go2
Tags: 1.8.6-1
* new upstream version, 1.8.6.
* libruby1.8 conflicts with libopenssl-ruby1.8 (< 1.8.6) (closes: #410018)
* changed packaging style to cdbs from dbs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# = parsedate.rb: Parses dates
 
3
#
 
4
# Author:: Tadayoshi Funaba
 
5
# Documentation:: Konrad Meyer
 
6
#
 
7
# ParseDate munches on a date and turns it into an array of values.
 
8
#
 
9
 
 
10
#
 
11
# ParseDate converts a date into an array of values.
 
12
# For example:
 
13
#
 
14
#   require 'parsedate'
 
15
#
 
16
#   ParseDate.parsedate "Tuesday, July 6th, 2007, 18:35:20 UTC"
 
17
#   # => [2007, 7, 6, 18, 35, 20, "UTC", 2]
 
18
#
 
19
# The order is of the form [year, month, day of month, hour, minute, second,
 
20
# timezone, day of the week].
 
21
 
 
22
require 'date/format'
 
23
 
 
24
module ParseDate
 
25
  #
 
26
  # Parse a string representation of a date into values.
 
27
  # For example:
 
28
  #
 
29
  #   require 'parsedate'
 
30
  #
 
31
  #   ParseDate.parsedate "Tuesday, July 5th, 2007, 18:35:20 UTC"
 
32
  #   # => [2007, 7, 5, 18, 35, 20, "UTC", 2]
 
33
  #
 
34
  # The order is of the form [year, month, day of month, hour, minute,
 
35
  # second, timezone, day of week].
 
36
  #
 
37
  # ParseDate.parsedate can also take a second argument, +comp+, which
 
38
  # is a boolean telling the method to compensate for dates with years
 
39
  # expressed as two digits. Example:
 
40
  #
 
41
  #   require 'parsedate'
 
42
  #
 
43
  #   ParseDate.parsedate "Mon Dec 25 00 06:53:24 UTC", true
 
44
  #   # => [2000, 12, 25, 6, 53, 24, "UTC", 1]
 
45
  #
 
46
  def parsedate(str, comp=false)
 
47
    Date._parse(str, comp).
 
48
      values_at(:year, :mon, :mday, :hour, :min, :sec, :zone, :wday)
 
49
  end
 
50
 
 
51
  module_function :parsedate
 
52
 
 
53
end