Link to home
Start Free TrialLog in
Avatar of astrix2
astrix2

asked on

PHP - I search for a function that if I send a Local Date and Time and the TimeZone String ==> retrieve the Julianday Number

PHP - I search for a function that if I send a Local Date and Time and the TimeZone String ==> retrieve the Julianday Number

Any know???

Thanks in advance... Good day at all...
Avatar of Brian Tao
Brian Tao
Flag of Taiwan, Province of China image

There are PHP functions, UnixToJD or GregorianToJD, doing something similar to what you want. You can use it to write the function you want, something like the following:
// assumption:
// $localDate in the format "2016-09-21"
// $localTime in the format "14:17:32"
// $localTimezone is a valid PHP-supported timezone
function dayTimeToJulianDayNum($localDate, $localTime, $localTimezone)
{
  date_default_timezone_set($localTimezone);
  $phpTime = strtotime($localDate . " " . $localTime);
  return UnixToJD(date("U", $phpTime));
}

Open in new window

Avatar of astrix2
astrix2

ASKER

Ok thanks Brian, but not are a problem that the Unix Dates are only from 01-01-1970???

I need from 01-01-1900...

Or is valid dates prev of 01-01-1970???

Well, also I want a Script in PHP that advise of possible errors, for example, in Europe, in the last october sunday, the timezone change, when is 03 Am pass to be 2 Am, because this is posssible 2 date times, the date of the last sunday and hour 02:30 before the change, and the same after the change...

For example any person birth in the next change in Central Europe the 30 October 2016 - is Sunday - at 02:30 am, this day, at 03:00 Am pass to be 02:00 Am, but the person birth before the change of timezone is make, or after the change of timezone is make??? Not is possible know in te script, but the result of the script if possible do the 2 possible JulianDays...

Another error are when the change is the other, the Last Sunday of April in Central Europe the Timezone change, at 02:00 am, pass to be 03:00 am, and the time of day of change not possible to be 02:30 am, because not exists... The function need to do Error, not Possible this DateTime...

I search for make a deep script that solution retrieve the REAL Astronomical JulianDay from a DateTime and Timezone String, doing the possible errors, and the Date and Time from 01-01-1900 00:00 Am UTC or GMT...

Thanks in advance...
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of astrix2

ASKER

Thanks Ray, but the problem is that JulianDay not do the decimals, the time of the day...

Also PHP timezones DST changes are bad, not are equivalent to IANA Olson Timezones Databases:

https://www.iana.org/time-zones

PHP timezones functions not coincide exactly with the hours of change, for example, in Central Europe the Last Sunday of March at 02:00 Am pass to be 03:00 Am, and also, the Last Sunday of October at 03:00 Am pass to be 02:00 am, but PHP Timezones functions do that the changes is making at 01:00 Am in the two dates of DST changes, for example this:

http://www.astrodreams.com/testphp/gettzwithtzname.php?zonename=Europe/Madrid
<?php
$zonen = $_GET['zonename'];
$timezone = new DateTimeZone($zonen);
$transitions = $timezone->getTransitions();
for ($i=0; $i<500; $i++)
	{
	if ($transitions[$i] == "")
		break;
	print_r($transitions[$i]);
	print '<br>';
	}
$timezone_identifiers = DateTimeZone::listIdentifiers();
for ($i=0; $i < 1005; $i++)
	{
	if ($timezone_identifiers[$i] == "")
		break;
	echo "$timezone_identifiers[$i]";
	print '<br>';
	}
?>

Open in new window


And see how, for example, 2016:

/////////////////////////////////////////////
Array ( [ts] => 1459040400 [time] => 2016-03-27T01:00:00+0000 [offset] => 7200 [isdst] => 1 [abbr] => CEST )

Array ( [ts] => 1477789200 [time] => 2016-10-30T01:00:00+0000 [offset] => 3600 [isdst] => [abbr] => CET )
/////////////////////////////////////////////

And NOT, the DST changes in cities of Central Europe they are made at 02:00AM in March and at 03:00AM in October... Are not reliable the PHP Timezones Functions...

Also the JulianDay conversions not have the possibility of do directly the decimals, the hours, minutes and seconds in decimal format, only rounds to the more near JulianDay Long Integer...

But thanks Ray for your message, very thanks...

I give this information for if someone wants to use Timezones PHP functions, be careful, are nothing reliable in its changes ...

Inclusive I found sites that offer the service to provide timezones data, and they say they are fully equivalent to the MORE SECURE reference Olson IANA Database, and it is false, have PHP data, and PHP Tz Functions not are good...

Good day at all...
Avatar of astrix2

ASKER

Uhmm, not, I have an error, PHP timezones do Good the DST changes...

Pondering, I discover my error, when PHP Timezones Functions do this:

/////////////////////////////////////////////
Array ( [ts] => 1459040400 [time] => 2016-03-27T01:00:00+0000 [offset] => 7200 [isdst] => 1 [abbr] => CEST )

Array ( [ts] => 1477789200 [time] => 2016-10-30T01:00:00+0000 [offset] => 3600 [isdst] => [abbr] => CET )
/////////////////////////////////////////////

2016-03-27T01:00:00

This time of change are in UTC or GMT... And yes, is good time of the changes, but is in UTC or GMT...

Ok, sorry for the error... Php Timezones Functions are GOOD... Are equal to IANA Olson timezones Databases...

Good day at all...