Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →
class method
Date.rfc2822
Date.rfc2822(string = 'Mon, 1 Jan -4712 00:00:00 +0000', start = Date::ITALY, limit: 128) → date
ext/date/date_core.c
View on GitHub ↗
static VALUE
date_s_rfc2822(int argc, VALUE *argv, VALUE klass)
{
VALUE str, sg, opt;
rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
switch (argc) {
case 0:
str = rb_str_new2("Mon, 1 Jan -4712 00:00:00 +0000");
case 1:
sg = INT2FIX(DEFAULT_SG);
}
{
int argc2 = 1;
VALUE argv2[2], hash;
argv2[0] = str;
if (!NIL_P(opt)) argv2[argc2++] = opt;
hash = date_s__rfc2822(argc2, argv2, klass);
return d_new_by_frags(klass, hash, sg);
}
}
Returns a new Date object with values parsed from string, which should be a valid RFC 2822 date format:
Example
d = Date.new(2001, 2, 3) s = d.rfc2822 # => "Sat, 3 Feb 2001 00:00:00 +0000" Date.rfc2822(s) # => #<Date: 2001-02-03>
See:
-
Argument start.
-
Argument limit.
Related: Date._rfc2822 (returns a hash).