Leaf Dates
Handling Dates with Leaf Custom Dates


Using Leaf Dates

Just like all of Leaf's other functionality, the dates module will also have to be imported. In v1.3, the Date object has been renamed to Date

$date = new Leaf\Core\Date();
After this, all the Date methods will be available to us:

Date Function

Basically, Date just gives you methods to manipulate the date and time, faster that DateTime() would allow. Let's take a look at these methods.


randomTimestamp as the name implies, generates a new random timestamp. This method was Timestamp in the previous version.

$timestamp = $date->randomTimestamp();
randomTimestamp is already configured to give a wide range of dates, but if you ever feel like customizing this range, just pass in params for randomTimestamp
randomTimestamp($start, $end);


randomDate as the name implies, generates a new random date. This method is a new addition to the Date object.

$timestamp = $date->randomDate();
Just like randomTimestamp, randomDate is already configured with a wide range of dates, but you can set a specific range with:
randomDate($start, $end);


This method returns the current time zone of the user

$timeZone = $date->getTimeZone();


now returns the timestamp of the current date and time. Now will return the date based on the timezone, therefore, it is recommended to use now together with setTimeZone

$date->setTimeZone('Africa/Accra'); $timeZone = $date->now();


This method sets the timezone sets the timezone of the user. This method takes in one optional parameter, which is the timezone to set. If nothing is passed in there, the timezone is set to a GMT timezone.

$timeZone = $date->setTimeZone('Timezone');
You can get a list of all PHP supported timezones here


This method gets the date in YYYY-MM-DD format from an existing timestamp

$parsedDate = $date->GetDateFromTimeStamp($timestamp);


This gets the month in words from a number (1-12)

$month = $date->GetMonthFromNumber($number);


This gets the day in words from a number (1-7)

$month = $date->GetDayFromNumber($number);


This gets the date in the format (MM DD, YYYY) from an existing timestamp

$parsedDate = $date->GetEnglishDateFromTimeStamp($timestamp);


This gets the date in the format (DD MM, YYYY HH:MM:SS) from a timestamp

$parsedDate = $date->GetEnglishTimeStampFromTimeStamp($timestamp);


This gets the time in the format (HH:MM:SS) from a timestamp

$parsedDate = $date->GetTimeFromTimeStamp($timestamp);

Next Steps

Re-routing to index.php
Simple Routing