Changes

Jump to: navigation, search

OPS435 Assignment 1 for Section B

2,510 bytes removed, 23:34, 8 October 2020
Script structure and sample template
The following is a brief description of each function:
 
* The dbda() function should be the main function of your script. The dbda() function will take two dates in "DD-MM-YYYY" format, and return an integer that corresponds to the number of days between the given dates. If the start date is earlier than the stop date, the number is positive. If start date is later than the stop date, the number is negative. Your dbda() function should delegate the actual calculation of the target date to either the after() function or the before() function.
* The today() function will be called if the user has not specified a second argument. It will return '''your Linux computer's local time''' in the format DD-MM-YYYY. Hint: you may need to read man pages for a shell command in order to return a usable date. You may also use string formatting to modify output.
* The before() function will take a date in "DD-MM-YYYY" format and return the date of the previous day in the same format.
* The after() function will take a date in "DD-MM-YYYY" format and return the date of the next day in the same format. Next paragraph is a sample python code for the after() function. To earn the maximum possible mark for the assignment, you should modify the sample after() function to make use of the days_in_mon() function.
* The leap_year() function will take a year in "YYYY" format, and return True if the given year is a leap year, otherwise return False.
* The size_check() function
* The valid_date() function will take a date in "DD-MM-YYYY" format, and return True if the given date is a valid date, otherwise return False plus an appropriate status message. The valid_date() function should make use of the days_in_mon() function.
* The days_in_mon() function will take a year in "YYYY" format, and return a dictionary object which contains the total number of days in each month for the given year. The days_in_mon() function should make use of the leap_year() function.
* The usage() function will take no argument and return a string describing the usage of the script.
 
=== Sample code for the after() function ===
<pre>
# Return the date in DD-MM-YYYY after the given day
#
def after(today):
if len(today) != 10:
return '00-00-0000'
else:
str_day, str_month, str_year = today.split('-')
year = int(str_year)
month = int(str_month)
day = int(str_day)
 
lyear = year % 4
if lyear == 0:
feb_max = 29 # this is a leap year
else:
feb_max = 28 # this is not a leap year
 
lyear = year % 100
if lyear == 0:
feb_max = 28 # this is not a leap year
 
lyear = year % 400
if lyear == 0:
feb_max = 29 # this is a leap year
 
tmp_day = day + 1 # next day
 
mon_max = { 1:31, 2:feb_max, 3:31, 4:30, 5:31, 6:30, 7:31, 8:31, 9:30, 10:31, 11:30, 12:31}
if tmp_day > mon_max[month]:
to_day = tmp_day % mon_max[month] # if tmp_day > this month's max, reset to 1
tmp_month = month + 1
else:
to_day = tmp_day
tmp_month = month + 0
 
if tmp_month > 12:
to_month = 1
year = year + 1
else:
to_month = tmp_month + 0
 
next_date = str(to_day)+"-"+str(to_month).zfill(2)+"-"+str(year).zfill(2)
return next_date
</pre>
= Rubric =
1,760
edits

Navigation menu