i have the following code through which i need to detect a season .
[code] -
function season($period){
-
$seasons = array(
-
'spring' => array('March 21' , 'June 20'),
-
'summer' => array('June 21' , 'September 22'),
-
'fall' => array('September 23' , 'December 20'),
-
'winter' => array('December 21' , 'March 20')
-
);
-
-
$seasonsYear = array();
-
-
$start = strtotime($period[0]);
-
$end = strtotime($period[1]);
-
-
$seasonsYear[date('Y', $start)] = array();
-
-
-
if (key(current($seasonsYear)) != date('Y', $end))
-
$seasonsYear[date('Y', $end)] = array();
-
-
foreach ($seasonsYear as $year => &$seasonYear){
-
foreach ($seasons as $season => $period){
-
$seasonYear[$season] = array(strtotime($period[0].' '.$year), strtotime($period[1].' '.($season != 'winter' && $season != 'Winter2' ? $year : ($year+1))));
-
-
}
-
}
-
-
foreach ($seasonsYear as $year => &$seasons) {
-
foreach ($seasons as $season => &$period) {
-
if ($start >= $period[0] && $end <= $period[1]){
-
return ucFirst($season);
-
}
-
-
if ($start >= $period[0] && $start <= $period[1]) {
-
if (date('Y', $end) != $year)
-
$seasons = $seasonsYear[date('Y', $end)];
-
$year = date('Y', $end);
-
-
$nextSeason = key($seasons);
-
$nextPeriod = current($seasons);
-
do {
-
$findNext = ($end >= $nextPeriod[0] && $end <= $nextPeriod[1]);
-
-
$nextSeason = key($seasons);
-
$nextPeriod = current($seasons);
-
} while ($findNext = False);
-
-
$diffCurr = $period[1]-$start;
-
$diffNext = $end-$nextPeriod[0];
-
-
if ($diffCurr > $diffNext)
-
return ucFirst($season);
-
else {
-
return ucFirst($nextSeason);
-
}
-
}
-
}
-
}
-
}
-
echo season(array('2011-12-24','2011-12-26'));
-
now the problem is that the client does not want to have the standard season interval dates he wants
Winter to have interval from Nov 15th to May 15
Christmas to have interval from Dec 24 - Jan 1
and rest of the days to Summer
now when i try to replace the default $seasons array with the following every thing messes up -
'summer' => array('May 16' , 'November 16'),
-
'winter' => array('November 15' , 'December 23'),
-
'christmas' => array('December 24' , 'January 1'),
-
'winter' => array('January 2' , 'May 15')
-
i am really stuck why is this happening , at first it was tat i was using foreach loop for seasons and it only looped though the 3 indexes and even showed the sizeof $seasonYear equal to 3, until i changed the name of the last index Winter to Winter2 , but didnt not detect the right season even then may be it is because of the christmas season which falls between winter and winter2
any help in regarding this problem would be appreciated
regards,
Omer Aslam
2 2100
well, the key "winter" is used twice and there is a date overlap between summer and winter.
yeah dorm,
i mentioned that the key winter has been used twice , but didnt noticed the overlap in the dates and now i have changed it like -
'summer' => array('May 16' , 'November 14'),
-
'winter' => array('November 15' , 'December 23'),
-
'christmas' => array('December 24' , 'January 1'),
-
'winter2' => array('January 2' , 'May 15')
-
it still does not work right , why is it working with the standard intervals and not with my custom intervals , unable to figure out
regards,
Omer Aslam
Sign in to post your reply or Sign up for a free account.
Similar topics
by: MONO |
last post by:
Hello!
I´m trying to get the weeknumber fom a given date but at some dates
will return the wrong weeknumber.
WeekNumber = DatePart("ww", TodayAsDate, vbMonday, vbFirstFourDays)
like...
|
by: Lynn |
last post by:
On a form I have
Date_Start Date_End
I have a new
Date_Start1 Date_End1 which the use
inputs.
I need to validate that Date_Start1 and...
|
by: Dave |
last post by:
I have a problem that I can't quite get started on solving.
I have a table of asset statuses. Each time the asset status changes, a
new row is inserted into the table.
CREATE TABLE...
|
by: jsfromynr |
last post by:
Hi all,
I have two tables
CREATE TABLE (
NOT NULL ,
NULL , -- CURRENT DESIGNATION OF EMPLOYEE
NOT NULL
) ON
GO
|
by: dlx_son |
last post by:
Here is the code so far
<form name="thisform">
<h3>Enter time to add to or subtract from:</h3>
(If not entered, current time will be used)<br>
Day: <input name="d1" alt="Day of month"...
|
by: UnixSlaxer |
last post by:
Hello All,
While doing some TPC benchmark testing on DB2-UDB 8.2, I face the
following problem when running this query:
select *
from lineitem
where
l_shipdate <= date '1998-12-01' -...
|
by: perryclisbee via AccessMonster.com |
last post by:
I have dates of service for several people that range all over each month.
ie: patient had dates of service of: 7/3/2006, 7/24/2006 and 7/25/2006. I
need to create a new field via a query that...
|
by: oyis |
last post by:
Hi,
I'm looking for a function,which finds week number of given date.
I found this method before,but I can't find now...
Please help me...
|
by: aneinander |
last post by:
I'm beginner and getting following error message, please help.
The table contains transaction date, account number, branch, etc. And need to show previous transaction date or next transaction date...
|
by: abdutasleem357 |
last post by:
i want to know the query in oracle for, whether the given date is present or available in between two dates(startdate, enddate)
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |