Reply to Re: [PHP] Help with dates

Your name:

Reply:


Posted by Kevin on 03/15/05 06:08

Dear mr. Maas,

First of all my appologies for taking so long to respond. I had a family
death to attend to.

I will respond to the message in message.

Yours,

Kevin

"Jochem Maas" <jochem@iamjochem.com> wrote in message
news:422F5C9C.2050701@iamjochem.com...
> ...
> >>
> >>Why re-invent the wheel?
> >
> >
> > It's part of a game. In the RPG there are dates which the players would
like
> > to be able to convert from our calendar to that one, and back again..
> >
> >
> >>>In order to do that I need to find the exact days since the year 0
> >
> > BC/AD.
>
> why is OBC relevant, I read later on that you take the start of egyptian
> civilization as zero. is that not much earlier.

Well it's relevant to make a baseline so that I can calculate the difference
from then until now. That's the only reason thusfar.

>
> whats the structure of the egyptian|rpg calendar?

A year consists of 769 days, 13 months of 63 days a month, except for month
13 which has 14 days. Every month has 7 weeks of 9 days, of course month 13
is the exception. A day is 24 hours.

>
> >
> >>>However, the functions php provides only allow up to the unix epoch.
> >>>
> >>>Could you guys give me some pointers on how to accomplish this,
> >>>accurately?
> >>
> >>Take a look at the MySQL date ranges -- They may have a data type that
> >>allows for more than just 1/1/1970 to 3/??/2038
> >>
> >>If not, consider using PostgreSQL which has VERY extensive and flexible
> >>date support, for ranges MUCH larger than 0 BC/AD.
> >>http://postgresql.org
> >>
> >>I believe PostgreSQL even supports time scales on the order of
geological
> >>events and for astronomical purposes, though not with "day" accuracy.
> >>
>
> +1 on using a DB to calculate and format dates on this one :-)
> I'm guessing Kevins probably written an SQL statement before and he's
> already proved he can RTFPM (P for PHP)
>
> >>I am assuming that by "accurately" you mean "to the nearest day" since
you
> >>spoke of "exact days", right?
> >
> >
> > Aye.. it's nearest day, and according to calculations should have
repeatable
> > results. So what is date X today should also be it tomorrow (after the
> > calculations of course). That's what i've noticed so far. when I add a
date
> > and convert it and then convert it back it is a different date.
> >
>
> show us some code :-)

At the end of the message code will be provided.

> >
>>But you didn't define how far into the future you need to go.
> >>Current time?
> >>A few years out?
> >>Stardates from Star Trek?
> >>You have to specify a start date, end date, and accuracy to choose a
> >>correct calendar system.
> >
> >
> > It's mostly the past. The RPG is set in Egypt and the beginning of the
> > society in egypt has been taken as year 0. The start date I think is
> > obvious, but I do not understand an end date of a calendar.. Perhaps I'm
> > just blond.. but could you perhaps explain that one?
> >
>
> I must be blond, I don't even grok that question :-/

WEll I don't understand why an end date is important or what is meant with
accuracy. The term being blond is, at least in the Netherlands "a dumb
blond", so I made it so that when I am dumb or anything, I'm blond (which in
fact I am - dark blond) :-P.

>
> rgds,
> jochem

Code:

function get_date_ec($EarthDay, $EarthMonth, $EarthYear) {
$DayOfYear = 0;
# Setting internal date variables.
$intDay = intval($EarthDay);
$intMonth = intval($EarthMonth);
$intYear = intval($EarthYear);
$array_MonthDays["1"] = intval(31); // January
$array_MonthDays["3"] = intval(31); // March
$array_MonthDays["4"] = intval(30); // April
$array_MonthDays["5"] = intval(31); // May
$array_MonthDays["6"] = intval(30); // June
$array_MonthDays["7"] = intval(31); // July
$array_MonthDays["8"] = intval(31); // August
$array_MonthDays["9"] = intval(30); // September
$array_MonthDays["10"] = intval(31); // October
$array_MonthDays["11"] = intval(30); // November
$array_MonthDays["12"] = intval(31); // December

# Making a few Leap Year Checks
$RETURN_CHECK_LEAP_YEAR = check_leap_year($intYear);
if ($RETURN_CHECK_LEAP_YEAR == TRUE) {
$array_MonthDays["2"] = intval(29); // february
} else {
$array_MonthDays["2"] = intval(28); // february
};

if ($RETURN_CHECK_LEAP_YEAR == 1) {
#check date if leapdate has passed.
echo "$intYear is a LEAP YEAR <br> ";
if (($intDay >= 29) AND ($intMonth >= 2)) {
echo "LEAP DATE HAS PASSED!!!! <br>";
for ($n=1 ; $n<$intMonth ; $n++) {
$DayOfYear = $DayOfYear + $array_MonthDays["$n"];
$testje = $array_MonthDays["$n"]+$intDay;
echo "testje: $testje <br>";
};
$DayOfYear = $DayOfYear + $intDay;
echo "$DayOfYear <Br>";
$intTotalDaysSinceEpoch = ($intYear * 365) + ($intYear / 4) +
$DayOfYear;
echo "$intTotalDaysSinceEpoch = ($intYear*365) + ($intYear /4) +
$DayOfYear <br>";
echo "$intTotalDaysSinceEpoch = " . $intYear*365 ." + ". ($intYear
/4) . "+ $DayOfYear <br><br>";
} else {
echo "LEAP DATE HAS NOT YET PASSED..<br>";
for ($n=1 ; $n<$intMonth ; $n++) {
$DayOfYear = $DayOfYear + $array_MonthDays["$n"];
$testje = $array_MonthDays["$n"]+$intDay;
echo "testje: $testje <br>";
};
$DayOfYear = $DayOfYear + $intDay;
echo "$DayOfYear <Br>";
$intTotalDaysSinceEpoch = ($intYear * 365) + (($intYear / 4) - 1) +
$DayOfYear;
echo "$intTotalDaysSinceEpoch = ($intYear*365) + (($intYear /4)-1) +
$DayOfYear <br>";
echo "$intTotalDaysSinceEpoch = ". $intYear*365 . " + " . (($intYear
/4)-1). " + $DayOfYear <br><br>";
};
} else {
echo "$intYear is NOT a LEAP YEAR <br> ";
};

# Calculating the year in Egypt.
$yr_Egypt = floor($EgyptianDays / 769);
# Calculating the Month in Egypt.
$mnt_Egypt = round( ($EgyptianDays-($yr_Egypt*769)) / 63 );
# Calculating the Day in Egypt.
$dy_Egypt = round( $EgyptianDays - (($yr_Egypt * 769) + ($mnt_Egypt *
63)) );
# Filling the date array variable with the day, month and year of the
Egyptian calendar.
$ec_date["Day"] = $dy_Egypt;
$ec_date["Month"] = $mnt_Egypt;
$ec_date["Year"] = $yr_Egypt;
# Returning the Calculated date.
return $ec_date;

};


Here is the code to feed the function with the values:

$DUMP = get_date_ec(1, 3, 2004);
echo "<pre>";
var_dump($DUMP);
echo "</pre>";

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация