Last Friday of each month: Difference between revisions

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