Find the last Sunday of each month: Difference between revisions

Content added Content deleted
(Added Elixir)
m (Added the Sidef language)
Line 1,756: Line 1,756:
{{out}} when called with <tt>s7 rosetta/lastWeekdayInMonth 7 2013</tt>:
{{out}} when called with <tt>s7 rosetta/lastWeekdayInMonth 7 2013</tt>:
<pre>
<pre>
2013-01-27
2013-02-24
2013-03-31
2013-04-28
2013-05-26
2013-06-30
2013-07-28
2013-08-25
2013-09-29
2013-10-27
2013-11-24
2013-12-29
</pre>

=={{header|Sidef}}==
<lang ruby>require 'DateTime';

var (year=2015) = ARGV»to_i»()...;

range(1, 12).each { |i|
var date = %s'DateTime'.last_day_of_month(
year => year,
month => i
);

while (date.dow != 7) {
[date.subtract(days => 1)] » \date;
};

say date.ymd;
}</lang>
{{out}}
<pre>
$ sidef last_sunday.sf 2013
2013-01-27
2013-01-27
2013-02-24
2013-02-24