Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

mrzen/php-date-test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MrZen PHP Test

Calculate the difference between two given dates without using any of the built in PHP date functions or objects.

Assumptions

  • Dates will be provided in the format “YYYY/MM/DD” for example “2015/03/21”.
  • All dates will be based on the Gregorian calendar.
  • There should be a single interface for calculating the difference in the format:
$difference = MyDate::diff($start, $end);
  • The return value should be an object in the format:
stdClass {
    int   $years,        // The number of years between the two dates.
    int   $months,       // The number of years between the two dates.
    int   $days,         // The number of days between the two dates less the months and the years.
    int   $total_days,   // The total days between the two dates including the months and years.
    bool  $invert        // true if the the difference is negative (i.e. $start > $end).
}
  • You are free to structure the rest of your code however you like and will be asked to explain your decisions.
  • Basic unit tests are provided however you are free to add tests to cover anything additional you feel is required.

Requirements

Getting Started

  • Fork and clone this repository
  • From the root run composer install
  • Start with the src/MyDate.php file and code until you are satisfied
  • ZIP up your solution and send it in

Testing

Basic unit tests are provided in the tests folder. To run these steps simply run:

phpunit --bootstrap= src/autoload.php tests/MyDateTest.php

Notes

If you create new class files be sure to update the src/autoload.php file to load these for the tests.

About

Php Date Diff Test for Back-end Developers

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages