Last Friday of each month: Difference between revisions

→‎{{header|Ada}}: implemented a general solution where the weekday is part of the input, also the previous solution was wrong if Feb. 29 was a Friday (in a leap year, of course)
(changed wordcase of "find last sunday of each month" to match actual title of same. -- ~~~~)
(→‎{{header|Ada}}: implemented a general solution where the weekday is part of the input, also the previous solution was wrong if Feb. 29 was a Friday (in a leap year, of course))
Line 24:
 
=={{header|Ada}}==
 
<lang Ada>with Ada.Text_IO; use Ada.Text_IO;
Uses GNAT.
with Ada.Calendar; use Ada.Calendar;
 
with Ada.Command_Line; use Ada.Command_Line;
<lang Ada>with Ada.Text_IO, GNAT.Calendar.Formatting; useTime_IO, Ada.Calendar.Formatting;Command_Line,
Ada.Calendar.Formatting, Ada.Calendar.Arithmetic;
procedure Fridays is
 
T : Ada.Calendar.Time;
procedure Last_Weekday_In_Month is
Year : Year_Number := Integer'Value (Argument (1));
MLength : constant array (1 .. 12) of Positive :=
Tprocedure Put_Line(T: Ada.Calendar.Time;) is
(4 | 6 | 9 | 11 => 30, 2 => 28, others => 31);
use GNAT.Calendar.Time_IO;
begin
Ada.Text_IO.Put_Line (Image (Date => T)(1, ..Picture 10=> ISO_Date)); exit;
end Put_Line;
with use Ada.Calendar; use, Ada.Calendar.Arithmetic;
subtype Day_Name is Formatting.Day_Name; use type Formatting.Day_Name;
T, Selected : Time;
Weekday: Day_Name := Day_Name'Value(Ada.Command_Line.Argument (1));
Year : Year_Number := Integer'Value (Ada.Command_Line.Argument (12));
begin
for monthMonth in 1 .. 12 loop
T := Time_Of (Year => Year, Month => Month, Day => 01);
for day in reverse 1 .. MLength (month) loop
T :=while Ada.Calendar.Time_Of Month(Year,T) month,= day);Month loop
if Formatting.Day_Of_Week (T) = FridayWeekday then
Selected := T;
Put_Line (Image (Date => T)(1 .. 10)); exit;
end if;
T := T + Day_Count(1);
end loop;
Put_Line(Selected);
end loop;
end FridaysLast_Weekday_In_Month;</lang>
{{out}}
<pre>>./fridayslast_weekday_in_month friday 2012
2012-01-27
2012-02-24
Anonymous user