Menu

Leaf Dates
Handling Dates with Leaf Custom Dates

Overview

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

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

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);

getTimeZone

This method returns the current time zone of the user

$timeZone = $date->getTimeZone();

now

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();

setTimeZone

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

GetDateFromTimeStamp

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

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

GetMonthFromNumber

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

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

GetDayFromNumber

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

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

GetEnglishDateFromTimeStamp

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

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

GetEnglishTimeStampFromTimeStamp

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

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

GetTimeFromTimeStamp

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
Request
Response