Function __global->to_epoch_interval_index

Definitions

sources/temporal.php

  • Convert an epoch timestamp to an epoch interval index.In other words, this will return the number of *full* $intervals from $epoch to $timestamp. This function is handy for accurately calculating date durations; put the "from" as $epoch, and "to" as $timestamp.Note that when using Unix epoch, weeks start on a Thursday given that is when epoch starts. Set $epoch to 345600 to start on a Monday, or 259200 for Sunday.
  • Visibility: public
  • Is abstract?: No
  • Is static?: No
  • Is final?: No
  • Returns: int

Parameters

Name Type Passed by reference? Variadic? Default Set Range Description
$timestamp TIME No No required parameter N/A N/A The timestamp which we want to convert to an interval index
$interval ID_TEXT No No required parameter minutes, hours, days, weeks, months, years N/A The interval we want to use
$epoch TIME No No 0 N/A N/A Define our own epoch relative to the Unix epoch to use in this calculation instead

Returns

  • The index of the interval at which $timestamp is located
  • Type: integer
  • Set: N/A
  • Range: N/A

Preview

Code (PHP)

/**
 * Convert an epoch timestamp to an epoch interval index.In other words, this will return the number of *full* $intervals from $epoch to $timestamp. This function is handy for accurately calculating date durations; put the "from" as $epoch, and "to" as $timestamp.Note that when using Unix epoch, weeks start on a Thursday given that is when epoch starts. Set $epoch to 345600 to start on a Monday, or 259200 for Sunday.
 *
 * @param  TIME $timestamp The timestamp which we want to convert to an interval index
 * @param  ID_TEXT $interval The interval we want to use
 * @set minutes, hours, days, weeks, months, years
 * @param  TIME $epoch Define our own epoch relative to the Unix epoch to use in this calculation instead
 * @return integer The index of the interval at which $timestamp is located
 */

function to_epoch_interval_index(int $timestamp, string $interval, int $epoch = 0) : int