Billing Period
May 18, 2018
I’m not sure of the origin of today’s exercise, but given the contrived nature of the calculation, I suspect it’s a programming exercise for beginning programming students:
Our merchants receive “weekly” invoices, following these rules:
- Each Saturday marks the beginning of a new billing period.
- Each 1st of a month marks the begining of a new billing period.
- Within a year, billing periods are numbered consecutively, starting with billing period 1 on January 1st.
Thus, a billing period can be referenced by a year and period number.
Your task is to write a program that calculates the billing period for a given date. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.
Mumps/Cache version
What ?
Mumps/Cache version, with comments and expanded commands, etc
Here’s a solution in C.
Example:
In Ruby.
Output:
2018-01-01 -> 1
2018-01-03 -> 1
2018-01-06 -> 2
2018-01-10 -> 2
2018-01-26 -> 4
2018-02-01 -> 6
2018-05-18 -> 24