Last Friday of each month: Difference between revisions
Content added Content deleted
mNo edit summary |
|||
Line 2,142: | Line 2,142: | ||
=={{header|Nanoquery}}== |
=={{header|Nanoquery}}== |
||
<lang Nanoquery>import Nanoquery.Util |
<lang Nanoquery>import Nanoquery.Util |
||
// a function to check if a year is a leap year |
// a function to check if a year is a leap year |
||
def isLeapYear( |
def isLeapYear(year) |
||
if ( |
if (year % 100 = 0) |
||
return ( |
return (year % 400 = 0) |
||
else |
else |
||
return ( |
return (year % 4 = 0) |
||
end |
end |
||
end |
end |
||
// a function to format 1-digit numbers as "0x" |
// a function to format 1-digit numbers as "0x" |
||
def |
def form(num) |
||
if ( |
if (num > 9) |
||
return str( |
return str(num) |
||
else |
else |
||
return "0" + str( |
return "0" + str(num) |
||
end |
end |
||
end |
end |
||
// get a year from the console |
// get a year from the console |
||
print "enter year: " |
print "enter year: " |
||
year = int(input()) |
|||
// build a list of the expected amount of days for each month |
// build a list of the expected amount of days for each month |
||
⚫ | |||
$days = list(12) |
|||
append $days 31 |
|||
if isLeapYear($year) |
if isLeapYear($year) |
||
days[1] = 29 |
|||
else |
|||
append $days 28 |
|||
end |
end |
||
// march - december |
|||
⚫ | |||
// loop through each month |
// loop through each month |
||
for |
for month in range(1, len($days)) |
||
// loop through each day of the month |
// loop through each day of the month |
||
friday = null |
|||
for |
for day in range(1, days[month - 1]) |
||
// create a date object for this date |
// create a date object for this date |
||
date = new(Date) |
|||
date.setYear(year).setMonth(month).setDay(day) |
|||
// check if it's a friday |
// check if it's a friday |
||
if ( |
if (date.getDayOfWeek() = "Friday") |
||
// if it is, keep it |
// if it is, keep it |
||
friday = new(Date, date) |
|||
end |
end |
||
end for |
end for |
||
// display the last friday found |
// display the last friday found |
||
print |
print friday.getYear() + "-" |
||
print |
print form(friday.getMonth()) + "-" |
||
println |
println form(friday.getDay()) |
||
end</lang> |
end</lang> |
||