source: extensions/gsdl-video/trunk/installed/cmdline/lib/ruby/1.8/parsedate.rb@ 18425

Last change on this file since 18425 was 18425, checked in by davidb, 15 years ago

Video extension to Greenstone

File size: 1.3 KB
Line 
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
22require 'date/format'
23
24module 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
53end
Note: See TracBrowser for help on using the repository browser.