Exercises: Date and Time Processing
Exercise 21.1: Date Validator
Write a comprehensive date validation program that accepts a date string in YYYYMMDD format and validates: 1. All characters are numeric 2. Year is in range 1900-2099 3. Month is in range 01-12 4. Day is valid for the given month 5. Leap year February is handled correctly (test with 2024, 2023, 1900, 2000)
Display specific error messages for each type of validation failure.
Exercise 21.2: Date Calculator
Write a program that accepts two dates and computes: 1. The number of calendar days between them 2. The number of complete weeks between them 3. The approximate number of months (using year/month components) 4. Which date is earlier (handle both orderings) 5. The midpoint date between the two dates
Exercise 21.3: Leap Year Explorer
Write a program that: 1. Lists all leap years from 1900 to 2100 2. Correctly identifies 1900 as NOT a leap year and 2000 AS a leap year 3. Counts the total number of leap years in the range 4. For a given year, displays whether it is a leap year and explains why (divisible by 4, 100, or 400)
Exercise 21.4: Aging Report Generator
Create an aging report program that: 1. Reads a file of invoice records (invoice number, date, amount) 2. Computes the age of each invoice in days from today 3. Assigns each invoice to an aging bucket (Current, 1-30, 31-60, 61-90, 91-120, Over 120) 4. Produces a report showing each bucket's count and total amount 5. Flags invoices over 90 days with a warning indicator
Exercise 21.5: Business Day Calculator
Build a business day calculator that: 1. Stores a holiday table for the current year (at least 10 US federal holidays) 2. Accepts a start date and number of business days to add 3. Computes the result date, skipping weekends and holidays 4. Displays each skipped non-business day with its reason (weekend/holiday name) 5. Also handles subtracting business days (counting backward)
Exercise 21.6: Statement Period Calculator
Implement GlobalBank's statement period logic: 1. Accept a cycle day (1-28) and a current date 2. Compute the statement start date (previous month's cycle day + 1) and end date (current month's cycle day) 3. Handle month-end adjustments (cycle day 31 on a 30-day month) 4. Handle year boundaries (January statement period starts in December) 5. Display the statement period and the number of days it covers
Exercise 21.7: MedClaim Timely Filing Checker
Write a timely filing validation program that: 1. Reads a batch of claim records (claim ID, service date, received date, payer code) 2. Looks up the payer's timely filing limit from a table (90, 120, 180, or 365 days) 3. Computes days since service for each claim 4. Reports: Timely, Warning (within 30 days of deadline), or Untimely 5. Produces summary statistics: total claims, timely count, untimely count, untimely dollar amount
Exercise 21.8: Date Format Converter
Write a program that converts dates between multiple formats: 1. YYYYMMDD (ISO numeric) 2. MM/DD/YYYY (US) 3. DD-MM-YYYY (European) 4. YYYY-DDD (Julian) 5. "Month DD, YYYY" (written: "June 15, 2024")
Accept input in any of the five formats and display in all five formats. Use a month name table for written format conversion.
Exercise 21.9: Timezone Converter
Build a timezone converter that: 1. Gets the local time using FUNCTION CURRENT-DATE 2. Displays the local time and GMT offset 3. Converts to GMT/UTC 4. Converts to three other time zones (EST, CST, PST) using hardcoded offsets 5. Handles day-boundary crossings (e.g., 11 PM EST = 4 AM next day GMT)
Exercise 21.10: Challenge — Y2K Windowing Simulator
Write a program that demonstrates the Y2K problem and both fix approaches: 1. Define 10 dates using 2-digit years spanning 1985-2015 2. Sort them using 2-digit years and display the (incorrect) result 3. Apply date windowing (pivot year 50) and re-sort — display the corrected result 4. Apply date expansion (convert to 4-digit years) and re-sort — display the corrected result 5. Demonstrate a case where windowing produces a different result than expansion (hint: dates near the pivot year)