/datecounter

An exercise in date calculations

Primary LanguagePHP

A Date Calculator Exercise

Pre-requisites

LAMP stack

Installation

Clone the repository visit the webroot in your browser

The Challenge

  1. Find out the number of days between two datetime parameters.
  2. Find out the number of weekdays between two datetime parameters.
  3. Find out the number of complete weeks between two datetime parameters.
  4. Accept a third parameter to convert the result of (1, 2 or 3) into one of seconds, minutes, hours, years.
  5. Allow the specification of a timezone for comparison of input parameters from different timezones.

The Solution

  1. PHP / Web front-end using JS calendar plug-in
  2. Submit form (no validation!) to perform calculation
  3. Instantiate DateCalulator Class
  4. Call relevant functions

Run tests

  1. run composer install
  2. run vendor/phpunit/phpunit/phpunit tests/DateCalculatorTest.php

Possible improvements

  1. Further Testing
  2. General refactor
  3. PHPDoc
  4. Re-visit algorithm to improve performance
  5. Improve interface
  6. Implement code re-use for calculating different units
  7. PHPUnit tests