File: C:/Ruby27-x64/share/doc/ruby/html/Date.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>class Date - RDoc Documentation</title>
<script type="text/javascript">
var rdoc_rel_prefix = "./";
var index_rel_prefix = "./";
</script>
<script src="./js/navigation.js" defer></script>
<script src="./js/search.js" defer></script>
<script src="./js/search_index.js" defer></script>
<script src="./js/searcher.js" defer></script>
<script src="./js/darkfish.js" defer></script>
<link href="./css/fonts.css" rel="stylesheet">
<link href="./css/rdoc.css" rel="stylesheet">
<body id="top" role="document" class="class">
<nav role="navigation">
<div id="project-navigation">
<div id="home-section" role="region" title="Quick navigation" class="nav-section">
<h2>
<a href="./index.html" rel="home">Home</a>
</h2>
<div id="table-of-contents-navigation">
<a href="./table_of_contents.html#pages">Pages</a>
<a href="./table_of_contents.html#classes">Classes</a>
<a href="./table_of_contents.html#methods">Methods</a>
</div>
</div>
<div id="search-section" role="search" class="project-section initially-hidden">
<form action="#" method="get" accept-charset="utf-8">
<div id="search-field-wrapper">
<input id="search-field" role="combobox" aria-label="Search"
aria-autocomplete="list" aria-controls="search-results"
type="text" name="search" placeholder="Search" spellcheck="false"
title="Type to search, Up and Down to navigate, Enter to load">
</div>
<ul id="search-results" aria-label="Search Results"
aria-busy="false" aria-expanded="false"
aria-atomic="false" class="initially-hidden"></ul>
</form>
</div>
</div>
<div class="nav-section">
<h3>Table of Contents</h3>
<ul class="link-list" role="directory">
<li><a href="#class-Date-label-Terms+and+Definitions">Terms and Definitions</a>
<li><a href="#class-Date-label-Calendar+Date">Calendar Date</a>
<li><a href="#class-Date-label-Ordinal+Date">Ordinal Date</a>
<li><a href="#class-Date-label-Week+Date">Week Date</a>
<li><a href="#class-Date-label-Julian+Day+Number">Julian Day Number</a>
<li><a href="#class-Date-label-Modified+Julian+Day+Number">Modified Julian Day Number</a>
<li><a href="#class-Date-label-Date">Date</a>
</ul>
</div>
<div id="class-metadata">
<div id="parent-class-section" class="nav-section">
<h3>Parent</h3>
<p class="link"><a href="Object.html">Object</a>
</div>
<div id="includes-section" class="nav-section">
<h3>Included Modules</h3>
<ul class="link-list">
<li><a class="include" href="Comparable.html">Comparable</a>
</ul>
</div>
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
<h3>Methods</h3>
<ul class="link-list" role="directory">
<li ><a href="#method-c-_httpdate">::_httpdate</a>
<li ><a href="#method-c-_iso8601">::_iso8601</a>
<li ><a href="#method-c-_jisx0301">::_jisx0301</a>
<li ><a href="#method-c-_parse">::_parse</a>
<li ><a href="#method-c-_rfc2822">::_rfc2822</a>
<li ><a href="#method-c-_rfc3339">::_rfc3339</a>
<li ><a href="#method-c-_rfc822">::_rfc822</a>
<li ><a href="#method-c-_strptime">::_strptime</a>
<li ><a href="#method-c-_xmlschema">::_xmlschema</a>
<li ><a href="#method-c-civil">::civil</a>
<li ><a href="#method-c-commercial">::commercial</a>
<li ><a href="#method-c-gregorian_leap-3F">::gregorian_leap?</a>
<li ><a href="#method-c-httpdate">::httpdate</a>
<li ><a href="#method-c-iso8601">::iso8601</a>
<li ><a href="#method-c-jd">::jd</a>
<li ><a href="#method-c-jisx0301">::jisx0301</a>
<li ><a href="#method-c-json_create">::json_create</a>
<li ><a href="#method-c-julian_leap-3F">::julian_leap?</a>
<li ><a href="#method-c-leap-3F">::leap?</a>
<li ><a href="#method-c-new">::new</a>
<li ><a href="#method-c-new-21">::new!</a>
<li ><a href="#method-c-nth_kday">::nth_kday</a>
<li ><a href="#method-c-ordinal">::ordinal</a>
<li ><a href="#method-c-parse">::parse</a>
<li ><a href="#method-c-rfc2822">::rfc2822</a>
<li ><a href="#method-c-rfc3339">::rfc3339</a>
<li ><a href="#method-c-rfc822">::rfc822</a>
<li ><a href="#method-c-strptime">::strptime</a>
<li ><a href="#method-c-test_all">::test_all</a>
<li ><a href="#method-c-test_civil">::test_civil</a>
<li ><a href="#method-c-test_commercial">::test_commercial</a>
<li ><a href="#method-c-test_nth_kday">::test_nth_kday</a>
<li ><a href="#method-c-test_ordinal">::test_ordinal</a>
<li ><a href="#method-c-test_unit_conv">::test_unit_conv</a>
<li ><a href="#method-c-test_weeknum">::test_weeknum</a>
<li ><a href="#method-c-today">::today</a>
<li ><a href="#method-c-valid_civil-3F">::valid_civil?</a>
<li ><a href="#method-c-valid_commercial-3F">::valid_commercial?</a>
<li ><a href="#method-c-valid_date-3F">::valid_date?</a>
<li ><a href="#method-c-valid_jd-3F">::valid_jd?</a>
<li ><a href="#method-c-valid_ordinal-3F">::valid_ordinal?</a>
<li ><a href="#method-c-weeknum">::weeknum</a>
<li ><a href="#method-c-xmlschema">::xmlschema</a>
<li ><a href="#method-i-2B">#+</a>
<li ><a href="#method-i-2D">#-</a>
<li ><a href="#method-i-3C-3C">#<<</a>
<li ><a href="#method-i-3C-3D-3E">#<=></a>
<li ><a href="#method-i-3D-3D-3D">#===</a>
<li ><a href="#method-i-3E-3E">#>></a>
<li ><a href="#method-i-ajd">#ajd</a>
<li ><a href="#method-i-amjd">#amjd</a>
<li ><a href="#method-i-as_json">#as_json</a>
<li ><a href="#method-i-asctime">#asctime</a>
<li ><a href="#method-i-ctime">#ctime</a>
<li ><a href="#method-i-cwday">#cwday</a>
<li ><a href="#method-i-cweek">#cweek</a>
<li ><a href="#method-i-cwyear">#cwyear</a>
<li ><a href="#method-i-day">#day</a>
<li ><a href="#method-i-day_fraction">#day_fraction</a>
<li ><a href="#method-i-downto">#downto</a>
<li ><a href="#method-i-england">#england</a>
<li ><a href="#method-i-fill">#fill</a>
<li ><a href="#method-i-friday-3F">#friday?</a>
<li ><a href="#method-i-gregorian">#gregorian</a>
<li ><a href="#method-i-gregorian-3F">#gregorian?</a>
<li ><a href="#method-i-hour">#hour</a>
<li ><a href="#method-i-httpdate">#httpdate</a>
<li ><a href="#method-i-inspect">#inspect</a>
<li ><a href="#method-i-inspect_raw">#inspect_raw</a>
<li ><a href="#method-i-iso8601">#iso8601</a>
<li ><a href="#method-i-italy">#italy</a>
<li ><a href="#method-i-jd">#jd</a>
<li ><a href="#method-i-jisx0301">#jisx0301</a>
<li ><a href="#method-i-julian">#julian</a>
<li ><a href="#method-i-julian-3F">#julian?</a>
<li ><a href="#method-i-ld">#ld</a>
<li ><a href="#method-i-leap-3F">#leap?</a>
<li ><a href="#method-i-marshal_dump_old">#marshal_dump_old</a>
<li ><a href="#method-i-mday">#mday</a>
<li ><a href="#method-i-min">#min</a>
<li ><a href="#method-i-minute">#minute</a>
<li ><a href="#method-i-mjd">#mjd</a>
<li ><a href="#method-i-mon">#mon</a>
<li ><a href="#method-i-monday-3F">#monday?</a>
<li ><a href="#method-i-month">#month</a>
<li ><a href="#method-i-new_start">#new_start</a>
<li ><a href="#method-i-next">#next</a>
<li ><a href="#method-i-next_day">#next_day</a>
<li ><a href="#method-i-next_month">#next_month</a>
<li ><a href="#method-i-next_year">#next_year</a>
<li ><a href="#method-i-nth_kday-3F">#nth_kday?</a>
<li ><a href="#method-i-prev_day">#prev_day</a>
<li ><a href="#method-i-prev_month">#prev_month</a>
<li ><a href="#method-i-prev_year">#prev_year</a>
<li ><a href="#method-i-rfc2822">#rfc2822</a>
<li ><a href="#method-i-rfc3339">#rfc3339</a>
<li ><a href="#method-i-rfc822">#rfc822</a>
<li ><a href="#method-i-saturday-3F">#saturday?</a>
<li ><a href="#method-i-sec">#sec</a>
<li ><a href="#method-i-second">#second</a>
<li ><a href="#method-i-start">#start</a>
<li ><a href="#method-i-step">#step</a>
<li ><a href="#method-i-strftime">#strftime</a>
<li ><a href="#method-i-succ">#succ</a>
<li ><a href="#method-i-sunday-3F">#sunday?</a>
<li ><a href="#method-i-thursday-3F">#thursday?</a>
<li ><a href="#method-i-to_date">#to_date</a>
<li ><a href="#method-i-to_datetime">#to_datetime</a>
<li ><a href="#method-i-to_json">#to_json</a>
<li ><a href="#method-i-to_s">#to_s</a>
<li ><a href="#method-i-to_time">#to_time</a>
<li ><a href="#method-i-tuesday-3F">#tuesday?</a>
<li ><a href="#method-i-upto">#upto</a>
<li ><a href="#method-i-wday">#wday</a>
<li ><a href="#method-i-wednesday-3F">#wednesday?</a>
<li ><a href="#method-i-wnum0">#wnum0</a>
<li ><a href="#method-i-wnum1">#wnum1</a>
<li ><a href="#method-i-xmlschema">#xmlschema</a>
<li ><a href="#method-i-yday">#yday</a>
<li ><a href="#method-i-year">#year</a>
</ul>
</div>
</div>
</nav>
<main role="main" aria-labelledby="class-Date">
<h1 id="class-Date" class="class">
class Date
</h1>
<section class="description">
<p>date and datetime class - Tadayoshi Funaba 1998-2011</p>
<p>'date' provides two classes: <a href="Date.html"><code>Date</code></a> and <a href="DateTime.html"><code>DateTime</code></a>.</p>
<h2 id="class-Date-label-Terms+and+Definitions">Terms and Definitions<span><a href="#class-Date-label-Terms+and+Definitions">¶</a> <a href="#top">↑</a></span></h2>
<p>Some terms and definitions are based on ISO 8601 and JIS X 0301.</p>
<h3 id="class-Date-label-Calendar+Date">Calendar <a href="Date.html"><code>Date</code></a><span><a href="#class-Date-label-Calendar+Date">¶</a> <a href="#top">↑</a></span></h3>
<p>The calendar date is a particular day of a calendar year, identified by its ordinal number within a calendar month within that year.</p>
<p>In those classes, this is so-called “civil”.</p>
<h3 id="class-Date-label-Ordinal+Date">Ordinal <a href="Date.html"><code>Date</code></a><span><a href="#class-Date-label-Ordinal+Date">¶</a> <a href="#top">↑</a></span></h3>
<p>The ordinal date is a particular day of a calendar year identified by its ordinal number within the year.</p>
<p>In those classes, this is so-called “ordinal”.</p>
<h3 id="class-Date-label-Week+Date">Week <a href="Date.html"><code>Date</code></a><span><a href="#class-Date-label-Week+Date">¶</a> <a href="#top">↑</a></span></h3>
<p>The week date is a date identified by calendar week and day numbers.</p>
<p>The calendar week is a seven day period within a calendar year, starting on a Monday and identified by its ordinal number within the year; the first calendar week of the year is the one that includes the first Thursday of that year. In the Gregorian calendar, this is equivalent to the week which includes January 4.</p>
<p>In those classes, this is so-called “commercial”.</p>
<h3 id="class-Date-label-Julian+Day+Number">Julian Day Number<span><a href="#class-Date-label-Julian+Day+Number">¶</a> <a href="#top">↑</a></span></h3>
<p>The Julian day number is in elapsed days since noon (Greenwich Mean <a href="Time.html"><code>Time</code></a>) on January 1, 4713 BCE (in the Julian calendar).</p>
<p>In this document, the astronomical Julian day number is the same as the original Julian day number. And the chronological Julian day number is a variation of the Julian day number. Its days begin at midnight on local time.</p>
<p>In this document, when the term “Julian day number” simply appears, it just refers to “chronological Julian day number”, not the original.</p>
<p>In those classes, those are so-called “ajd” and “jd”.</p>
<h3 id="class-Date-label-Modified+Julian+Day+Number">Modified Julian Day Number<span><a href="#class-Date-label-Modified+Julian+Day+Number">¶</a> <a href="#top">↑</a></span></h3>
<p>The modified Julian day number is in elapsed days since midnight (Coordinated Universal <a href="Time.html"><code>Time</code></a>) on November 17, 1858 CE (in the Gregorian calendar).</p>
<p>In this document, the astronomical modified Julian day number is the same as the original modified Julian day number. And the chronological modified Julian day number is a variation of the modified Julian day number. Its days begin at midnight on local time.</p>
<p>In this document, when the term “modified Julian day number” simply appears, it just refers to “chronological modified Julian day number”, not the original.</p>
<p>In those classes, those are so-called “amjd” and “mjd”.</p>
<h2 id="class-Date-label-Date"><a href="Date.html"><code>Date</code></a><span><a href="#class-Date-label-Date">¶</a> <a href="#top">↑</a></span></h2>
<p>A subclass of <a href="Object.html"><code>Object</code></a> that includes the <a href="Comparable.html"><code>Comparable</code></a> module and easily handles date.</p>
<p>A <a href="Date.html"><code>Date</code></a> object is created with <a href="Date.html#method-c-new"><code>Date::new</code></a>, <a href="Date.html#method-c-jd"><code>Date::jd</code></a>, <a href="Date.html#method-c-ordinal"><code>Date::ordinal</code></a>, <a href="Date.html#method-c-commercial"><code>Date::commercial</code></a>, <a href="Date.html#method-c-parse"><code>Date::parse</code></a>, <a href="Date.html#method-c-strptime"><code>Date::strptime</code></a>, <a href="Date.html#method-c-today"><code>Date::today</code></a>, <a href="Time.html#method-i-to_date"><code>Time#to_date</code></a>, etc.</p>
<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">'date'</span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>)
<span class="ruby-comment">#=> #<Date: 2001-02-03 ...></span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">jd</span>(<span class="ruby-value">2451944</span>)
<span class="ruby-comment">#=> #<Date: 2001-02-03 ...></span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">ordinal</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">34</span>)
<span class="ruby-comment">#=> #<Date: 2001-02-03 ...></span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">commercial</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">5</span>,<span class="ruby-value">6</span>)
<span class="ruby-comment">#=> #<Date: 2001-02-03 ...></span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-string">'2001-02-03'</span>)
<span class="ruby-comment">#=> #<Date: 2001-02-03 ...></span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">strptime</span>(<span class="ruby-string">'03-02-2001'</span>, <span class="ruby-string">'%d-%m-%Y'</span>)
<span class="ruby-comment">#=> #<Date: 2001-02-03 ...></span>
<span class="ruby-constant">Time</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>).<span class="ruby-identifier">to_date</span>
<span class="ruby-comment">#=> #<Date: 2001-02-03 ...></span>
</pre>
<p>All date objects are immutable; hence cannot modify themselves.</p>
<p>The concept of a date object can be represented as a tuple of the day count, the offset and the day of calendar reform.</p>
<p>The day count denotes the absolute position of a temporal dimension. The offset is relative adjustment, which determines decoded local time with the day count. The day of calendar reform denotes the start day of the new style. The old style of the West is the Julian calendar which was adopted by Caesar. The new style is the Gregorian calendar, which is the current civil calendar of many countries.</p>
<p>The day count is virtually the astronomical Julian day number. The offset in this class is usually zero, and cannot be specified directly.</p>
<p>A <a href="Date.html"><code>Date</code></a> object can be created with an optional argument, the day of calendar reform as a Julian day number, which should be 2298874 to 2426355 or negative/positive infinity. The default value is <code>Date::ITALY</code> (2299161=1582-10-15). See also sample/cal.rb.</p>
<pre>$ ruby sample/cal.rb -c it 10 1582
October 1582
S M Tu W Th F S
1 2 3 4 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
$ ruby sample/cal.rb -c gb 9 1752
September 1752
S M Tu W Th F S
1 2 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30</pre>
<p>A <a href="Date.html"><code>Date</code></a> object has various methods. See each reference.</p>
<pre class="ruby"><span class="ruby-identifier">d</span> = <span class="ruby-constant">Date</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-string">'3rd Feb 2001'</span>)
<span class="ruby-comment">#=> #<Date: 2001-02-03 ...></span>
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">year</span> <span class="ruby-comment">#=> 2001</span>
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">mon</span> <span class="ruby-comment">#=> 2</span>
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">mday</span> <span class="ruby-comment">#=> 3</span>
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">wday</span> <span class="ruby-comment">#=> 6</span>
<span class="ruby-identifier">d</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span> <span class="ruby-comment">#=> #<Date: 2001-02-04 ...></span>
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">strftime</span>(<span class="ruby-string">'%a %d %b %Y'</span>) <span class="ruby-comment">#=> "Sun 04 Feb 2001"</span>
</pre>
</section>
<section id="5Buntitled-5D" class="documentation-section">
<section class="constants-list">
<header>
<h3>Constants</h3>
</header>
<dl>
<dt id="ABBR_DAYNAMES">ABBR_DAYNAMES
<dd><p>An array of strings of abbreviated day names in <a href="English.html"><code>English</code></a>. The first is “Sun”.</p>
<dt id="ABBR_MONTHNAMES">ABBR_MONTHNAMES
<dd><p>An array of strings of abbreviated month names in <a href="English.html"><code>English</code></a>. The first element is nil.</p>
<dt id="DAYNAMES">DAYNAMES
<dd><p>An array of strings of the full names of days of the week in <a href="English.html"><code>English</code></a>. The first is “Sunday”.</p>
<dt id="ENGLAND">ENGLAND
<dd><p>The Julian day number of the day of calendar reform for England and her colonies.</p>
<dt id="GREGORIAN">GREGORIAN
<dd><p>The Julian day number of the day of calendar reform for the proleptic Gregorian calendar.</p>
<dt id="ITALY">ITALY
<dd><p>The Julian day number of the day of calendar reform for Italy and some catholic countries.</p>
<dt id="JULIAN">JULIAN
<dd><p>The Julian day number of the day of calendar reform for the proleptic Julian calendar.</p>
<dt id="MONTHNAMES">MONTHNAMES
<dd><p>An array of strings of full month names in <a href="English.html"><code>English</code></a>. The first element is nil.</p>
</dl>
</section>
<section id="public-class-5Buntitled-5D-method-details" class="method-section">
<header>
<h3>Public Class Methods</h3>
</header>
<div id="method-c-_httpdate" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
_httpdate(string, limit: 128) → hash
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns a hash of parsed elements.</p>
<p>Raise an <a href="ArgumentError.html"><code>ArgumentError</code></a> when the string length is longer than <em>limit</em>. You can stop this check by passing `limit: nil`, but note that it may take a long time to parse.</p>
<div class="method-source-code" id="_httpdate-source">
<pre>static VALUE
date_s__httpdate(int argc, VALUE *argv, VALUE klass)
{
VALUE str, opt;
rb_scan_args(argc, argv, "1:", &str, &opt);
check_limit(str, opt);
return date__httpdate(str);
}</pre>
</div>
</div>
</div>
<div id="method-c-_iso8601" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
_iso8601(string, limit: 128) → hash
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns a hash of parsed elements.</p>
<p>Raise an <a href="ArgumentError.html"><code>ArgumentError</code></a> when the string length is longer than <em>limit</em>. You can stop this check by passing `limit: nil`, but note that it may take a long time to parse.</p>
<div class="method-source-code" id="_iso8601-source">
<pre>static VALUE
date_s__iso8601(int argc, VALUE *argv, VALUE klass)
{
VALUE str, opt;
rb_scan_args(argc, argv, "1:", &str, &opt);
check_limit(str, opt);
return date__iso8601(str);
}</pre>
</div>
</div>
</div>
<div id="method-c-_jisx0301" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
_jisx0301(string, limit: 128) → hash
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns a hash of parsed elements.</p>
<p>Raise an <a href="ArgumentError.html"><code>ArgumentError</code></a> when the string length is longer than <em>limit</em>. You can stop this check by passing `limit: nil`, but note that it may take a long time to parse.</p>
<div class="method-source-code" id="_jisx0301-source">
<pre>static VALUE
date_s__jisx0301(int argc, VALUE *argv, VALUE klass)
{
VALUE str, opt;
rb_scan_args(argc, argv, "1:", &str, &opt);
check_limit(str, opt);
return date__jisx0301(str);
}</pre>
</div>
</div>
</div>
<div id="method-c-_parse" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
_parse(string[, comp=true], limit: 128) → hash
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Parses the given representation of date and time, and returns a hash of parsed elements. This method does not function as a validator.</p>
<p>If the optional second argument is true and the detected year is in the range “00” to “99”, considers the year a 2-digit form and makes it full.</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">_parse</span>(<span class="ruby-string">'2001-02-03'</span>) <span class="ruby-comment">#=> {:year=>2001, :mon=>2, :mday=>3}</span>
</pre>
<p>Raise an <a href="ArgumentError.html"><code>ArgumentError</code></a> when the string length is longer than <em>limit</em>. You can stop this check by passing `limit: nil`, but note that it may take a long time to parse.</p>
<div class="method-source-code" id="_parse-source">
<pre>static VALUE
date_s__parse(int argc, VALUE *argv, VALUE klass)
{
return date_s__parse_internal(argc, argv, klass);
}</pre>
</div>
</div>
</div>
<div id="method-c-_rfc2822" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
_rfc2822(string, limit: 128) → hash
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns a hash of parsed elements.</p>
<p>Raise an <a href="ArgumentError.html"><code>ArgumentError</code></a> when the string length is longer than <em>limit</em>. You can stop this check by passing `limit: nil`, but note that it may take a long time to parse.</p>
<div class="method-source-code" id="_rfc2822-source">
<pre>static VALUE
date_s__rfc2822(int argc, VALUE *argv, VALUE klass)
{
VALUE str, opt;
rb_scan_args(argc, argv, "1:", &str, &opt);
check_limit(str, opt);
return date__rfc2822(str);
}</pre>
</div>
</div>
</div>
<div id="method-c-_rfc3339" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
_rfc3339(string, limit: 128) → hash
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns a hash of parsed elements.</p>
<p>Raise an <a href="ArgumentError.html"><code>ArgumentError</code></a> when the string length is longer than <em>limit</em>. You can stop this check by passing `limit: nil`, but note that it may take a long time to parse.</p>
<div class="method-source-code" id="_rfc3339-source">
<pre>static VALUE
date_s__rfc3339(int argc, VALUE *argv, VALUE klass)
{
VALUE str, opt;
rb_scan_args(argc, argv, "1:", &str, &opt);
check_limit(str, opt);
return date__rfc3339(str);
}</pre>
</div>
</div>
</div>
<div id="method-c-_rfc822" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
_rfc822(string, limit: 128) → hash
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns a hash of parsed elements.</p>
<p>Raise an <a href="ArgumentError.html"><code>ArgumentError</code></a> when the string length is longer than <em>limit</em>. You can stop this check by passing `limit: nil`, but note that it may take a long time to parse.</p>
<div class="method-source-code" id="_rfc822-source">
<pre>static VALUE
date_s__rfc2822(int argc, VALUE *argv, VALUE klass)
{
VALUE str, opt;
rb_scan_args(argc, argv, "1:", &str, &opt);
check_limit(str, opt);
return date__rfc2822(str);
}</pre>
</div>
</div>
</div>
<div id="method-c-_strptime" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
_strptime(string[, format='%F']) → hash
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Parses the given representation of date and time with the given template, and returns a hash of parsed elements. _strptime does not support specification of flags and width unlike strftime.</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">_strptime</span>(<span class="ruby-string">'2001-02-03'</span>, <span class="ruby-string">'%Y-%m-%d'</span>)
<span class="ruby-comment">#=> {:year=>2001, :mon=>2, :mday=>3}</span>
</pre>
<p>See also strptime(3) and <a href="Date.html#method-i-strftime"><code>strftime</code></a>.</p>
<div class="method-source-code" id="_strptime-source">
<pre>static VALUE
date_s__strptime(int argc, VALUE *argv, VALUE klass)
{
return date_s__strptime_internal(argc, argv, klass, "%F");
}</pre>
</div>
</div>
</div>
<div id="method-c-_xmlschema" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
_xmlschema(string, limit: 128) → hash
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns a hash of parsed elements.</p>
<p>Raise an <a href="ArgumentError.html"><code>ArgumentError</code></a> when the string length is longer than <em>limit</em>. You can stop this check by passing `limit: nil`, but note that it may take a long time to parse.</p>
<div class="method-source-code" id="_xmlschema-source">
<pre>static VALUE
date_s__xmlschema(int argc, VALUE *argv, VALUE klass)
{
VALUE str, opt;
rb_scan_args(argc, argv, "1:", &str, &opt);
check_limit(str, opt);
return date__xmlschema(str);
}</pre>
</div>
</div>
</div>
<div id="method-c-civil" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
civil([year=-4712[, month=1[, mday=1[, start=Date::ITALY]]]]) → date
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-heading">
<span class="method-callseq">
new([year=-4712[, month=1[, mday=1[, start=Date::ITALY]]]]) → date
</span>
</div>
<div class="method-description">
<p>Creates a date object denoting the given calendar date.</p>
<p>In this class, BCE years are counted astronomically. Thus, the year before the year 1 is the year zero, and the year preceding the year zero is the year -1. The month and the day of month should be a negative or a positive number (as a relative month/day from the end of year/month when negative). They should not be zero.</p>
<p>The last argument should be a Julian day number which denotes the day of calendar reform. <a href="Date.html#ITALY"><code>Date::ITALY</code></a> (2299161=1582-10-15), <a href="Date.html#ENGLAND"><code>Date::ENGLAND</code></a> (2361222=1752-09-14), <a href="Date.html#GREGORIAN"><code>Date::GREGORIAN</code></a> (the proleptic Gregorian calendar) and <a href="Date.html#JULIAN"><code>Date::JULIAN</code></a> (the proleptic Julian calendar) can be specified as a day of calendar reform.</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>) <span class="ruby-comment">#=> #<Date: 2001-01-01 ...></span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>) <span class="ruby-comment">#=> #<Date: 2001-02-03 ...></span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">-1</span>) <span class="ruby-comment">#=> #<Date: 2001-02-28 ...></span>
</pre>
<p>See also <a href="Date.html#method-c-jd"><code>::jd</code></a>.</p>
<div class="method-source-code" id="civil-source">
<pre>static VALUE
date_s_civil(int argc, VALUE *argv, VALUE klass)
{
return date_initialize(argc, argv, d_lite_s_alloc_simple(klass));
}</pre>
</div>
</div>
</div>
<div id="method-c-commercial" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
commercial([cwyear=-4712[, cweek=1[, cwday=1[, start=Date::ITALY]]]]) → date
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Creates a date object denoting the given week date.</p>
<p>The week and the day of week should be a negative or a positive number (as a relative week/day from the end of year/week when negative). They should not be zero.</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">commercial</span>(<span class="ruby-value">2001</span>) <span class="ruby-comment">#=> #<Date: 2001-01-01 ...></span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">commercial</span>(<span class="ruby-value">2002</span>) <span class="ruby-comment">#=> #<Date: 2001-12-31 ...></span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">commercial</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">5</span>,<span class="ruby-value">6</span>) <span class="ruby-comment">#=> #<Date: 2001-02-03 ...></span>
</pre>
<p>See also <a href="Date.html#method-c-jd"><code>::jd</code></a> and <a href="Date.html#method-c-new"><code>::new</code></a>.</p>
<div class="method-source-code" id="commercial-source">
<pre>static VALUE
date_s_commercial(int argc, VALUE *argv, VALUE klass)
{
VALUE vy, vw, vd, vsg, y, fr, fr2, ret;
int w, d;
double sg;
rb_scan_args(argc, argv, "04", &vy, &vw, &vd, &vsg);
y = INT2FIX(-4712);
w = 1;
d = 1;
fr2 = INT2FIX(0);
sg = DEFAULT_SG;
switch (argc) {
case 4:
val2sg(vsg, sg);
case 3:
check_numeric(vd, "cwday");
num2int_with_frac(d, positive_inf);
case 2:
check_numeric(vw, "cweek");
w = NUM2INT(vw);
case 1:
check_numeric(vy, "year");
y = vy;
}
{
VALUE nth;
int ry, rw, rd, rjd, ns;
if (!valid_commercial_p(y, w, d, sg,
&nth, &ry,
&rw, &rd, &rjd,
&ns))
rb_raise(eDateError, "invalid date");
ret = d_simple_new_internal(klass,
nth, rjd,
sg,
0, 0, 0,
HAVE_JD);
}
add_frac();
return ret;
}</pre>
</div>
</div>
</div>
<div id="method-c-gregorian_leap-3F" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
gregorian_leap?(year) → bool
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns true if the given year is a leap year of the proleptic Gregorian calendar.</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">gregorian_leap?</span>(<span class="ruby-value">1900</span>) <span class="ruby-comment">#=> false</span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">gregorian_leap?</span>(<span class="ruby-value">2000</span>) <span class="ruby-comment">#=> true</span>
</pre>
<div class="method-source-code" id="gregorian_leap-3F-source">
<pre>static VALUE
date_s_gregorian_leap_p(VALUE klass, VALUE y)
{
VALUE nth;
int ry;
check_numeric(y, "year");
decode_year(y, -1, &nth, &ry);
return f_boolcast(c_gregorian_leap_p(ry));
}</pre>
</div>
</div>
</div>
<div id="method-c-httpdate" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
httpdate(string='Mon, 01 Jan -4712 00:00:00 GMT'[, start=Date::ITALY], limit: 128) → date
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Creates a new <a href="Date.html"><code>Date</code></a> object by parsing from a string according to some RFC 2616 format.</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">httpdate</span>(<span class="ruby-string">'Sat, 03 Feb 2001 00:00:00 GMT'</span>)
<span class="ruby-comment">#=> #<Date: 2001-02-03 ...></span>
</pre>
<p>Raise an <a href="ArgumentError.html"><code>ArgumentError</code></a> when the string length is longer than <em>limit</em>. You can stop this check by passing `limit: nil`, but note that it may take a long time to parse.</p>
<div class="method-source-code" id="httpdate-source">
<pre>static VALUE
date_s_httpdate(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, 01 Jan -4712 00:00:00 GMT");
case 1:
sg = INT2FIX(DEFAULT_SG);
}
{
int argc2 = 1;
VALUE argv2[2];
argv2[0] = str;
if (!NIL_P(opt)) argv2[argc2++] = opt;
VALUE hash = date_s__httpdate(argc2, argv2, klass);
return d_new_by_frags(klass, hash, sg);
}
}</pre>
</div>
</div>
</div>
<div id="method-c-iso8601" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
iso8601(string='-4712-01-01'[, start=Date::ITALY], limit: 128) → date
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Creates a new <a href="Date.html"><code>Date</code></a> object by parsing from a string according to some typical ISO 8601 formats.</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">iso8601</span>(<span class="ruby-string">'2001-02-03'</span>) <span class="ruby-comment">#=> #<Date: 2001-02-03 ...></span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">iso8601</span>(<span class="ruby-string">'20010203'</span>) <span class="ruby-comment">#=> #<Date: 2001-02-03 ...></span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">iso8601</span>(<span class="ruby-string">'2001-W05-6'</span>) <span class="ruby-comment">#=> #<Date: 2001-02-03 ...></span>
</pre>
<p>Raise an <a href="ArgumentError.html"><code>ArgumentError</code></a> when the string length is longer than <em>limit</em>. You can stop this check by passing `limit: nil`, but note that it may take a long time to parse.</p>
<div class="method-source-code" id="iso8601-source">
<pre>static VALUE
date_s_iso8601(int argc, VALUE *argv, VALUE klass)
{
VALUE str, sg, opt;
rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
if (!NIL_P(opt)) argc--;
switch (argc) {
case 0:
str = rb_str_new2("-4712-01-01");
case 1:
sg = INT2FIX(DEFAULT_SG);
}
{
int argc2 = 1;
VALUE argv2[2];
argv2[0] = str;
if (!NIL_P(opt)) argv2[argc2++] = opt;
VALUE hash = date_s__iso8601(argc2, argv2, klass);
return d_new_by_frags(klass, hash, sg);
}
}</pre>
</div>
</div>
</div>
<div id="method-c-jd" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
jd([jd=0[, start=Date::ITALY]]) → date
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Creates a date object denoting the given chronological Julian day number.</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">jd</span>(<span class="ruby-value">2451944</span>) <span class="ruby-comment">#=> #<Date: 2001-02-03 ...></span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">jd</span>(<span class="ruby-value">2451945</span>) <span class="ruby-comment">#=> #<Date: 2001-02-04 ...></span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">jd</span>(<span class="ruby-value">0</span>) <span class="ruby-comment">#=> #<Date: -4712-01-01 ...></span>
</pre>
<p>See also <a href="Date.html#method-c-new"><code>::new</code></a>.</p>
<div class="method-source-code" id="jd-source">
<pre>static VALUE
date_s_jd(int argc, VALUE *argv, VALUE klass)
{
VALUE vjd, vsg, jd, fr, fr2, ret;
double sg;
rb_scan_args(argc, argv, "02", &vjd, &vsg);
jd = INT2FIX(0);
fr2 = INT2FIX(0);
sg = DEFAULT_SG;
switch (argc) {
case 2:
val2sg(vsg, sg);
case 1:
check_numeric(vjd, "jd");
num2num_with_frac(jd, positive_inf);
}
{
VALUE nth;
int rjd;
decode_jd(jd, &nth, &rjd);
ret = d_simple_new_internal(klass,
nth, rjd,
sg,
0, 0, 0,
HAVE_JD);
}
add_frac();
return ret;
}</pre>
</div>
</div>
</div>
<div id="method-c-jisx0301" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
jisx0301(string='-4712-01-01'[, start=Date::ITALY], limit: 128) → date
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Creates a new <a href="Date.html"><code>Date</code></a> object by parsing from a string according to some typical JIS X 0301 formats.</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">jisx0301</span>(<span class="ruby-string">'H13.02.03'</span>) <span class="ruby-comment">#=> #<Date: 2001-02-03 ...></span>
</pre>
<p>For no-era year, legacy format, Heisei is assumed.</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">jisx0301</span>(<span class="ruby-string">'13.02.03'</span>) <span class="ruby-comment">#=> #<Date: 2001-02-03 ...></span>
</pre>
<p>Raise an <a href="ArgumentError.html"><code>ArgumentError</code></a> when the string length is longer than <em>limit</em>. You can stop this check by passing `limit: nil`, but note that it may take a long time to parse.</p>
<div class="method-source-code" id="jisx0301-source">
<pre>static VALUE
date_s_jisx0301(int argc, VALUE *argv, VALUE klass)
{
VALUE str, sg, opt;
rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
if (!NIL_P(opt)) argc--;
switch (argc) {
case 0:
str = rb_str_new2("-4712-01-01");
case 1:
sg = INT2FIX(DEFAULT_SG);
}
{
int argc2 = 1;
VALUE argv2[2];
argv2[0] = str;
if (!NIL_P(opt)) argv2[argc2++] = opt;
VALUE hash = date_s__jisx0301(argc2, argv2, klass);
return d_new_by_frags(klass, hash, sg);
}
}</pre>
</div>
</div>
</div>
<div id="method-c-json_create" class="method-detail ">
<div class="method-heading">
<span class="method-name">json_create</span><span
class="method-args">(object)</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Deserializes <a href="JSON.html"><code>JSON</code></a> string by converting Julian year <code>y</code>, month <code>m</code>, day <code>d</code> and Day of Calendar Reform <code>sg</code> to <a href="Date.html"><code>Date</code></a>.</p>
<div class="method-source-code" id="json_create-source">
<pre><span class="ruby-comment"># File ext/json/lib/json/add/date.rb, line 11</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">json_create</span>(<span class="ruby-identifier">object</span>)
<span class="ruby-identifier">civil</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">object</span>.<span class="ruby-identifier">values_at</span>(<span class="ruby-string">'y'</span>, <span class="ruby-string">'m'</span>, <span class="ruby-string">'d'</span>, <span class="ruby-string">'sg'</span>))
<span class="ruby-keyword">end</span></pre>
</div>
</div>
</div>
<div id="method-c-julian_leap-3F" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
julian_leap?(year) → bool
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns true if the given year is a leap year of the proleptic Julian calendar.</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">julian_leap?</span>(<span class="ruby-value">1900</span>) <span class="ruby-comment">#=> true</span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">julian_leap?</span>(<span class="ruby-value">1901</span>) <span class="ruby-comment">#=> false</span>
</pre>
<div class="method-source-code" id="julian_leap-3F-source">
<pre>static VALUE
date_s_julian_leap_p(VALUE klass, VALUE y)
{
VALUE nth;
int ry;
check_numeric(y, "year");
decode_year(y, +1, &nth, &ry);
return f_boolcast(c_julian_leap_p(ry));
}</pre>
</div>
</div>
</div>
<div id="method-c-leap-3F" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
leap?(year) → bool
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns true if the given year is a leap year of the proleptic Gregorian calendar.</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">gregorian_leap?</span>(<span class="ruby-value">1900</span>) <span class="ruby-comment">#=> false</span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">gregorian_leap?</span>(<span class="ruby-value">2000</span>) <span class="ruby-comment">#=> true</span>
</pre>
<div class="method-source-code" id="leap-3F-source">
<pre>static VALUE
date_s_gregorian_leap_p(VALUE klass, VALUE y)
{
VALUE nth;
int ry;
check_numeric(y, "year");
decode_year(y, -1, &nth, &ry);
return f_boolcast(c_gregorian_leap_p(ry));
}</pre>
</div>
</div>
</div>
<div id="method-c-new" class="method-detail ">
<div class="method-heading">
<span class="method-name">new</span><span
class="method-args">(p1 = v1, p2 = v2, p3 = v3, p4 = v4)</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<div class="method-source-code" id="new-source">
<pre>static VALUE
date_initialize(int argc, VALUE *argv, VALUE self)
{
VALUE vy, vm, vd, vsg, y, fr, fr2, ret;
int m, d;
double sg;
struct SimpleDateData *dat = rb_check_typeddata(self, &d_lite_type);
if (!simple_dat_p(dat)) {
rb_raise(rb_eTypeError, "Date expected");
}
rb_scan_args(argc, argv, "04", &vy, &vm, &vd, &vsg);
y = INT2FIX(-4712);
m = 1;
d = 1;
fr2 = INT2FIX(0);
sg = DEFAULT_SG;
switch (argc) {
case 4:
val2sg(vsg, sg);
case 3:
check_numeric(vd, "day");
num2int_with_frac(d, positive_inf);
case 2:
check_numeric(vm, "month");
m = NUM2INT(vm);
case 1:
check_numeric(vy, "year");
y = vy;
}
if (guess_style(y, sg) < 0) {
VALUE nth;
int ry, rm, rd;
if (!valid_gregorian_p(y, m, d,
&nth, &ry,
&rm, &rd))
rb_raise(eDateError, "invalid date");
set_to_simple(self, dat, nth, 0, sg, ry, rm, rd, HAVE_CIVIL);
}
else {
VALUE nth;
int ry, rm, rd, rjd, ns;
if (!valid_civil_p(y, m, d, sg,
&nth, &ry,
&rm, &rd, &rjd,
&ns))
rb_raise(eDateError, "invalid date");
set_to_simple(self, dat, nth, rjd, sg, ry, rm, rd, HAVE_JD | HAVE_CIVIL);
}
ret = self;
add_frac();
return ret;
}</pre>
</div>
</div>
</div>
<div id="method-c-new-21" class="method-detail ">
<div class="method-heading">
<span class="method-name">new!</span><span
class="method-args">(p1 = v1, p2 = v2, p3 = v3)</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<div class="method-source-code" id="new-21-source">
<pre>static VALUE
date_s_new_bang(int argc, VALUE *argv, VALUE klass)
{
VALUE ajd, of, sg, nth, sf;
int jd, df, rof;
double rsg;
rb_scan_args(argc, argv, "03", &ajd, &of, &sg);
switch (argc) {
case 0:
ajd = INT2FIX(0);
case 1:
of = INT2FIX(0);
case 2:
sg = INT2FIX(DEFAULT_SG);
}
old_to_new(ajd, of, sg,
&nth, &jd, &df, &sf, &rof, &rsg);
if (!df && f_zero_p(sf) && !rof)
return d_simple_new_internal(klass,
nth, jd,
rsg,
0, 0, 0,
HAVE_JD);
else
return d_complex_new_internal(klass,
nth, jd,
df, sf,
rof, rsg,
0, 0, 0,
0, 0, 0,
HAVE_JD | HAVE_DF);
}</pre>
</div>
</div>
</div>
<div id="method-c-nth_kday" class="method-detail ">
<div class="method-heading">
<span class="method-name">nth_kday</span><span
class="method-args">(p1 = v1, p2 = v2, p3 = v3, p4 = v4, p5 = v5)</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<div class="method-source-code" id="nth_kday-source">
<pre>static VALUE
date_s_nth_kday(int argc, VALUE *argv, VALUE klass)
{
VALUE vy, vm, vn, vk, vsg, y, fr, fr2, ret;
int m, n, k;
double sg;
rb_scan_args(argc, argv, "05", &vy, &vm, &vn, &vk, &vsg);
y = INT2FIX(-4712);
m = 1;
n = 1;
k = 1;
fr2 = INT2FIX(0);
sg = DEFAULT_SG;
switch (argc) {
case 5:
val2sg(vsg, sg);
case 4:
num2int_with_frac(k, positive_inf);
case 3:
n = NUM2INT(vn);
case 2:
m = NUM2INT(vm);
case 1:
y = vy;
}
{
VALUE nth;
int ry, rm, rn, rk, rjd, ns;
if (!valid_nth_kday_p(y, m, n, k, sg,
&nth, &ry,
&rm, &rn, &rk, &rjd,
&ns))
rb_raise(eDateError, "invalid date");
ret = d_simple_new_internal(klass,
nth, rjd,
sg,
0, 0, 0,
HAVE_JD);
}
add_frac();
return ret;
}</pre>
</div>
</div>
</div>
<div id="method-c-ordinal" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
ordinal([year=-4712[, yday=1[, start=Date::ITALY]]]) → date
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Creates a date object denoting the given ordinal date.</p>
<p>The day of year should be a negative or a positive number (as a relative day from the end of year when negative). It should not be zero.</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">ordinal</span>(<span class="ruby-value">2001</span>) <span class="ruby-comment">#=> #<Date: 2001-01-01 ...></span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">ordinal</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">34</span>) <span class="ruby-comment">#=> #<Date: 2001-02-03 ...></span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">ordinal</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">-1</span>) <span class="ruby-comment">#=> #<Date: 2001-12-31 ...></span>
</pre>
<p>See also <a href="Date.html#method-c-jd"><code>::jd</code></a> and <a href="Date.html#method-c-new"><code>::new</code></a>.</p>
<div class="method-source-code" id="ordinal-source">
<pre>static VALUE
date_s_ordinal(int argc, VALUE *argv, VALUE klass)
{
VALUE vy, vd, vsg, y, fr, fr2, ret;
int d;
double sg;
rb_scan_args(argc, argv, "03", &vy, &vd, &vsg);
y = INT2FIX(-4712);
d = 1;
fr2 = INT2FIX(0);
sg = DEFAULT_SG;
switch (argc) {
case 3:
val2sg(vsg, sg);
case 2:
check_numeric(vd, "yday");
num2int_with_frac(d, positive_inf);
case 1:
check_numeric(vy, "year");
y = vy;
}
{
VALUE nth;
int ry, rd, rjd, ns;
if (!valid_ordinal_p(y, d, sg,
&nth, &ry,
&rd, &rjd,
&ns))
rb_raise(eDateError, "invalid date");
ret = d_simple_new_internal(klass,
nth, rjd,
sg,
0, 0, 0,
HAVE_JD);
}
add_frac();
return ret;
}</pre>
</div>
</div>
</div>
<div id="method-c-parse" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
parse(string='-4712-01-01'[, comp=true[, start=Date::ITALY]], limit: 128) → date
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Parses the given representation of date and time, and creates a date object. This method does not function as a validator.</p>
<p>If the optional second argument is true and the detected year is in the range “00” to “99”, considers the year a 2-digit form and makes it full.</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-string">'2001-02-03'</span>) <span class="ruby-comment">#=> #<Date: 2001-02-03 ...></span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-string">'20010203'</span>) <span class="ruby-comment">#=> #<Date: 2001-02-03 ...></span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-string">'3rd Feb 2001'</span>) <span class="ruby-comment">#=> #<Date: 2001-02-03 ...></span>
</pre>
<p>Raise an <a href="ArgumentError.html"><code>ArgumentError</code></a> when the string length is longer than <em>limit</em>. You can stop this check by passing `limit: nil`, but note that it may take a long time to parse.</p>
<div class="method-source-code" id="parse-source">
<pre>static VALUE
date_s_parse(int argc, VALUE *argv, VALUE klass)
{
VALUE str, comp, sg, opt;
rb_scan_args(argc, argv, "03:", &str, &comp, &sg, &opt);
if (!NIL_P(opt)) argc--;
switch (argc) {
case 0:
str = rb_str_new2("-4712-01-01");
case 1:
comp = Qtrue;
case 2:
sg = INT2FIX(DEFAULT_SG);
}
{
int argc2 = 2;
VALUE argv2[3];
argv2[0] = str;
argv2[1] = comp;
if (!NIL_P(opt)) argv2[argc2++] = opt;
VALUE hash = date_s__parse(argc2, argv2, klass);
return d_new_by_frags(klass, hash, sg);
}
}</pre>
</div>
</div>
</div>
<div id="method-c-rfc2822" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
rfc2822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY], limit: 128) → date
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Creates a new <a href="Date.html"><code>Date</code></a> object by parsing from a string according to some typical RFC 2822 formats.</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">rfc2822</span>(<span class="ruby-string">'Sat, 3 Feb 2001 00:00:00 +0000'</span>)
<span class="ruby-comment">#=> #<Date: 2001-02-03 ...></span>
</pre>
<p>Raise an <a href="ArgumentError.html"><code>ArgumentError</code></a> when the string length is longer than <em>limit</em>. You can stop this check by passing `limit: nil`, but note that it may take a long time to parse.</p>
<div class="method-source-code" id="rfc2822-source">
<pre>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];
argv2[0] = str;
if (!NIL_P(opt)) argv2[argc2++] = opt;
VALUE hash = date_s__rfc2822(argc2, argv2, klass);
return d_new_by_frags(klass, hash, sg);
}
}</pre>
</div>
</div>
</div>
<div id="method-c-rfc3339" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
rfc3339(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY], limit: 128) → date
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Creates a new <a href="Date.html"><code>Date</code></a> object by parsing from a string according to some typical RFC 3339 formats.</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">rfc3339</span>(<span class="ruby-string">'2001-02-03T04:05:06+07:00'</span>) <span class="ruby-comment">#=> #<Date: 2001-02-03 ...></span>
</pre>
<p>Raise an <a href="ArgumentError.html"><code>ArgumentError</code></a> when the string length is longer than <em>limit</em>. You can stop this check by passing `limit: nil`, but note that it may take a long time to parse.</p>
<div class="method-source-code" id="rfc3339-source">
<pre>static VALUE
date_s_rfc3339(int argc, VALUE *argv, VALUE klass)
{
VALUE str, sg, opt;
rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
if (!NIL_P(opt)) argc--;
switch (argc) {
case 0:
str = rb_str_new2("-4712-01-01T00:00:00+00:00");
case 1:
sg = INT2FIX(DEFAULT_SG);
}
{
int argc2 = 1;
VALUE argv2[2];
argv2[0] = str;
if (!NIL_P(opt)) argv2[argc2++] = opt;
VALUE hash = date_s__rfc3339(argc2, argv2, klass);
return d_new_by_frags(klass, hash, sg);
}
}</pre>
</div>
</div>
</div>
<div id="method-c-rfc822" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
rfc822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY], limit: 128) → date
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Creates a new <a href="Date.html"><code>Date</code></a> object by parsing from a string according to some typical RFC 2822 formats.</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">rfc2822</span>(<span class="ruby-string">'Sat, 3 Feb 2001 00:00:00 +0000'</span>)
<span class="ruby-comment">#=> #<Date: 2001-02-03 ...></span>
</pre>
<p>Raise an <a href="ArgumentError.html"><code>ArgumentError</code></a> when the string length is longer than <em>limit</em>. You can stop this check by passing `limit: nil`, but note that it may take a long time to parse.</p>
<div class="method-source-code" id="rfc822-source">
<pre>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];
argv2[0] = str;
if (!NIL_P(opt)) argv2[argc2++] = opt;
VALUE hash = date_s__rfc2822(argc2, argv2, klass);
return d_new_by_frags(klass, hash, sg);
}
}</pre>
</div>
</div>
</div>
<div id="method-c-strptime" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
strptime([string='-4712-01-01'[, format='%F'[, start=Date::ITALY]]]) → date
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Parses the given representation of date and time with the given template, and creates a date object. strptime does not support specification of flags and width unlike strftime.</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">strptime</span>(<span class="ruby-string">'2001-02-03'</span>, <span class="ruby-string">'%Y-%m-%d'</span>) <span class="ruby-comment">#=> #<Date: 2001-02-03 ...></span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">strptime</span>(<span class="ruby-string">'03-02-2001'</span>, <span class="ruby-string">'%d-%m-%Y'</span>) <span class="ruby-comment">#=> #<Date: 2001-02-03 ...></span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">strptime</span>(<span class="ruby-string">'2001-034'</span>, <span class="ruby-string">'%Y-%j'</span>) <span class="ruby-comment">#=> #<Date: 2001-02-03 ...></span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">strptime</span>(<span class="ruby-string">'2001-W05-6'</span>, <span class="ruby-string">'%G-W%V-%u'</span>) <span class="ruby-comment">#=> #<Date: 2001-02-03 ...></span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">strptime</span>(<span class="ruby-string">'2001 04 6'</span>, <span class="ruby-string">'%Y %U %w'</span>) <span class="ruby-comment">#=> #<Date: 2001-02-03 ...></span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">strptime</span>(<span class="ruby-string">'2001 05 6'</span>, <span class="ruby-string">'%Y %W %u'</span>) <span class="ruby-comment">#=> #<Date: 2001-02-03 ...></span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">strptime</span>(<span class="ruby-string">'sat3feb01'</span>, <span class="ruby-string">'%a%d%b%y'</span>) <span class="ruby-comment">#=> #<Date: 2001-02-03 ...></span>
</pre>
<p>See also strptime(3) and <a href="Date.html#method-i-strftime"><code>strftime</code></a>.</p>
<div class="method-source-code" id="strptime-source">
<pre>static VALUE
date_s_strptime(int argc, VALUE *argv, VALUE klass)
{
VALUE str, fmt, sg;
rb_scan_args(argc, argv, "03", &str, &fmt, &sg);
switch (argc) {
case 0:
str = rb_str_new2("-4712-01-01");
case 1:
fmt = rb_str_new2("%F");
case 2:
sg = INT2FIX(DEFAULT_SG);
}
{
VALUE argv2[2], hash;
argv2[0] = str;
argv2[1] = fmt;
hash = date_s__strptime(2, argv2, klass);
return d_new_by_frags(klass, hash, sg);
}
}</pre>
</div>
</div>
</div>
<div id="method-c-test_all" class="method-detail ">
<div class="method-heading">
<span class="method-name">test_all</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<div class="method-source-code" id="test_all-source">
<pre>static VALUE
date_s_test_all(VALUE klass)
{
if (date_s_test_civil(klass) == Qfalse)
return Qfalse;
if (date_s_test_ordinal(klass) == Qfalse)
return Qfalse;
if (date_s_test_commercial(klass) == Qfalse)
return Qfalse;
if (date_s_test_weeknum(klass) == Qfalse)
return Qfalse;
if (date_s_test_nth_kday(klass) == Qfalse)
return Qfalse;
if (date_s_test_unit_conv(klass) == Qfalse)
return Qfalse;
return Qtrue;
}</pre>
</div>
</div>
</div>
<div id="method-c-test_civil" class="method-detail ">
<div class="method-heading">
<span class="method-name">test_civil</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<div class="method-source-code" id="test_civil-source">
<pre>static VALUE
date_s_test_civil(VALUE klass)
{
if (!test_civil(MIN_JD, MIN_JD + 366, GREGORIAN))
return Qfalse;
if (!test_civil(2305814, 2598007, GREGORIAN))
return Qfalse;
if (!test_civil(MAX_JD - 366, MAX_JD, GREGORIAN))
return Qfalse;
if (!test_civil(MIN_JD, MIN_JD + 366, ITALY))
return Qfalse;
if (!test_civil(2305814, 2598007, ITALY))
return Qfalse;
if (!test_civil(MAX_JD - 366, MAX_JD, ITALY))
return Qfalse;
return Qtrue;
}</pre>
</div>
</div>
</div>
<div id="method-c-test_commercial" class="method-detail ">
<div class="method-heading">
<span class="method-name">test_commercial</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<div class="method-source-code" id="test_commercial-source">
<pre>static VALUE
date_s_test_commercial(VALUE klass)
{
if (!test_commercial(MIN_JD, MIN_JD + 366, GREGORIAN))
return Qfalse;
if (!test_commercial(2305814, 2598007, GREGORIAN))
return Qfalse;
if (!test_commercial(MAX_JD - 366, MAX_JD, GREGORIAN))
return Qfalse;
if (!test_commercial(MIN_JD, MIN_JD + 366, ITALY))
return Qfalse;
if (!test_commercial(2305814, 2598007, ITALY))
return Qfalse;
if (!test_commercial(MAX_JD - 366, MAX_JD, ITALY))
return Qfalse;
return Qtrue;
}</pre>
</div>
</div>
</div>
<div id="method-c-test_nth_kday" class="method-detail ">
<div class="method-heading">
<span class="method-name">test_nth_kday</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<div class="method-source-code" id="test_nth_kday-source">
<pre>static VALUE
date_s_test_nth_kday(VALUE klass)
{
if (!test_nth_kday(MIN_JD, MIN_JD + 366, GREGORIAN))
return Qfalse;
if (!test_nth_kday(2305814, 2598007, GREGORIAN))
return Qfalse;
if (!test_nth_kday(MAX_JD - 366, MAX_JD, GREGORIAN))
return Qfalse;
if (!test_nth_kday(MIN_JD, MIN_JD + 366, ITALY))
return Qfalse;
if (!test_nth_kday(2305814, 2598007, ITALY))
return Qfalse;
if (!test_nth_kday(MAX_JD - 366, MAX_JD, ITALY))
return Qfalse;
return Qtrue;
}</pre>
</div>
</div>
</div>
<div id="method-c-test_ordinal" class="method-detail ">
<div class="method-heading">
<span class="method-name">test_ordinal</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<div class="method-source-code" id="test_ordinal-source">
<pre>static VALUE
date_s_test_ordinal(VALUE klass)
{
if (!test_ordinal(MIN_JD, MIN_JD + 366, GREGORIAN))
return Qfalse;
if (!test_ordinal(2305814, 2598007, GREGORIAN))
return Qfalse;
if (!test_ordinal(MAX_JD - 366, MAX_JD, GREGORIAN))
return Qfalse;
if (!test_ordinal(MIN_JD, MIN_JD + 366, ITALY))
return Qfalse;
if (!test_ordinal(2305814, 2598007, ITALY))
return Qfalse;
if (!test_ordinal(MAX_JD - 366, MAX_JD, ITALY))
return Qfalse;
return Qtrue;
}</pre>
</div>
</div>
</div>
<div id="method-c-test_unit_conv" class="method-detail ">
<div class="method-heading">
<span class="method-name">test_unit_conv</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<div class="method-source-code" id="test_unit_conv-source">
<pre>static VALUE
date_s_test_unit_conv(VALUE klass)
{
if (!test_unit_v2v_iter(sec_to_day, day_to_sec))
return Qfalse;
if (!test_unit_v2v_iter(ms_to_sec, sec_to_ms))
return Qfalse;
if (!test_unit_v2v_iter(ns_to_day, day_to_ns))
return Qfalse;
if (!test_unit_v2v_iter(ns_to_sec, sec_to_ns))
return Qfalse;
return Qtrue;
}</pre>
</div>
</div>
</div>
<div id="method-c-test_weeknum" class="method-detail ">
<div class="method-heading">
<span class="method-name">test_weeknum</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<div class="method-source-code" id="test_weeknum-source">
<pre>static VALUE
date_s_test_weeknum(VALUE klass)
{
int f;
for (f = 0; f <= 1; f++) {
if (!test_weeknum(MIN_JD, MIN_JD + 366, f, GREGORIAN))
return Qfalse;
if (!test_weeknum(2305814, 2598007, f, GREGORIAN))
return Qfalse;
if (!test_weeknum(MAX_JD - 366, MAX_JD, f, GREGORIAN))
return Qfalse;
if (!test_weeknum(MIN_JD, MIN_JD + 366, f, ITALY))
return Qfalse;
if (!test_weeknum(2305814, 2598007, f, ITALY))
return Qfalse;
if (!test_weeknum(MAX_JD - 366, MAX_JD, f, ITALY))
return Qfalse;
}
return Qtrue;
}</pre>
</div>
</div>
</div>
<div id="method-c-today" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
today([start=Date::ITALY]) → date
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Creates a date object denoting the present day.</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">today</span> <span class="ruby-comment">#=> #<Date: 2011-06-11 ...></span>
</pre>
<div class="method-source-code" id="today-source">
<pre>static VALUE
date_s_today(int argc, VALUE *argv, VALUE klass)
{
VALUE vsg, nth, ret;
double sg;
time_t t;
struct tm tm;
int y, ry, m, d;
rb_scan_args(argc, argv, "01", &vsg);
if (argc < 1)
sg = DEFAULT_SG;
else
val2sg(vsg, sg);
if (time(&t) == -1)
rb_sys_fail("time");
tzset();
if (!localtime_r(&t, &tm))
rb_sys_fail("localtime");
y = tm.tm_year + 1900;
m = tm.tm_mon + 1;
d = tm.tm_mday;
decode_year(INT2FIX(y), -1, &nth, &ry);
ret = d_simple_new_internal(klass,
nth, 0,
GREGORIAN,
ry, m, d,
HAVE_CIVIL);
{
get_d1(ret);
set_sg(dat, sg);
}
return ret;
}</pre>
</div>
</div>
</div>
<div id="method-c-valid_civil-3F" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
valid_civil?(year, month, mday[, start=Date::ITALY]) → bool
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns true if the given calendar date is valid, and false if not. Valid in this context is whether the arguments passed to this method would be accepted by <a href="Date.html#method-c-new"><code>::new</code></a>.</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">valid_date?</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>) <span class="ruby-comment">#=> true</span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">valid_date?</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">29</span>) <span class="ruby-comment">#=> false</span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">valid_date?</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">-1</span>) <span class="ruby-comment">#=> true</span>
</pre>
<p>See also <a href="Date.html#method-c-jd"><code>::jd</code></a> and <a href="Date.html#method-c-civil"><code>::civil</code></a>.</p>
<div class="method-source-code" id="valid_civil-3F-source">
<pre>static VALUE
date_s_valid_civil_p(int argc, VALUE *argv, VALUE klass)
{
VALUE vy, vm, vd, vsg;
VALUE argv2[4];
rb_scan_args(argc, argv, "31", &vy, &vm, &vd, &vsg);
RETURN_FALSE_UNLESS_NUMERIC(vy);
RETURN_FALSE_UNLESS_NUMERIC(vm);
RETURN_FALSE_UNLESS_NUMERIC(vd);
argv2[0] = vy;
argv2[1] = vm;
argv2[2] = vd;
if (argc < 4)
argv2[3] = INT2FIX(DEFAULT_SG);
else
argv2[3] = vsg;
if (NIL_P(valid_civil_sub(4, argv2, klass, 0)))
return Qfalse;
return Qtrue;
}</pre>
</div>
</div>
</div>
<div id="method-c-valid_commercial-3F" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
valid_commercial?(cwyear, cweek, cwday[, start=Date::ITALY]) → bool
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns true if the given week date is valid, and false if not.</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">valid_commercial?</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">5</span>,<span class="ruby-value">6</span>) <span class="ruby-comment">#=> true</span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">valid_commercial?</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">5</span>,<span class="ruby-value">8</span>) <span class="ruby-comment">#=> false</span>
</pre>
<p>See also <a href="Date.html#method-c-jd"><code>::jd</code></a> and <a href="Date.html#method-c-commercial"><code>::commercial</code></a>.</p>
<div class="method-source-code" id="valid_commercial-3F-source">
<pre>static VALUE
date_s_valid_commercial_p(int argc, VALUE *argv, VALUE klass)
{
VALUE vy, vw, vd, vsg;
VALUE argv2[4];
rb_scan_args(argc, argv, "31", &vy, &vw, &vd, &vsg);
RETURN_FALSE_UNLESS_NUMERIC(vy);
RETURN_FALSE_UNLESS_NUMERIC(vw);
RETURN_FALSE_UNLESS_NUMERIC(vd);
argv2[0] = vy;
argv2[1] = vw;
argv2[2] = vd;
if (argc < 4)
argv2[3] = INT2FIX(DEFAULT_SG);
else
argv2[3] = vsg;
if (NIL_P(valid_commercial_sub(4, argv2, klass, 0)))
return Qfalse;
return Qtrue;
}</pre>
</div>
</div>
</div>
<div id="method-c-valid_date-3F" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
valid_date?(year, month, mday[, start=Date::ITALY]) → bool
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns true if the given calendar date is valid, and false if not. Valid in this context is whether the arguments passed to this method would be accepted by <a href="Date.html#method-c-new"><code>::new</code></a>.</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">valid_date?</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>) <span class="ruby-comment">#=> true</span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">valid_date?</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">29</span>) <span class="ruby-comment">#=> false</span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">valid_date?</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">-1</span>) <span class="ruby-comment">#=> true</span>
</pre>
<p>See also <a href="Date.html#method-c-jd"><code>::jd</code></a> and <a href="Date.html#method-c-civil"><code>::civil</code></a>.</p>
<div class="method-source-code" id="valid_date-3F-source">
<pre>static VALUE
date_s_valid_civil_p(int argc, VALUE *argv, VALUE klass)
{
VALUE vy, vm, vd, vsg;
VALUE argv2[4];
rb_scan_args(argc, argv, "31", &vy, &vm, &vd, &vsg);
RETURN_FALSE_UNLESS_NUMERIC(vy);
RETURN_FALSE_UNLESS_NUMERIC(vm);
RETURN_FALSE_UNLESS_NUMERIC(vd);
argv2[0] = vy;
argv2[1] = vm;
argv2[2] = vd;
if (argc < 4)
argv2[3] = INT2FIX(DEFAULT_SG);
else
argv2[3] = vsg;
if (NIL_P(valid_civil_sub(4, argv2, klass, 0)))
return Qfalse;
return Qtrue;
}</pre>
</div>
</div>
</div>
<div id="method-c-valid_jd-3F" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
valid_jd?(jd[, start=Date::ITALY]) → bool
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Just returns true. It's nonsense, but is for symmetry.</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">valid_jd?</span>(<span class="ruby-value">2451944</span>) <span class="ruby-comment">#=> true</span>
</pre>
<p>See also <a href="Date.html#method-c-jd"><code>::jd</code></a>.</p>
<div class="method-source-code" id="valid_jd-3F-source">
<pre>static VALUE
date_s_valid_jd_p(int argc, VALUE *argv, VALUE klass)
{
VALUE vjd, vsg;
VALUE argv2[2];
rb_scan_args(argc, argv, "11", &vjd, &vsg);
RETURN_FALSE_UNLESS_NUMERIC(vjd);
argv2[0] = vjd;
if (argc < 2)
argv2[1] = INT2FIX(DEFAULT_SG);
else
argv2[1] = vsg;
if (NIL_P(valid_jd_sub(2, argv2, klass, 0)))
return Qfalse;
return Qtrue;
}</pre>
</div>
</div>
</div>
<div id="method-c-valid_ordinal-3F" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
valid_ordinal?(year, yday[, start=Date::ITALY]) → bool
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns true if the given ordinal date is valid, and false if not.</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">valid_ordinal?</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">34</span>) <span class="ruby-comment">#=> true</span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">valid_ordinal?</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">366</span>) <span class="ruby-comment">#=> false</span>
</pre>
<p>See also <a href="Date.html#method-c-jd"><code>::jd</code></a> and <a href="Date.html#method-c-ordinal"><code>::ordinal</code></a>.</p>
<div class="method-source-code" id="valid_ordinal-3F-source">
<pre>static VALUE
date_s_valid_ordinal_p(int argc, VALUE *argv, VALUE klass)
{
VALUE vy, vd, vsg;
VALUE argv2[3];
rb_scan_args(argc, argv, "21", &vy, &vd, &vsg);
RETURN_FALSE_UNLESS_NUMERIC(vy);
RETURN_FALSE_UNLESS_NUMERIC(vd);
argv2[0] = vy;
argv2[1] = vd;
if (argc < 3)
argv2[2] = INT2FIX(DEFAULT_SG);
else
argv2[2] = vsg;
if (NIL_P(valid_ordinal_sub(3, argv2, klass, 0)))
return Qfalse;
return Qtrue;
}</pre>
</div>
</div>
</div>
<div id="method-c-weeknum" class="method-detail ">
<div class="method-heading">
<span class="method-name">weeknum</span><span
class="method-args">(p1 = v1, p2 = v2, p3 = v3, p4 = v4, p5 = v5)</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<div class="method-source-code" id="weeknum-source">
<pre>static VALUE
date_s_weeknum(int argc, VALUE *argv, VALUE klass)
{
VALUE vy, vw, vd, vf, vsg, y, fr, fr2, ret;
int w, d, f;
double sg;
rb_scan_args(argc, argv, "05", &vy, &vw, &vd, &vf, &vsg);
y = INT2FIX(-4712);
w = 0;
d = 1;
f = 0;
fr2 = INT2FIX(0);
sg = DEFAULT_SG;
switch (argc) {
case 5:
val2sg(vsg, sg);
case 4:
f = NUM2INT(vf);
case 3:
num2int_with_frac(d, positive_inf);
case 2:
w = NUM2INT(vw);
case 1:
y = vy;
}
{
VALUE nth;
int ry, rw, rd, rjd, ns;
if (!valid_weeknum_p(y, w, d, f, sg,
&nth, &ry,
&rw, &rd, &rjd,
&ns))
rb_raise(eDateError, "invalid date");
ret = d_simple_new_internal(klass,
nth, rjd,
sg,
0, 0, 0,
HAVE_JD);
}
add_frac();
return ret;
}</pre>
</div>
</div>
</div>
<div id="method-c-xmlschema" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
xmlschema(string='-4712-01-01'[, start=Date::ITALY], limit: 128) → date
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Creates a new <a href="Date.html"><code>Date</code></a> object by parsing from a string according to some typical <a href="XML.html"><code>XML</code></a> Schema formats.</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">xmlschema</span>(<span class="ruby-string">'2001-02-03'</span>) <span class="ruby-comment">#=> #<Date: 2001-02-03 ...></span>
</pre>
<p>Raise an <a href="ArgumentError.html"><code>ArgumentError</code></a> when the string length is longer than <em>limit</em>. You can stop this check by passing `limit: nil`, but note that it may take a long time to parse.</p>
<div class="method-source-code" id="xmlschema-source">
<pre>static VALUE
date_s_xmlschema(int argc, VALUE *argv, VALUE klass)
{
VALUE str, sg, opt;
rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
if (!NIL_P(opt)) argc--;
switch (argc) {
case 0:
str = rb_str_new2("-4712-01-01");
case 1:
sg = INT2FIX(DEFAULT_SG);
}
{
int argc2 = 1;
VALUE argv2[2];
argv2[0] = str;
if (!NIL_P(opt)) argv2[argc2++] = opt;
VALUE hash = date_s__xmlschema(argc2, argv2, klass);
return d_new_by_frags(klass, hash, sg);
}
}</pre>
</div>
</div>
</div>
</section>
<section id="public-instance-5Buntitled-5D-method-details" class="method-section">
<header>
<h3>Public Instance Methods</h3>
</header>
<div id="method-i-2B" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
d + other → date
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns a date object pointing <code>other</code> days after self. The other should be a numeric value. If the other is a fractional number, assumes its precision is at most nanosecond.</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>) <span class="ruby-operator">+</span> <span class="ruby-value">1</span> <span class="ruby-comment">#=> #<Date: 2001-02-04 ...></span>
<span class="ruby-constant">DateTime</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>) <span class="ruby-operator">+</span> <span class="ruby-constant">Rational</span>(<span class="ruby-value">1</span>,<span class="ruby-value">2</span>)
<span class="ruby-comment">#=> #<DateTime: 2001-02-03T12:00:00+00:00 ...></span>
<span class="ruby-constant">DateTime</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>) <span class="ruby-operator">+</span> <span class="ruby-constant">Rational</span>(<span class="ruby-value">-1</span>,<span class="ruby-value">2</span>)
<span class="ruby-comment">#=> #<DateTime: 2001-02-02T12:00:00+00:00 ...></span>
<span class="ruby-constant">DateTime</span>.<span class="ruby-identifier">jd</span>(<span class="ruby-value">0</span>,<span class="ruby-value">12</span>) <span class="ruby-operator">+</span> <span class="ruby-constant">DateTime</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>).<span class="ruby-identifier">ajd</span>
<span class="ruby-comment">#=> #<DateTime: 2001-02-03T00:00:00+00:00 ...></span>
</pre>
<div class="method-source-code" id="2B-source">
<pre>static VALUE
d_lite_plus(VALUE self, VALUE other)
{
int try_rational = 1;
get_d1(self);
again:
switch (TYPE(other)) {
case T_FIXNUM:
{
VALUE nth;
long t;
int jd;
nth = m_nth(dat);
t = FIX2LONG(other);
if (DIV(t, CM_PERIOD)) {
nth = f_add(nth, INT2FIX(DIV(t, CM_PERIOD)));
t = MOD(t, CM_PERIOD);
}
if (!t)
jd = m_jd(dat);
else {
jd = m_jd(dat) + (int)t;
canonicalize_jd(nth, jd);
}
if (simple_dat_p(dat))
return d_simple_new_internal(rb_obj_class(self),
nth, jd,
dat->s.sg,
0, 0, 0,
(dat->s.flags | HAVE_JD) &
~HAVE_CIVIL);
else
return d_complex_new_internal(rb_obj_class(self),
nth, jd,
dat->c.df, dat->c.sf,
dat->c.of, dat->c.sg,
0, 0, 0,
#ifndef USE_PACK
dat->c.hour,
dat->c.min,
dat->c.sec,
#else
EX_HOUR(dat->c.pc),
EX_MIN(dat->c.pc),
EX_SEC(dat->c.pc),
#endif
(dat->c.flags | HAVE_JD) &
~HAVE_CIVIL);
}
break;
case T_BIGNUM:
{
VALUE nth;
int jd, s;
if (f_positive_p(other))
s = +1;
else {
s = -1;
other = f_negate(other);
}
nth = f_idiv(other, INT2FIX(CM_PERIOD));
jd = FIX2INT(f_mod(other, INT2FIX(CM_PERIOD)));
if (s < 0) {
nth = f_negate(nth);
jd = -jd;
}
if (!jd)
jd = m_jd(dat);
else {
jd = m_jd(dat) + jd;
canonicalize_jd(nth, jd);
}
if (f_zero_p(nth))
nth = m_nth(dat);
else
nth = f_add(m_nth(dat), nth);
if (simple_dat_p(dat))
return d_simple_new_internal(rb_obj_class(self),
nth, jd,
dat->s.sg,
0, 0, 0,
(dat->s.flags | HAVE_JD) &
~HAVE_CIVIL);
else
return d_complex_new_internal(rb_obj_class(self),
nth, jd,
dat->c.df, dat->c.sf,
dat->c.of, dat->c.sg,
0, 0, 0,
#ifndef USE_PACK
dat->c.hour,
dat->c.min,
dat->c.sec,
#else
EX_HOUR(dat->c.pc),
EX_MIN(dat->c.pc),
EX_SEC(dat->c.pc),
#endif
(dat->c.flags | HAVE_JD) &
~HAVE_CIVIL);
}
break;
case T_FLOAT:
{
double jd, o, tmp;
int s, df;
VALUE nth, sf;
o = RFLOAT_VALUE(other);
if (o > 0)
s = +1;
else {
s = -1;
o = -o;
}
o = modf(o, &tmp);
if (!floor(tmp / CM_PERIOD)) {
nth = INT2FIX(0);
jd = (int)tmp;
}
else {
double i, f;
f = modf(tmp / CM_PERIOD, &i);
nth = f_floor(DBL2NUM(i));
jd = (int)(f * CM_PERIOD);
}
o *= DAY_IN_SECONDS;
o = modf(o, &tmp);
df = (int)tmp;
o *= SECOND_IN_NANOSECONDS;
sf = INT2FIX((int)round(o));
if (s < 0) {
jd = -jd;
df = -df;
sf = f_negate(sf);
}
if (f_zero_p(sf))
sf = m_sf(dat);
else {
sf = f_add(m_sf(dat), sf);
if (f_lt_p(sf, INT2FIX(0))) {
df -= 1;
sf = f_add(sf, INT2FIX(SECOND_IN_NANOSECONDS));
}
else if (f_ge_p(sf, INT2FIX(SECOND_IN_NANOSECONDS))) {
df += 1;
sf = f_sub(sf, INT2FIX(SECOND_IN_NANOSECONDS));
}
}
if (!df)
df = m_df(dat);
else {
df = m_df(dat) + df;
if (df < 0) {
jd -= 1;
df += DAY_IN_SECONDS;
}
else if (df >= DAY_IN_SECONDS) {
jd += 1;
df -= DAY_IN_SECONDS;
}
}
if (!jd)
jd = m_jd(dat);
else {
jd = m_jd(dat) + jd;
canonicalize_jd(nth, jd);
}
if (f_zero_p(nth))
nth = m_nth(dat);
else
nth = f_add(m_nth(dat), nth);
if (!df && f_zero_p(sf) && !m_of(dat))
return d_simple_new_internal(rb_obj_class(self),
nth, (int)jd,
m_sg(dat),
0, 0, 0,
(dat->s.flags | HAVE_JD) &
~(HAVE_CIVIL | HAVE_TIME |
COMPLEX_DAT));
else
return d_complex_new_internal(rb_obj_class(self),
nth, (int)jd,
df, sf,
m_of(dat), m_sg(dat),
0, 0, 0,
0, 0, 0,
(dat->c.flags |
HAVE_JD | HAVE_DF) &
~(HAVE_CIVIL | HAVE_TIME));
}
break;
default:
expect_numeric(other);
other = f_to_r(other);
if (!k_rational_p(other)) {
if (!try_rational) Check_Type(other, T_RATIONAL);
try_rational = 0;
goto again;
}
/* fall through */
case T_RATIONAL:
{
VALUE nth, sf, t;
int jd, df, s;
if (wholenum_p(other)) {
other = rb_rational_num(other);
goto again;
}
if (f_positive_p(other))
s = +1;
else {
s = -1;
other = f_negate(other);
}
nth = f_idiv(other, INT2FIX(CM_PERIOD));
t = f_mod(other, INT2FIX(CM_PERIOD));
jd = FIX2INT(f_idiv(t, INT2FIX(1)));
t = f_mod(t, INT2FIX(1));
t = f_mul(t, INT2FIX(DAY_IN_SECONDS));
df = FIX2INT(f_idiv(t, INT2FIX(1)));
t = f_mod(t, INT2FIX(1));
sf = f_mul(t, INT2FIX(SECOND_IN_NANOSECONDS));
if (s < 0) {
nth = f_negate(nth);
jd = -jd;
df = -df;
sf = f_negate(sf);
}
if (f_zero_p(sf))
sf = m_sf(dat);
else {
sf = f_add(m_sf(dat), sf);
if (f_lt_p(sf, INT2FIX(0))) {
df -= 1;
sf = f_add(sf, INT2FIX(SECOND_IN_NANOSECONDS));
}
else if (f_ge_p(sf, INT2FIX(SECOND_IN_NANOSECONDS))) {
df += 1;
sf = f_sub(sf, INT2FIX(SECOND_IN_NANOSECONDS));
}
}
if (!df)
df = m_df(dat);
else {
df = m_df(dat) + df;
if (df < 0) {
jd -= 1;
df += DAY_IN_SECONDS;
}
else if (df >= DAY_IN_SECONDS) {
jd += 1;
df -= DAY_IN_SECONDS;
}
}
if (!jd)
jd = m_jd(dat);
else {
jd = m_jd(dat) + jd;
canonicalize_jd(nth, jd);
}
if (f_zero_p(nth))
nth = m_nth(dat);
else
nth = f_add(m_nth(dat), nth);
if (!df && f_zero_p(sf) && !m_of(dat))
return d_simple_new_internal(rb_obj_class(self),
nth, jd,
m_sg(dat),
0, 0, 0,
(dat->s.flags | HAVE_JD) &
~(HAVE_CIVIL | HAVE_TIME |
COMPLEX_DAT));
else
return d_complex_new_internal(rb_obj_class(self),
nth, jd,
df, sf,
m_of(dat), m_sg(dat),
0, 0, 0,
0, 0, 0,
(dat->c.flags |
HAVE_JD | HAVE_DF) &
~(HAVE_CIVIL | HAVE_TIME));
}
break;
}
}</pre>
</div>
</div>
</div>
<div id="method-i-2D" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
d - other → date or rational
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the difference between the two dates if the other is a date object. If the other is a numeric value, returns a date object pointing <code>other</code> days before self. If the other is a fractional number, assumes its precision is at most nanosecond.</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>) <span class="ruby-operator">-</span> <span class="ruby-value">1</span> <span class="ruby-comment">#=> #<Date: 2001-02-02 ...></span>
<span class="ruby-constant">DateTime</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>) <span class="ruby-operator">-</span> <span class="ruby-constant">Rational</span>(<span class="ruby-value">1</span>,<span class="ruby-value">2</span>)
<span class="ruby-comment">#=> #<DateTime: 2001-02-02T12:00:00+00:00 ...></span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>) <span class="ruby-operator">-</span> <span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>)
<span class="ruby-comment">#=> (33/1)</span>
<span class="ruby-constant">DateTime</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>) <span class="ruby-operator">-</span> <span class="ruby-constant">DateTime</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">2</span>,<span class="ruby-value">12</span>)
<span class="ruby-comment">#=> (1/2)</span>
</pre>
<div class="method-source-code" id="2D-source">
<pre>static VALUE
d_lite_minus(VALUE self, VALUE other)
{
if (k_date_p(other))
return minus_dd(self, other);
switch (TYPE(other)) {
case T_FIXNUM:
return d_lite_plus(self, LONG2NUM(-FIX2LONG(other)));
case T_FLOAT:
return d_lite_plus(self, DBL2NUM(-RFLOAT_VALUE(other)));
default:
expect_numeric(other);
/* fall through */
case T_BIGNUM:
case T_RATIONAL:
return d_lite_plus(self, f_negate(other));
}
}</pre>
</div>
</div>
</div>
<div id="method-i-3C-3C" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
d << n → date
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns a date object pointing <code>n</code> months before self. The argument <code>n</code> should be a numeric value.</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>) <span class="ruby-operator"><<</span> <span class="ruby-value">1</span> <span class="ruby-comment">#=> #<Date: 2001-01-03 ...></span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>) <span class="ruby-operator"><<</span> <span class="ruby-value">-2</span> <span class="ruby-comment">#=> #<Date: 2001-04-03 ...></span>
</pre>
<p>When the same day does not exist for the corresponding month, the last day of the month is used instead:</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">3</span>,<span class="ruby-value">28</span>) <span class="ruby-operator"><<</span> <span class="ruby-value">1</span> <span class="ruby-comment">#=> #<Date: 2001-02-28 ...></span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">3</span>,<span class="ruby-value">31</span>) <span class="ruby-operator"><<</span> <span class="ruby-value">1</span> <span class="ruby-comment">#=> #<Date: 2001-02-28 ...></span>
</pre>
<p>This also results in the following, possibly unexpected, behavior:</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">3</span>,<span class="ruby-value">31</span>) <span class="ruby-operator"><<</span> <span class="ruby-value">2</span> <span class="ruby-comment">#=> #<Date: 2001-01-31 ...></span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">3</span>,<span class="ruby-value">31</span>) <span class="ruby-operator"><<</span> <span class="ruby-value">1</span> <span class="ruby-operator"><<</span> <span class="ruby-value">1</span> <span class="ruby-comment">#=> #<Date: 2001-01-28 ...></span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">3</span>,<span class="ruby-value">31</span>) <span class="ruby-operator"><<</span> <span class="ruby-value">1</span> <span class="ruby-operator"><<</span> <span class="ruby-value">-1</span> <span class="ruby-comment">#=> #<Date: 2001-03-28 ...></span>
</pre>
<div class="method-source-code" id="3C-3C-source">
<pre>static VALUE
d_lite_lshift(VALUE self, VALUE other)
{
expect_numeric(other);
return d_lite_rshift(self, f_negate(other));
}</pre>
</div>
</div>
</div>
<div id="method-i-3C-3D-3E" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
d <=> other → -1, 0, +1 or nil
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Compares the two dates and returns -1, zero, 1 or nil. The other should be a date object or a numeric value as an astronomical Julian day number.</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>) <span class="ruby-operator"><=></span> <span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">4</span>) <span class="ruby-comment">#=> -1</span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>) <span class="ruby-operator"><=></span> <span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>) <span class="ruby-comment">#=> 0</span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>) <span class="ruby-operator"><=></span> <span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">2</span>) <span class="ruby-comment">#=> 1</span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>) <span class="ruby-operator"><=></span> <span class="ruby-constant">Object</span>.<span class="ruby-identifier">new</span> <span class="ruby-comment">#=> nil</span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>) <span class="ruby-operator"><=></span> <span class="ruby-constant">Rational</span>(<span class="ruby-value">4903887</span>,<span class="ruby-value">2</span>) <span class="ruby-comment">#=> 0</span>
</pre>
<p>See also <a href="Comparable.html"><code>Comparable</code></a>.</p>
<div class="method-source-code" id="3C-3D-3E-source">
<pre>static VALUE
d_lite_cmp(VALUE self, VALUE other)
{
if (!k_date_p(other))
return cmp_gen(self, other);
{
get_d2(self, other);
if (!(simple_dat_p(adat) && simple_dat_p(bdat) &&
m_gregorian_p(adat) == m_gregorian_p(bdat)))
return cmp_dd(self, other);
{
VALUE a_nth, b_nth;
int a_jd, b_jd;
m_canonicalize_jd(self, adat);
m_canonicalize_jd(other, bdat);
a_nth = m_nth(adat);
b_nth = m_nth(bdat);
if (f_eqeq_p(a_nth, b_nth)) {
a_jd = m_jd(adat);
b_jd = m_jd(bdat);
if (a_jd == b_jd) {
return INT2FIX(0);
}
else if (a_jd < b_jd) {
return INT2FIX(-1);
}
else {
return INT2FIX(1);
}
}
else if (f_lt_p(a_nth, b_nth)) {
return INT2FIX(-1);
}
else {
return INT2FIX(1);
}
}
}
}</pre>
</div>
</div>
</div>
<div id="method-i-3D-3D-3D" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
d === other → bool
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns true if they are the same day.</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>) <span class="ruby-operator">===</span> <span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>)
<span class="ruby-comment">#=> true</span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>) <span class="ruby-operator">===</span> <span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">4</span>)
<span class="ruby-comment">#=> false</span>
<span class="ruby-constant">DateTime</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>) <span class="ruby-operator">===</span> <span class="ruby-constant">DateTime</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>,<span class="ruby-value">12</span>)
<span class="ruby-comment">#=> true</span>
<span class="ruby-constant">DateTime</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>) <span class="ruby-operator">===</span> <span class="ruby-constant">DateTime</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>,<span class="ruby-value">0</span>,<span class="ruby-value">0</span>,<span class="ruby-value">0</span>,<span class="ruby-string">'+24:00'</span>)
<span class="ruby-comment">#=> true</span>
<span class="ruby-constant">DateTime</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>) <span class="ruby-operator">===</span> <span class="ruby-constant">DateTime</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">4</span>,<span class="ruby-value">0</span>,<span class="ruby-value">0</span>,<span class="ruby-value">0</span>,<span class="ruby-string">'+24:00'</span>)
<span class="ruby-comment">#=> false</span>
</pre>
<div class="method-source-code" id="3D-3D-3D-source">
<pre>static VALUE
d_lite_equal(VALUE self, VALUE other)
{
if (!k_date_p(other))
return equal_gen(self, other);
{
get_d2(self, other);
if (!(m_gregorian_p(adat) == m_gregorian_p(bdat)))
return equal_gen(self, other);
{
VALUE a_nth, b_nth;
int a_jd, b_jd;
m_canonicalize_jd(self, adat);
m_canonicalize_jd(other, bdat);
a_nth = m_nth(adat);
b_nth = m_nth(bdat);
a_jd = m_local_jd(adat);
b_jd = m_local_jd(bdat);
if (f_eqeq_p(a_nth, b_nth) &&
a_jd == b_jd)
return Qtrue;
return Qfalse;
}
}
}</pre>
</div>
</div>
</div>
<div id="method-i-3E-3E" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
d >> n → date
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns a date object pointing <code>n</code> months after self. The argument <code>n</code> should be a numeric value.</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>) <span class="ruby-operator">>></span> <span class="ruby-value">1</span> <span class="ruby-comment">#=> #<Date: 2001-03-03 ...></span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>) <span class="ruby-operator">>></span> <span class="ruby-value">-2</span> <span class="ruby-comment">#=> #<Date: 2000-12-03 ...></span>
</pre>
<p>When the same day does not exist for the corresponding month, the last day of the month is used instead:</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">1</span>,<span class="ruby-value">28</span>) <span class="ruby-operator">>></span> <span class="ruby-value">1</span> <span class="ruby-comment">#=> #<Date: 2001-02-28 ...></span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">1</span>,<span class="ruby-value">31</span>) <span class="ruby-operator">>></span> <span class="ruby-value">1</span> <span class="ruby-comment">#=> #<Date: 2001-02-28 ...></span>
</pre>
<p>This also results in the following, possibly unexpected, behavior:</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">1</span>,<span class="ruby-value">31</span>) <span class="ruby-operator">>></span> <span class="ruby-value">2</span> <span class="ruby-comment">#=> #<Date: 2001-03-31 ...></span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">1</span>,<span class="ruby-value">31</span>) <span class="ruby-operator">>></span> <span class="ruby-value">1</span> <span class="ruby-operator">>></span> <span class="ruby-value">1</span> <span class="ruby-comment">#=> #<Date: 2001-03-28 ...></span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">1</span>,<span class="ruby-value">31</span>) <span class="ruby-operator">>></span> <span class="ruby-value">1</span> <span class="ruby-operator">>></span> <span class="ruby-value">-1</span> <span class="ruby-comment">#=> #<Date: 2001-01-28 ...></span>
</pre>
<div class="method-source-code" id="3E-3E-source">
<pre>static VALUE
d_lite_rshift(VALUE self, VALUE other)
{
VALUE t, y, nth, rjd2;
int m, d, rjd;
double sg;
get_d1(self);
t = f_add3(f_mul(m_real_year(dat), INT2FIX(12)),
INT2FIX(m_mon(dat) - 1),
other);
if (FIXNUM_P(t)) {
long it = FIX2LONG(t);
y = LONG2NUM(DIV(it, 12));
it = MOD(it, 12);
m = (int)it + 1;
}
else {
y = f_idiv(t, INT2FIX(12));
t = f_mod(t, INT2FIX(12));
m = FIX2INT(t) + 1;
}
d = m_mday(dat);
sg = m_sg(dat);
while (1) {
int ry, rm, rd, ns;
if (valid_civil_p(y, m, d, sg,
&nth, &ry,
&rm, &rd, &rjd, &ns))
break;
if (--d < 1)
rb_raise(eDateError, "invalid date");
}
encode_jd(nth, rjd, &rjd2);
return d_lite_plus(self, f_sub(rjd2, m_real_local_jd(dat)));
}</pre>
</div>
</div>
</div>
<div id="method-i-ajd" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
ajd → rational
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the astronomical Julian day number. This is a fractional number, which is not adjusted by the offset.</p>
<pre class="ruby"><span class="ruby-constant">DateTime</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>,<span class="ruby-value">4</span>,<span class="ruby-value">5</span>,<span class="ruby-value">6</span>,<span class="ruby-string">'+7'</span>).<span class="ruby-identifier">ajd</span> <span class="ruby-comment">#=> (11769328217/4800)</span>
<span class="ruby-constant">DateTime</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">2</span>,<span class="ruby-value">14</span>,<span class="ruby-value">5</span>,<span class="ruby-value">6</span>,<span class="ruby-string">'-7'</span>).<span class="ruby-identifier">ajd</span> <span class="ruby-comment">#=> (11769328217/4800)</span>
</pre>
<div class="method-source-code" id="ajd-source">
<pre>static VALUE
d_lite_ajd(VALUE self)
{
get_d1(self);
return m_ajd(dat);
}</pre>
</div>
</div>
</div>
<div id="method-i-amjd" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
amjd → rational
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the astronomical modified Julian day number. This is a fractional number, which is not adjusted by the offset.</p>
<pre class="ruby"><span class="ruby-constant">DateTime</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>,<span class="ruby-value">4</span>,<span class="ruby-value">5</span>,<span class="ruby-value">6</span>,<span class="ruby-string">'+7'</span>).<span class="ruby-identifier">amjd</span> <span class="ruby-comment">#=> (249325817/4800)</span>
<span class="ruby-constant">DateTime</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">2</span>,<span class="ruby-value">14</span>,<span class="ruby-value">5</span>,<span class="ruby-value">6</span>,<span class="ruby-string">'-7'</span>).<span class="ruby-identifier">amjd</span> <span class="ruby-comment">#=> (249325817/4800)</span>
</pre>
<div class="method-source-code" id="amjd-source">
<pre>static VALUE
d_lite_amjd(VALUE self)
{
get_d1(self);
return m_amjd(dat);
}</pre>
</div>
</div>
</div>
<div id="method-i-as_json" class="method-detail ">
<div class="method-heading">
<span class="method-name">as_json</span><span
class="method-args">(*)</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns a hash, that will be turned into a <a href="JSON.html"><code>JSON</code></a> object and represent this object.</p>
<div class="method-source-code" id="as_json-source">
<pre><span class="ruby-comment"># File ext/json/lib/json/add/date.rb, line 19</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">as_json</span>(<span class="ruby-operator">*</span>)
{
<span class="ruby-constant">JSON</span>.<span class="ruby-identifier">create_id</span> <span class="ruby-operator">=></span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">name</span>,
<span class="ruby-string">'y'</span> <span class="ruby-operator">=></span> <span class="ruby-identifier">year</span>,
<span class="ruby-string">'m'</span> <span class="ruby-operator">=></span> <span class="ruby-identifier">month</span>,
<span class="ruby-string">'d'</span> <span class="ruby-operator">=></span> <span class="ruby-identifier">day</span>,
<span class="ruby-string">'sg'</span> <span class="ruby-operator">=></span> <span class="ruby-identifier">start</span>,
}
<span class="ruby-keyword">end</span></pre>
</div>
</div>
</div>
<div id="method-i-asctime" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
asctime → string
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns a string in asctime(3) format (but without “n0” at the end). This method is equivalent to strftime('%c').</p>
<p>See also asctime(3) or ctime(3).</p>
<div class="method-source-code" id="asctime-source">
<pre>static VALUE
d_lite_asctime(VALUE self)
{
return strftimev("%a %b %e %H:%M:%S %Y", self, set_tmx);
}</pre>
</div>
</div>
</div>
<div id="method-i-ctime" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
ctime → string
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns a string in asctime(3) format (but without “n0” at the end). This method is equivalent to strftime('%c').</p>
<p>See also asctime(3) or ctime(3).</p>
<div class="method-source-code" id="ctime-source">
<pre>static VALUE
d_lite_asctime(VALUE self)
{
return strftimev("%a %b %e %H:%M:%S %Y", self, set_tmx);
}</pre>
</div>
</div>
</div>
<div id="method-i-cwday" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
cwday → fixnum
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the day of calendar week (1-7, Monday is 1).</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>).<span class="ruby-identifier">cwday</span> <span class="ruby-comment">#=> 6</span>
</pre>
<div class="method-source-code" id="cwday-source">
<pre>static VALUE
d_lite_cwday(VALUE self)
{
get_d1(self);
return INT2FIX(m_cwday(dat));
}</pre>
</div>
</div>
</div>
<div id="method-i-cweek" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
cweek → fixnum
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the calendar week number (1-53).</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>).<span class="ruby-identifier">cweek</span> <span class="ruby-comment">#=> 5</span>
</pre>
<div class="method-source-code" id="cweek-source">
<pre>static VALUE
d_lite_cweek(VALUE self)
{
get_d1(self);
return INT2FIX(m_cweek(dat));
}</pre>
</div>
</div>
</div>
<div id="method-i-cwyear" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
cwyear → integer
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the calendar week based year.</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>).<span class="ruby-identifier">cwyear</span> <span class="ruby-comment">#=> 2001</span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2000</span>,<span class="ruby-value">1</span>,<span class="ruby-value">1</span>).<span class="ruby-identifier">cwyear</span> <span class="ruby-comment">#=> 1999</span>
</pre>
<div class="method-source-code" id="cwyear-source">
<pre>static VALUE
d_lite_cwyear(VALUE self)
{
get_d1(self);
return m_real_cwyear(dat);
}</pre>
</div>
</div>
</div>
<div id="method-i-day" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
day → fixnum
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the day of the month (1-31).</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>).<span class="ruby-identifier">mday</span> <span class="ruby-comment">#=> 3</span>
</pre>
<div class="method-source-code" id="day-source">
<pre>static VALUE
d_lite_mday(VALUE self)
{
get_d1(self);
return INT2FIX(m_mday(dat));
}</pre>
</div>
</div>
</div>
<div id="method-i-day_fraction" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
day_fraction → rational
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the fractional part of the day.</p>
<pre class="ruby"><span class="ruby-constant">DateTime</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>,<span class="ruby-value">12</span>).<span class="ruby-identifier">day_fraction</span> <span class="ruby-comment">#=> (1/2)</span>
</pre>
<div class="method-source-code" id="day_fraction-source">
<pre>static VALUE
d_lite_day_fraction(VALUE self)
{
get_d1(self);
if (simple_dat_p(dat))
return INT2FIX(0);
return m_fr(dat);
}</pre>
</div>
</div>
</div>
<div id="method-i-downto" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
downto(min) → enumerator
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-heading">
<span class="method-callseq">
downto(min){|date| ...} → self
</span>
</div>
<div class="method-description">
<p>This method is equivalent to step(min, -1){|date| …}.</p>
<div class="method-source-code" id="downto-source">
<pre>static VALUE
d_lite_downto(VALUE self, VALUE min)
{
VALUE date;
RETURN_ENUMERATOR(self, 1, &min);
date = self;
while (FIX2INT(d_lite_cmp(date, min)) >= 0) {
rb_yield(date);
date = d_lite_plus(date, INT2FIX(-1));
}
return self;
}</pre>
</div>
</div>
</div>
<div id="method-i-england" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
england → date
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>This method is equivalent to <a href="Date.html#method-i-new_start"><code>new_start</code></a>(<a href="Date.html#ENGLAND"><code>Date::ENGLAND</code></a>).</p>
<div class="method-source-code" id="england-source">
<pre>static VALUE
d_lite_england(VALUE self)
{
return dup_obj_with_new_start(self, ENGLAND);
}</pre>
</div>
</div>
</div>
<div id="method-i-fill" class="method-detail ">
<div class="method-heading">
<span class="method-name">fill</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<div class="method-source-code" id="fill-source">
<pre>static VALUE
d_lite_fill(VALUE self)
{
get_d1(self);
if (simple_dat_p(dat)) {
get_s_jd(dat);
get_s_civil(dat);
}
else {
get_c_jd(dat);
get_c_civil(dat);
get_c_df(dat);
get_c_time(dat);
}
return self;
}</pre>
</div>
</div>
</div>
<div id="method-i-friday-3F" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
friday? → bool
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns true if the date is Friday.</p>
<div class="method-source-code" id="friday-3F-source">
<pre>static VALUE
d_lite_friday_p(VALUE self)
{
get_d1(self);
return f_boolcast(m_wday(dat) == 5);
}</pre>
</div>
</div>
</div>
<div id="method-i-gregorian" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
gregorian → date
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>This method is equivalent to <a href="Date.html#method-i-new_start"><code>new_start</code></a>(<a href="Date.html#GREGORIAN"><code>Date::GREGORIAN</code></a>).</p>
<div class="method-source-code" id="gregorian-source">
<pre>static VALUE
d_lite_gregorian(VALUE self)
{
return dup_obj_with_new_start(self, GREGORIAN);
}</pre>
</div>
</div>
</div>
<div id="method-i-gregorian-3F" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
gregorian? → bool
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns true if the date is on or after the day of calendar reform.</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">1582</span>,<span class="ruby-value">10</span>,<span class="ruby-value">15</span>).<span class="ruby-identifier">gregorian?</span> <span class="ruby-comment">#=> true</span>
(<span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">1582</span>,<span class="ruby-value">10</span>,<span class="ruby-value">15</span>) <span class="ruby-operator">-</span> <span class="ruby-value">1</span>).<span class="ruby-identifier">gregorian?</span> <span class="ruby-comment">#=> false</span>
</pre>
<div class="method-source-code" id="gregorian-3F-source">
<pre>static VALUE
d_lite_gregorian_p(VALUE self)
{
get_d1(self);
return f_boolcast(m_gregorian_p(dat));
}</pre>
</div>
</div>
</div>
<div id="method-i-httpdate" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
httpdate → string
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>This method is equivalent to strftime('%a, %d %b %Y %T GMT'). See also RFC 2616.</p>
<div class="method-source-code" id="httpdate-source">
<pre>static VALUE
d_lite_httpdate(VALUE self)
{
volatile VALUE dup = dup_obj_with_new_offset(self, 0);
return strftimev("%a, %d %b %Y %T GMT", dup, set_tmx);
}</pre>
</div>
</div>
</div>
<div id="method-i-inspect" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
inspect → string
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the value as a string for inspection.</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>).<span class="ruby-identifier">inspect</span>
<span class="ruby-comment">#=> "#<Date: 2001-02-03>"</span>
<span class="ruby-constant">DateTime</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>,<span class="ruby-value">4</span>,<span class="ruby-value">5</span>,<span class="ruby-value">6</span>,<span class="ruby-string">'-7'</span>).<span class="ruby-identifier">inspect</span>
<span class="ruby-comment">#=> "#<DateTime: 2001-02-03T04:05:06-07:00>"</span>
</pre>
<div class="method-source-code" id="inspect-source">
<pre>static VALUE
d_lite_inspect(VALUE self)
{
get_d1(self);
return mk_inspect(dat, rb_obj_class(self), self);
}</pre>
</div>
</div>
</div>
<div id="method-i-inspect_raw" class="method-detail ">
<div class="method-heading">
<span class="method-name">inspect_raw</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<div class="method-source-code" id="inspect_raw-source">
<pre>static VALUE
d_lite_inspect_raw(VALUE self)
{
get_d1(self);
return mk_inspect_raw(dat, rb_obj_class(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-iso8601" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
iso8601 → string
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-heading">
<span class="method-callseq">
xmlschema → string
</span>
</div>
<div class="method-description">
<p>This method is equivalent to strftime('%F').</p>
<div class="method-source-code" id="iso8601-source">
<pre>static VALUE
d_lite_iso8601(VALUE self)
{
return strftimev("%Y-%m-%d", self, set_tmx);
}</pre>
</div>
</div>
</div>
<div id="method-i-italy" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
italy → date
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>This method is equivalent to <a href="Date.html#method-i-new_start"><code>new_start</code></a>(<a href="Date.html#ITALY"><code>Date::ITALY</code></a>).</p>
<div class="method-source-code" id="italy-source">
<pre>static VALUE
d_lite_italy(VALUE self)
{
return dup_obj_with_new_start(self, ITALY);
}</pre>
</div>
</div>
</div>
<div id="method-i-jd" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
jd → integer
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the Julian day number. This is a whole number, which is adjusted by the offset as the local time.</p>
<pre class="ruby"><span class="ruby-constant">DateTime</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>,<span class="ruby-value">4</span>,<span class="ruby-value">5</span>,<span class="ruby-value">6</span>,<span class="ruby-string">'+7'</span>).<span class="ruby-identifier">jd</span> <span class="ruby-comment">#=> 2451944</span>
<span class="ruby-constant">DateTime</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>,<span class="ruby-value">4</span>,<span class="ruby-value">5</span>,<span class="ruby-value">6</span>,<span class="ruby-string">'-7'</span>).<span class="ruby-identifier">jd</span> <span class="ruby-comment">#=> 2451944</span>
</pre>
<div class="method-source-code" id="jd-source">
<pre>static VALUE
d_lite_jd(VALUE self)
{
get_d1(self);
return m_real_local_jd(dat);
}</pre>
</div>
</div>
</div>
<div id="method-i-jisx0301" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
jisx0301 → string
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns a string in a JIS X 0301 format.</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>).<span class="ruby-identifier">jisx0301</span> <span class="ruby-comment">#=> "H13.02.03"</span>
</pre>
<div class="method-source-code" id="jisx0301-source">
<pre>static VALUE
d_lite_jisx0301(VALUE self)
{
char fmtbuf[JISX0301_DATE_SIZE];
const char *fmt;
get_d1(self);
fmt = jisx0301_date_format(fmtbuf, sizeof(fmtbuf),
m_real_local_jd(dat),
m_real_year(dat));
return strftimev(fmt, self, set_tmx);
}</pre>
</div>
</div>
</div>
<div id="method-i-julian" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
julian → date
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>This method is equivalent to <a href="Date.html#method-i-new_start"><code>new_start</code></a>(<a href="Date.html#JULIAN"><code>Date::JULIAN</code></a>).</p>
<div class="method-source-code" id="julian-source">
<pre>static VALUE
d_lite_julian(VALUE self)
{
return dup_obj_with_new_start(self, JULIAN);
}</pre>
</div>
</div>
</div>
<div id="method-i-julian-3F" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
julian? → bool
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns true if the date is before the day of calendar reform.</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">1582</span>,<span class="ruby-value">10</span>,<span class="ruby-value">15</span>).<span class="ruby-identifier">julian?</span> <span class="ruby-comment">#=> false</span>
(<span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">1582</span>,<span class="ruby-value">10</span>,<span class="ruby-value">15</span>) <span class="ruby-operator">-</span> <span class="ruby-value">1</span>).<span class="ruby-identifier">julian?</span> <span class="ruby-comment">#=> true</span>
</pre>
<div class="method-source-code" id="julian-3F-source">
<pre>static VALUE
d_lite_julian_p(VALUE self)
{
get_d1(self);
return f_boolcast(m_julian_p(dat));
}</pre>
</div>
</div>
</div>
<div id="method-i-ld" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
ld → integer
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the Lilian day number. This is a whole number, which is adjusted by the offset as the local time.</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>).<span class="ruby-identifier">ld</span> <span class="ruby-comment">#=> 152784</span>
</pre>
<div class="method-source-code" id="ld-source">
<pre>static VALUE
d_lite_ld(VALUE self)
{
get_d1(self);
return f_sub(m_real_local_jd(dat), INT2FIX(2299160));
}</pre>
</div>
</div>
</div>
<div id="method-i-leap-3F" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
leap? → bool
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns true if the year is a leap year.</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2000</span>).<span class="ruby-identifier">leap?</span> <span class="ruby-comment">#=> true</span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>).<span class="ruby-identifier">leap?</span> <span class="ruby-comment">#=> false</span>
</pre>
<div class="method-source-code" id="leap-3F-source">
<pre>static VALUE
d_lite_leap_p(VALUE self)
{
int rjd, ns, ry, rm, rd;
get_d1(self);
if (m_gregorian_p(dat))
return f_boolcast(c_gregorian_leap_p(m_year(dat)));
c_civil_to_jd(m_year(dat), 3, 1, m_virtual_sg(dat),
&rjd, &ns);
c_jd_to_civil(rjd - 1, m_virtual_sg(dat), &ry, &rm, &rd);
return f_boolcast(rd == 29);
}</pre>
</div>
</div>
</div>
<div id="method-i-marshal_dump_old" class="method-detail ">
<div class="method-heading">
<span class="method-name">marshal_dump_old</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<div class="method-source-code" id="marshal_dump_old-source">
<pre>static VALUE
d_lite_marshal_dump_old(VALUE self)
{
VALUE a;
get_d1(self);
a = rb_ary_new3(3,
m_ajd(dat),
m_of_in_day(dat),
DBL2NUM(m_sg(dat)));
if (FL_TEST(self, FL_EXIVAR)) {
rb_copy_generic_ivar(a, self);
FL_SET(a, FL_EXIVAR);
}
return a;
}</pre>
</div>
</div>
</div>
<div id="method-i-mday" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
mday → fixnum
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the day of the month (1-31).</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>).<span class="ruby-identifier">mday</span> <span class="ruby-comment">#=> 3</span>
</pre>
<div class="method-source-code" id="mday-source">
<pre>static VALUE
d_lite_mday(VALUE self)
{
get_d1(self);
return INT2FIX(m_mday(dat));
}</pre>
</div>
</div>
</div>
<div id="method-i-mjd" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
mjd → integer
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the modified Julian day number. This is a whole number, which is adjusted by the offset as the local time.</p>
<pre class="ruby"><span class="ruby-constant">DateTime</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>,<span class="ruby-value">4</span>,<span class="ruby-value">5</span>,<span class="ruby-value">6</span>,<span class="ruby-string">'+7'</span>).<span class="ruby-identifier">mjd</span> <span class="ruby-comment">#=> 51943</span>
<span class="ruby-constant">DateTime</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>,<span class="ruby-value">4</span>,<span class="ruby-value">5</span>,<span class="ruby-value">6</span>,<span class="ruby-string">'-7'</span>).<span class="ruby-identifier">mjd</span> <span class="ruby-comment">#=> 51943</span>
</pre>
<div class="method-source-code" id="mjd-source">
<pre>static VALUE
d_lite_mjd(VALUE self)
{
get_d1(self);
return f_sub(m_real_local_jd(dat), INT2FIX(2400001));
}</pre>
</div>
</div>
</div>
<div id="method-i-mon" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
mon → fixnum
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-heading">
<span class="method-callseq">
month → fixnum
</span>
</div>
<div class="method-description">
<p>Returns the month (1-12).</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>).<span class="ruby-identifier">mon</span> <span class="ruby-comment">#=> 2</span>
</pre>
<div class="method-source-code" id="mon-source">
<pre>static VALUE
d_lite_mon(VALUE self)
{
get_d1(self);
return INT2FIX(m_mon(dat));
}</pre>
</div>
</div>
</div>
<div id="method-i-monday-3F" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
monday? → bool
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns true if the date is Monday.</p>
<div class="method-source-code" id="monday-3F-source">
<pre>static VALUE
d_lite_monday_p(VALUE self)
{
get_d1(self);
return f_boolcast(m_wday(dat) == 1);
}</pre>
</div>
</div>
</div>
<div id="method-i-month" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
month → fixnum
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the month (1-12).</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>).<span class="ruby-identifier">mon</span> <span class="ruby-comment">#=> 2</span>
</pre>
<div class="method-source-code" id="month-source">
<pre>static VALUE
d_lite_mon(VALUE self)
{
get_d1(self);
return INT2FIX(m_mon(dat));
}</pre>
</div>
</div>
</div>
<div id="method-i-new_start" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
new_start([start=Date::ITALY]) → date
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Duplicates self and resets its day of calendar reform.</p>
<pre class="ruby"><span class="ruby-identifier">d</span> = <span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">1582</span>,<span class="ruby-value">10</span>,<span class="ruby-value">15</span>)
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">new_start</span>(<span class="ruby-constant">Date</span><span class="ruby-operator">::</span><span class="ruby-constant">JULIAN</span>) <span class="ruby-comment">#=> #<Date: 1582-10-05 ...></span>
</pre>
<div class="method-source-code" id="new_start-source">
<pre>static VALUE
d_lite_new_start(int argc, VALUE *argv, VALUE self)
{
VALUE vsg;
double sg;
rb_scan_args(argc, argv, "01", &vsg);
sg = DEFAULT_SG;
if (argc >= 1)
val2sg(vsg, sg);
return dup_obj_with_new_start(self, sg);
}</pre>
</div>
</div>
</div>
<div id="method-i-next" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
next → date
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns a date object denoting the following day.</p>
<div class="method-source-code" id="next-source">
<pre>static VALUE
d_lite_next(VALUE self)
{
return d_lite_next_day(0, (VALUE *)NULL, self);
}</pre>
</div>
</div>
</div>
<div id="method-i-next_day" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
next_day([n=1]) → date
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>This method is equivalent to d + n.</p>
<div class="method-source-code" id="next_day-source">
<pre>static VALUE
d_lite_next_day(int argc, VALUE *argv, VALUE self)
{
VALUE n;
rb_scan_args(argc, argv, "01", &n);
if (argc < 1)
n = INT2FIX(1);
return d_lite_plus(self, n);
}</pre>
</div>
</div>
</div>
<div id="method-i-next_month" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
next_month([n=1]) → date
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>This method is equivalent to d >> n.</p>
<p>See <a href="Date.html#method-i-3E-3E"><code>Date#>></code></a> for examples.</p>
<div class="method-source-code" id="next_month-source">
<pre>static VALUE
d_lite_next_month(int argc, VALUE *argv, VALUE self)
{
VALUE n;
rb_scan_args(argc, argv, "01", &n);
if (argc < 1)
n = INT2FIX(1);
return d_lite_rshift(self, n);
}</pre>
</div>
</div>
</div>
<div id="method-i-next_year" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
next_year([n=1]) → date
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>This method is equivalent to d >> (n * 12).</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>).<span class="ruby-identifier">next_year</span> <span class="ruby-comment">#=> #<Date: 2002-02-03 ...></span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2008</span>,<span class="ruby-value">2</span>,<span class="ruby-value">29</span>).<span class="ruby-identifier">next_year</span> <span class="ruby-comment">#=> #<Date: 2009-02-28 ...></span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2008</span>,<span class="ruby-value">2</span>,<span class="ruby-value">29</span>).<span class="ruby-identifier">next_year</span>(<span class="ruby-value">4</span>) <span class="ruby-comment">#=> #<Date: 2012-02-29 ...></span>
</pre>
<p>See also <a href="Date.html#method-i-3E-3E"><code>Date#>></code></a>.</p>
<div class="method-source-code" id="next_year-source">
<pre>static VALUE
d_lite_next_year(int argc, VALUE *argv, VALUE self)
{
VALUE n;
rb_scan_args(argc, argv, "01", &n);
if (argc < 1)
n = INT2FIX(1);
return d_lite_rshift(self, f_mul(n, INT2FIX(12)));
}</pre>
</div>
</div>
</div>
<div id="method-i-nth_kday-3F" class="method-detail ">
<div class="method-heading">
<span class="method-name">nth_kday?</span><span
class="method-args">(p1, p2)</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<div class="method-source-code" id="nth_kday-3F-source">
<pre>static VALUE
d_lite_nth_kday_p(VALUE self, VALUE n, VALUE k)
{
int rjd, ns;
get_d1(self);
if (NUM2INT(k) != m_wday(dat))
return Qfalse;
c_nth_kday_to_jd(m_year(dat), m_mon(dat),
NUM2INT(n), NUM2INT(k), m_virtual_sg(dat), /* !=m_sg() */
&rjd, &ns);
if (m_local_jd(dat) != rjd)
return Qfalse;
return Qtrue;
}</pre>
</div>
</div>
</div>
<div id="method-i-prev_day" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
prev_day([n=1]) → date
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>This method is equivalent to d - n.</p>
<div class="method-source-code" id="prev_day-source">
<pre>static VALUE
d_lite_prev_day(int argc, VALUE *argv, VALUE self)
{
VALUE n;
rb_scan_args(argc, argv, "01", &n);
if (argc < 1)
n = INT2FIX(1);
return d_lite_minus(self, n);
}</pre>
</div>
</div>
</div>
<div id="method-i-prev_month" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
prev_month([n=1]) → date
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>This method is equivalent to d << n.</p>
<p>See <a href="Date.html#method-i-3C-3C"><code>Date#<<</code></a> for examples.</p>
<div class="method-source-code" id="prev_month-source">
<pre>static VALUE
d_lite_prev_month(int argc, VALUE *argv, VALUE self)
{
VALUE n;
rb_scan_args(argc, argv, "01", &n);
if (argc < 1)
n = INT2FIX(1);
return d_lite_lshift(self, n);
}</pre>
</div>
</div>
</div>
<div id="method-i-prev_year" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
prev_year([n=1]) → date
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>This method is equivalent to d << (n * 12).</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>).<span class="ruby-identifier">prev_year</span> <span class="ruby-comment">#=> #<Date: 2000-02-03 ...></span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2008</span>,<span class="ruby-value">2</span>,<span class="ruby-value">29</span>).<span class="ruby-identifier">prev_year</span> <span class="ruby-comment">#=> #<Date: 2007-02-28 ...></span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2008</span>,<span class="ruby-value">2</span>,<span class="ruby-value">29</span>).<span class="ruby-identifier">prev_year</span>(<span class="ruby-value">4</span>) <span class="ruby-comment">#=> #<Date: 2004-02-29 ...></span>
</pre>
<p>See also <a href="Date.html#method-i-3C-3C"><code>Date#<<</code></a>.</p>
<div class="method-source-code" id="prev_year-source">
<pre>static VALUE
d_lite_prev_year(int argc, VALUE *argv, VALUE self)
{
VALUE n;
rb_scan_args(argc, argv, "01", &n);
if (argc < 1)
n = INT2FIX(1);
return d_lite_lshift(self, f_mul(n, INT2FIX(12)));
}</pre>
</div>
</div>
</div>
<div id="method-i-rfc2822" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
rfc2822 → string
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-heading">
<span class="method-callseq">
rfc822 → string
</span>
</div>
<div class="method-description">
<p>This method is equivalent to strftime('%a, %-d %b %Y %T %z').</p>
<div class="method-source-code" id="rfc2822-source">
<pre>static VALUE
d_lite_rfc2822(VALUE self)
{
return strftimev("%a, %-d %b %Y %T %z", self, set_tmx);
}</pre>
</div>
</div>
</div>
<div id="method-i-rfc3339" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
rfc3339 → string
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>This method is equivalent to strftime('%FT%T%:z').</p>
<div class="method-source-code" id="rfc3339-source">
<pre>static VALUE
d_lite_rfc3339(VALUE self)
{
return strftimev("%Y-%m-%dT%H:%M:%S%:z", self, set_tmx);
}</pre>
</div>
</div>
</div>
<div id="method-i-rfc822" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
rfc2822 → string
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-heading">
<span class="method-callseq">
rfc822 → string
</span>
</div>
<div class="method-description">
<p>This method is equivalent to strftime('%a, %-d %b %Y %T %z').</p>
<div class="method-source-code" id="rfc822-source">
<pre>static VALUE
d_lite_rfc2822(VALUE self)
{
return strftimev("%a, %-d %b %Y %T %z", self, set_tmx);
}</pre>
</div>
</div>
</div>
<div id="method-i-saturday-3F" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
saturday? → bool
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns true if the date is Saturday.</p>
<div class="method-source-code" id="saturday-3F-source">
<pre>static VALUE
d_lite_saturday_p(VALUE self)
{
get_d1(self);
return f_boolcast(m_wday(dat) == 6);
}</pre>
</div>
</div>
</div>
<div id="method-i-start" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
start → float
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the Julian day number denoting the day of calendar reform.</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>).<span class="ruby-identifier">start</span> <span class="ruby-comment">#=> 2299161.0</span>
<span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>,<span class="ruby-constant">Date</span><span class="ruby-operator">::</span><span class="ruby-constant">GREGORIAN</span>).<span class="ruby-identifier">start</span> <span class="ruby-comment">#=> -Infinity</span>
</pre>
<div class="method-source-code" id="start-source">
<pre>static VALUE
d_lite_start(VALUE self)
{
get_d1(self);
return DBL2NUM(m_sg(dat));
}</pre>
</div>
</div>
</div>
<div id="method-i-step" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
step(limit[, step=1]) → enumerator
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-heading">
<span class="method-callseq">
step(limit[, step=1]){|date| ...} → self
</span>
</div>
<div class="method-description">
<p>Iterates evaluation of the given block, which takes a date object. The limit should be a date object.</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>).<span class="ruby-identifier">step</span>(<span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">-1</span>,<span class="ruby-value">-1</span>)).<span class="ruby-identifier">select</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">d</span><span class="ruby-operator">|</span> <span class="ruby-identifier">d</span>.<span class="ruby-identifier">sunday?</span>}.<span class="ruby-identifier">size</span>
<span class="ruby-comment">#=> 52</span>
</pre>
<div class="method-source-code" id="step-source">
<pre>static VALUE
d_lite_step(int argc, VALUE *argv, VALUE self)
{
VALUE limit, step, date;
int c;
rb_scan_args(argc, argv, "11", &limit, &step);
if (argc < 2)
step = INT2FIX(1);
#if 0
if (f_zero_p(step))
rb_raise(rb_eArgError, "step can't be 0");
#endif
RETURN_ENUMERATOR(self, argc, argv);
date = self;
c = f_cmp(step, INT2FIX(0));
if (c < 0) {
while (FIX2INT(d_lite_cmp(date, limit)) >= 0) {
rb_yield(date);
date = d_lite_plus(date, step);
}
}
else if (c == 0) {
while (1)
rb_yield(date);
}
else /* if (c > 0) */ {
while (FIX2INT(d_lite_cmp(date, limit)) <= 0) {
rb_yield(date);
date = d_lite_plus(date, step);
}
}
return self;
}</pre>
</div>
</div>
</div>
<div id="method-i-strftime" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
strftime([format='%F']) → string
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Formats date according to the directives in the given format string. The directives begin with a percent (%) character. Any text not listed as a directive will be passed through to the output string.</p>
<p>A directive consists of a percent (%) character, zero or more flags, an optional minimum field width, an optional modifier, and a conversion specifier as follows.</p>
<pre>%<flags><width><modifier><conversion></pre>
<p>Flags:</p>
<pre>- don't pad a numerical output.
_ use spaces for padding.
0 use zeros for padding.
^ upcase the result string.
# change case.</pre>
<p>The minimum field width specifies the minimum width.</p>
<p>The modifiers are “E”, “O”, “:”, “::” and “:::”. “E” and “O” are ignored. No effect to result currently.</p>
<p>Format directives:</p>
<pre>Date (Year, Month, Day):
%Y - Year with century (can be negative, 4 digits at least)
-0001, 0000, 1995, 2009, 14292, etc.
%C - year / 100 (round down. 20 in 2009)
%y - year % 100 (00..99)
%m - Month of the year, zero-padded (01..12)
%_m blank-padded ( 1..12)
%-m no-padded (1..12)
%B - The full month name (``January'')
%^B uppercased (``JANUARY'')
%b - The abbreviated month name (``Jan'')
%^b uppercased (``JAN'')
%h - Equivalent to %b
%d - Day of the month, zero-padded (01..31)
%-d no-padded (1..31)
%e - Day of the month, blank-padded ( 1..31)
%j - Day of the year (001..366)
Time (Hour, Minute, Second, Subsecond):
%H - Hour of the day, 24-hour clock, zero-padded (00..23)
%k - Hour of the day, 24-hour clock, blank-padded ( 0..23)
%I - Hour of the day, 12-hour clock, zero-padded (01..12)
%l - Hour of the day, 12-hour clock, blank-padded ( 1..12)
%P - Meridian indicator, lowercase (``am'' or ``pm'')
%p - Meridian indicator, uppercase (``AM'' or ``PM'')
%M - Minute of the hour (00..59)
%S - Second of the minute (00..60)
%L - Millisecond of the second (000..999)
%N - Fractional seconds digits, default is 9 digits (nanosecond)
%3N millisecond (3 digits) %15N femtosecond (15 digits)
%6N microsecond (6 digits) %18N attosecond (18 digits)
%9N nanosecond (9 digits) %21N zeptosecond (21 digits)
%12N picosecond (12 digits) %24N yoctosecond (24 digits)
Time zone:
%z - Time zone as hour and minute offset from UTC (e.g. +0900)
%:z - hour and minute offset from UTC with a colon (e.g. +09:00)
%::z - hour, minute and second offset from UTC (e.g. +09:00:00)
%:::z - hour, minute and second offset from UTC
(e.g. +09, +09:30, +09:30:30)
%Z - Equivalent to %:z (e.g. +09:00)
Weekday:
%A - The full weekday name (``Sunday'')
%^A uppercased (``SUNDAY'')
%a - The abbreviated name (``Sun'')
%^a uppercased (``SUN'')
%u - Day of the week (Monday is 1, 1..7)
%w - Day of the week (Sunday is 0, 0..6)
ISO 8601 week-based year and week number:
The week 1 of YYYY starts with a Monday and includes YYYY-01-04.
The days in the year before the first week are in the last week of
the previous year.
%G - The week-based year
%g - The last 2 digits of the week-based year (00..99)
%V - Week number of the week-based year (01..53)
Week number:
The week 1 of YYYY starts with a Sunday or Monday (according to %U
or %W). The days in the year before the first week are in week 0.
%U - Week number of the year. The week starts with Sunday. (00..53)
%W - Week number of the year. The week starts with Monday. (00..53)
Seconds since the Unix Epoch:
%s - Number of seconds since 1970-01-01 00:00:00 UTC.
%Q - Number of milliseconds since 1970-01-01 00:00:00 UTC.
Literal string:
%n - Newline character (\n)
%t - Tab character (\t)
%% - Literal ``%'' character
Combination:
%c - date and time (%a %b %e %T %Y)
%D - Date (%m/%d/%y)
%F - The ISO 8601 date format (%Y-%m-%d)
%v - VMS date (%e-%b-%Y)
%x - Same as %D
%X - Same as %T
%r - 12-hour time (%I:%M:%S %p)
%R - 24-hour time (%H:%M)
%T - 24-hour time (%H:%M:%S)
%+ - date(1) (%a %b %e %H:%M:%S %Z %Y)</pre>
<p>This method is similar to the strftime() function defined in ISO C and POSIX. Several directives (%a, %A, %b, %B, %c, %p, %r, %x, %X, %E*, %O* and %Z) are locale dependent in the function. However, this method is locale independent. So, the result may differ even if the same format string is used in other systems such as C. It is good practice to avoid %x and %X because there are corresponding locale independent representations, %D and %T.</p>
<p>Examples:</p>
<pre class="ruby"><span class="ruby-identifier">d</span> = <span class="ruby-constant">DateTime</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2007</span>,<span class="ruby-value">11</span>,<span class="ruby-value">19</span>,<span class="ruby-value">8</span>,<span class="ruby-value">37</span>,<span class="ruby-value">48</span>,<span class="ruby-string">"-06:00"</span>)
<span class="ruby-comment">#=> #<DateTime: 2007-11-19T08:37:48-0600 ...></span>
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">strftime</span>(<span class="ruby-string">"Printed on %m/%d/%Y"</span>) <span class="ruby-comment">#=> "Printed on 11/19/2007"</span>
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">strftime</span>(<span class="ruby-string">"at %I:%M%p"</span>) <span class="ruby-comment">#=> "at 08:37AM"</span>
</pre>
<p>Various ISO 8601 formats:</p>
<pre>%Y%m%d => 20071119 Calendar date (basic)
%F => 2007-11-19 Calendar date (extended)
%Y-%m => 2007-11 Calendar date, reduced accuracy, specific month
%Y => 2007 Calendar date, reduced accuracy, specific year
%C => 20 Calendar date, reduced accuracy, specific century
%Y%j => 2007323 Ordinal date (basic)
%Y-%j => 2007-323 Ordinal date (extended)
%GW%V%u => 2007W471 Week date (basic)
%G-W%V-%u => 2007-W47-1 Week date (extended)
%GW%V => 2007W47 Week date, reduced accuracy, specific week (basic)
%G-W%V => 2007-W47 Week date, reduced accuracy, specific week (extended)
%H%M%S => 083748 Local time (basic)
%T => 08:37:48 Local time (extended)
%H%M => 0837 Local time, reduced accuracy, specific minute (basic)
%H:%M => 08:37 Local time, reduced accuracy, specific minute (extended)
%H => 08 Local time, reduced accuracy, specific hour
%H%M%S,%L => 083748,000 Local time with decimal fraction, comma as decimal sign (basic)
%T,%L => 08:37:48,000 Local time with decimal fraction, comma as decimal sign (extended)
%H%M%S.%L => 083748.000 Local time with decimal fraction, full stop as decimal sign (basic)
%T.%L => 08:37:48.000 Local time with decimal fraction, full stop as decimal sign (extended)
%H%M%S%z => 083748-0600 Local time and the difference from UTC (basic)
%T%:z => 08:37:48-06:00 Local time and the difference from UTC (extended)
%Y%m%dT%H%M%S%z => 20071119T083748-0600 Date and time of day for calendar date (basic)
%FT%T%:z => 2007-11-19T08:37:48-06:00 Date and time of day for calendar date (extended)
%Y%jT%H%M%S%z => 2007323T083748-0600 Date and time of day for ordinal date (basic)
%Y-%jT%T%:z => 2007-323T08:37:48-06:00 Date and time of day for ordinal date (extended)
%GW%V%uT%H%M%S%z => 2007W471T083748-0600 Date and time of day for week date (basic)
%G-W%V-%uT%T%:z => 2007-W47-1T08:37:48-06:00 Date and time of day for week date (extended)
%Y%m%dT%H%M => 20071119T0837 Calendar date and local time (basic)
%FT%R => 2007-11-19T08:37 Calendar date and local time (extended)
%Y%jT%H%MZ => 2007323T0837Z Ordinal date and UTC of day (basic)
%Y-%jT%RZ => 2007-323T08:37Z Ordinal date and UTC of day (extended)
%GW%V%uT%H%M%z => 2007W471T0837-0600 Week date and local time and difference from UTC (basic)
%G-W%V-%uT%R%:z => 2007-W47-1T08:37-06:00 Week date and local time and difference from UTC (extended)</pre>
<p>See also strftime(3) and <a href="Date.html#method-c-strptime"><code>::strptime</code></a>.</p>
<div class="method-source-code" id="strftime-source">
<pre>static VALUE
d_lite_strftime(int argc, VALUE *argv, VALUE self)
{
return date_strftime_internal(argc, argv, self,
"%Y-%m-%d", set_tmx);
}</pre>
</div>
</div>
</div>
<div id="method-i-succ" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
succ → date
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns a date object denoting the following day.</p>
<div class="method-source-code" id="succ-source">
<pre>static VALUE
d_lite_next(VALUE self)
{
return d_lite_next_day(0, (VALUE *)NULL, self);
}</pre>
</div>
</div>
</div>
<div id="method-i-sunday-3F" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
sunday? → bool
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns true if the date is Sunday.</p>
<div class="method-source-code" id="sunday-3F-source">
<pre>static VALUE
d_lite_sunday_p(VALUE self)
{
get_d1(self);
return f_boolcast(m_wday(dat) == 0);
}</pre>
</div>
</div>
</div>
<div id="method-i-thursday-3F" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
thursday? → bool
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns true if the date is Thursday.</p>
<div class="method-source-code" id="thursday-3F-source">
<pre>static VALUE
d_lite_thursday_p(VALUE self)
{
get_d1(self);
return f_boolcast(m_wday(dat) == 4);
}</pre>
</div>
</div>
</div>
<div id="method-i-to_date" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
to_date → self
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns self.</p>
<div class="method-source-code" id="to_date-source">
<pre>static VALUE
date_to_date(VALUE self)
{
return self;
}</pre>
</div>
</div>
</div>
<div id="method-i-to_datetime" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
to_datetime → datetime
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns a <a href="DateTime.html"><code>DateTime</code></a> object which denotes self.</p>
<div class="method-source-code" id="to_datetime-source">
<pre>static VALUE
date_to_datetime(VALUE self)
{
get_d1a(self);
if (simple_dat_p(adat)) {
VALUE new = d_lite_s_alloc_simple(cDateTime);
{
get_d1b(new);
bdat->s = adat->s;
return new;
}
}
else {
VALUE new = d_lite_s_alloc_complex(cDateTime);
{
get_d1b(new);
bdat->c = adat->c;
bdat->c.df = 0;
RB_OBJ_WRITE(new, &bdat->c.sf, INT2FIX(0));
#ifndef USE_PACK
bdat->c.hour = 0;
bdat->c.min = 0;
bdat->c.sec = 0;
#else
bdat->c.pc = PACK5(EX_MON(adat->c.pc), EX_MDAY(adat->c.pc),
0, 0, 0);
bdat->c.flags |= HAVE_DF | HAVE_TIME;
#endif
return new;
}
}
}</pre>
</div>
</div>
</div>
<div id="method-i-to_json" class="method-detail ">
<div class="method-heading">
<span class="method-name">to_json</span><span
class="method-args">(*args)</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Stores class name (<a href="Date.html"><code>Date</code></a>) with Julian year <code>y</code>, month <code>m</code>, day <code>d</code> and Day of Calendar Reform <code>sg</code> as <a href="JSON.html"><code>JSON</code></a> string</p>
<div class="method-source-code" id="to_json-source">
<pre><span class="ruby-comment"># File ext/json/lib/json/add/date.rb, line 31</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">to_json</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
<span class="ruby-identifier">as_json</span>.<span class="ruby-identifier">to_json</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
<span class="ruby-keyword">end</span></pre>
</div>
</div>
</div>
<div id="method-i-to_s" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
to_s → string
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns a string in an ISO 8601 format. (This method doesn't use the expanded representations.)</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>).<span class="ruby-identifier">to_s</span> <span class="ruby-comment">#=> "2001-02-03"</span>
</pre>
<div class="method-source-code" id="to_s-source">
<pre>static VALUE
d_lite_to_s(VALUE self)
{
return strftimev("%Y-%m-%d", self, set_tmx);
}</pre>
</div>
</div>
</div>
<div id="method-i-to_time" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
to_time → time
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns a <a href="Time.html"><code>Time</code></a> object which denotes self. If self is a julian date, convert it to a gregorian date before converting it to <a href="Time.html"><code>Time</code></a>.</p>
<div class="method-source-code" id="to_time-source">
<pre>static VALUE
date_to_time(VALUE self)
{
get_d1a(self);
if (m_julian_p(adat)) {
VALUE tmp = d_lite_gregorian(self);
get_d1b(tmp);
adat = bdat;
}
return f_local3(rb_cTime,
m_real_year(adat),
INT2FIX(m_mon(adat)),
INT2FIX(m_mday(adat)));
}</pre>
</div>
</div>
</div>
<div id="method-i-tuesday-3F" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
tuesday? → bool
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns true if the date is Tuesday.</p>
<div class="method-source-code" id="tuesday-3F-source">
<pre>static VALUE
d_lite_tuesday_p(VALUE self)
{
get_d1(self);
return f_boolcast(m_wday(dat) == 2);
}</pre>
</div>
</div>
</div>
<div id="method-i-upto" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
upto(max) → enumerator
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-heading">
<span class="method-callseq">
upto(max){|date| ...} → self
</span>
</div>
<div class="method-description">
<p>This method is equivalent to step(max, 1){|date| …}.</p>
<div class="method-source-code" id="upto-source">
<pre>static VALUE
d_lite_upto(VALUE self, VALUE max)
{
VALUE date;
RETURN_ENUMERATOR(self, 1, &max);
date = self;
while (FIX2INT(d_lite_cmp(date, max)) <= 0) {
rb_yield(date);
date = d_lite_plus(date, INT2FIX(1));
}
return self;
}</pre>
</div>
</div>
</div>
<div id="method-i-wday" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
wday → fixnum
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the day of week (0-6, Sunday is zero).</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>).<span class="ruby-identifier">wday</span> <span class="ruby-comment">#=> 6</span>
</pre>
<div class="method-source-code" id="wday-source">
<pre>static VALUE
d_lite_wday(VALUE self)
{
get_d1(self);
return INT2FIX(m_wday(dat));
}</pre>
</div>
</div>
</div>
<div id="method-i-wednesday-3F" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
wednesday? → bool
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns true if the date is Wednesday.</p>
<div class="method-source-code" id="wednesday-3F-source">
<pre>static VALUE
d_lite_wednesday_p(VALUE self)
{
get_d1(self);
return f_boolcast(m_wday(dat) == 3);
}</pre>
</div>
</div>
</div>
<div id="method-i-xmlschema" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
iso8601 → string
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-heading">
<span class="method-callseq">
xmlschema → string
</span>
</div>
<div class="method-description">
<p>This method is equivalent to strftime('%F').</p>
<div class="method-source-code" id="xmlschema-source">
<pre>static VALUE
d_lite_iso8601(VALUE self)
{
return strftimev("%Y-%m-%d", self, set_tmx);
}</pre>
</div>
</div>
</div>
<div id="method-i-yday" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
yday → fixnum
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the day of the year (1-366).</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>).<span class="ruby-identifier">yday</span> <span class="ruby-comment">#=> 34</span>
</pre>
<div class="method-source-code" id="yday-source">
<pre>static VALUE
d_lite_yday(VALUE self)
{
get_d1(self);
return INT2FIX(m_yday(dat));
}</pre>
</div>
</div>
</div>
<div id="method-i-year" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
year → integer
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the year.</p>
<pre class="ruby"><span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2001</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>).<span class="ruby-identifier">year</span> <span class="ruby-comment">#=> 2001</span>
(<span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">1</span>,<span class="ruby-value">1</span>,<span class="ruby-value">1</span>) <span class="ruby-operator">-</span> <span class="ruby-value">1</span>).<span class="ruby-identifier">year</span> <span class="ruby-comment">#=> 0</span>
</pre>
<div class="method-source-code" id="year-source">
<pre>static VALUE
d_lite_year(VALUE self)
{
get_d1(self);
return m_real_year(dat);
}</pre>
</div>
</div>
</div>
</section>
<section id="private-instance-5Buntitled-5D-method-details" class="method-section">
<header>
<h3>Private Instance Methods</h3>
</header>
<div id="method-i-hour" class="method-detail ">
<div class="method-heading">
<span class="method-name">hour</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<div class="method-source-code" id="hour-source">
<pre>static VALUE
d_lite_zero(VALUE x)
{
return INT2FIX(0);
}</pre>
</div>
</div>
</div>
<div id="method-i-min" class="method-detail ">
<div class="method-heading">
<span class="method-name">min</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<div class="method-source-code" id="min-source">
<pre>static VALUE
d_lite_zero(VALUE x)
{
return INT2FIX(0);
}</pre>
</div>
</div>
</div>
<div id="method-i-minute" class="method-detail ">
<div class="method-heading">
<span class="method-name">minute</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<div class="method-source-code" id="minute-source">
<pre>static VALUE
d_lite_zero(VALUE x)
{
return INT2FIX(0);
}</pre>
</div>
</div>
</div>
<div id="method-i-sec" class="method-detail ">
<div class="method-heading">
<span class="method-name">sec</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<div class="method-source-code" id="sec-source">
<pre>static VALUE
d_lite_zero(VALUE x)
{
return INT2FIX(0);
}</pre>
</div>
</div>
</div>
<div id="method-i-second" class="method-detail ">
<div class="method-heading">
<span class="method-name">second</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<div class="method-source-code" id="second-source">
<pre>static VALUE
d_lite_zero(VALUE x)
{
return INT2FIX(0);
}</pre>
</div>
</div>
</div>
<div id="method-i-wnum0" class="method-detail ">
<div class="method-heading">
<span class="method-name">wnum0</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<div class="method-source-code" id="wnum0-source">
<pre>static VALUE
d_lite_wnum0(VALUE self)
{
get_d1(self);
return INT2FIX(m_wnum0(dat));
}</pre>
</div>
</div>
</div>
<div id="method-i-wnum1" class="method-detail ">
<div class="method-heading">
<span class="method-name">wnum1</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<div class="method-source-code" id="wnum1-source">
<pre>static VALUE
d_lite_wnum1(VALUE self)
{
get_d1(self);
return INT2FIX(m_wnum1(dat));
}</pre>
</div>
</div>
</div>
</section>
</section>
</main>
<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.2.1.1.
<p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
</footer>