Jump to content

Date Script Help Needed Please :-)


bgareth

Recommended Posts

Barand, how am I doing, I've probably got this totally wrong:

 

[code]
<?php


function EnglishHols($year)
{
$englishHolidays = array();

$t = mktime(0,0,0,1,1,$year);
$d = date('Y-m-d', $t);
$englishHolidays[$d] = 'New Year\'s Day';

/* Ben's Note - Get Unix timestamp (number of seconds since 1970) for 1 January of the current year and then append the $year variable to it (defined later) to the $t variable) then find the date and assign this to $d variable appended by the $t variable. The last line I don't get, I don't know what square brackets do..*/


$t = easter_date($year);
$d = date('Y-m-d', strtotime('-2 days', $t));
$englishHolidays[$d] = 'Good Friday';
$d = date('Y-m-d', $t);
$englishHolidays[$d] = 'Easter Sunday';
$d = date('Y-m-d', strtotime('+1 days', $t));
$englishHolidays[$d] = 'Easter Monday';

/* Ben's Note - Reassign $t variable to now carry easter_date function and append the year variable (yet to be assigned). Reassign $d variable to contain date function and then convert it to unix timestamp as defined above but this time taking a normal date to do it (so different function name.) Take two days off the unix timestamp and append the $t variable to the end.

Now assign the variable $englishHolidays to contain unix timestamp calculated in $d variable (why specified i.e. $englishHolidays[$d]?) and assign that to the text 'Good Friday'. Reassign $d variable again to contain date function converted to unix timestamp and add 1 day to the timestamp returned.

Append the $t variable to the end (is $t variable inherited from above or from below?) Reassign variable $englishHolidays to contain newly assigned $d variable and add the string 'Easter Sunday'. (This does not have any days added or subtracted and doesn't seem to refer to the function easter_date? How does this bit work?

Reassign $d variable yet again and convert it to unix timestamp adding 1 day and append $t variable to the end. Reassign variable $englishHolidays to contain $d variable and append the string 'Easter Monday'.*/

 

Please give me some feedback :-)

 

Kind Regards,

 

BG.


function EnglishHols($year)
{
   $englishHolidays = array();

   $t = mktime(0,0,0,1,1,$year);
   $d = date('Y-m-d', $t);
   $englishHolidays[$d] = 'New Year\'s Day';

   /* Barand's note
    Create a unix timestamp for 1 Jan of the required year and store in $t.
    Create a date string in the format '2012-01-01' from $t and store it in $d
    Add to the array $englishHolidays with a key of $d and value = holiday description
   */

   $t = easter_date($year);
   $d = date('Y-m-d', strtotime('-2 days', $t));
   $englishHolidays[$d] = 'Good Friday';
   $d = date('Y-m-d', $t);
   $englishHolidays[$d] = 'Easter Sunday';
   $d = date('Y-m-d', strtotime('+1 days', $t));
   $englishHolidays[$d] = 'Easter Monday';

   /* Barand's note
    PHP easter_date returns a unix timestamp for easter Sunday in the required year. Store in $t.
    Create date string in 'yyyy-mm-dd' format for date 2 days earlier than $t (Easter Sunday) and store in $d
    Add this to the $englishHolidays array with date $d as the key and description of'Good Friday'
    Now get the date string, $d, for Easter Sunday
    Store in the $englishHolidays array with key = $d and value of 'Easter Sunday'
    Get date string (yyyy-mm-dd) for the day after $t and store in $d
    Store in the $englishHolidays array with key = $d and value of 'Easter Monday'
   */

   $t = mktime(0,0,0,6,1,$year);
   $d = date ('Y-m-d', strtotime('last monday', $t));   // last monday in may
   $englishHolidays[$d] = 'Spring Bank Holiday';

   /* Barand's note
    Get unix timestamp for 1 June of required year and store in $t
    Create date string for the last monday before this date (last monday in may) and store in $d
    Add to the holidays array
   */
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.