]> granicus.if.org Git - php/commitdiff
- New implementation of the sunset algorithm. Fixes bugs #33789, #33671, #32820
authorDerick Rethans <derick@php.net>
Wed, 4 Jan 2006 12:57:04 +0000 (12:57 +0000)
committerDerick Rethans <derick@php.net>
Wed, 4 Jan 2006 12:57:04 +0000 (12:57 +0000)
  and #30937.
#- Didn't add it to news yet, as we'll merge this to PHP 5.1.x (just need to
#  wait for Ilia to approve it for 5.1.2).

15 files changed:
ext/date/lib/astro.c
ext/date/lib/parse_date.c
ext/date/lib/parse_date.re
ext/date/lib/parse_tz.c
ext/date/lib/timelib.h
ext/date/lib/unixtime2tm.c
ext/date/php_date.c
ext/date/php_date.h
ext/standard/basic_functions.c
ext/standard/config.m4
ext/standard/config.w32
ext/standard/php_standard.h
ext/standard/php_sunfuncs.h [deleted file]
ext/standard/sunfuncs.c [deleted file]
ext/standard/tests/general_functions/sunfuncts.phpt

index bf6b89b4173791d1d57a753505a94cfb6cbf4646..f10d4c3a8466042e920694112eed4666a2d30616 100644 (file)
@@ -204,7 +204,7 @@ static void astro_sun_RA_dec(double d, double *RA, double *dec, double *r)
  *                    both set to the time when the sun is at south.  
  *                                                                    
  */
-int timelib_astro_rise_set_altitude(timelib_time *t_loc, double lon, double lat, double altit, int upper_limb, double *h_rise, double *h_set, timelib_sll *ts_rise, timelib_sll *ts_set)
+int timelib_astro_rise_set_altitude(timelib_time *t_loc, double lon, double lat, double altit, int upper_limb, double *h_rise, double *h_set, timelib_sll *ts_rise, timelib_sll *ts_set, timelib_sll *ts_transit)
 {
        double  d,  /* Days since 2000 Jan 0.0 (negative before) */
        sr,         /* Solar distance, astronomical units */
@@ -215,11 +215,12 @@ int timelib_astro_rise_set_altitude(timelib_time *t_loc, double lon, double lat,
        tsouth,     /* Time when Sun is at south */
        sidtime;    /* Local sidereal time */
        timelib_time *t_utc;
-       timelib_sll   timestamp;
+       timelib_sll   timestamp, old_sse;
 
        int rc = 0; /* Return cde from function - usually 0 */
 
        /* Normalize time */
+       old_sse = t_loc->sse;
        t_loc->h = 12;
        t_loc->i = t_loc->s = 0;
        timelib_update_ts(t_loc, NULL);
@@ -258,6 +259,7 @@ int timelib_astro_rise_set_altitude(timelib_time *t_loc, double lon, double lat,
        {
                double cost;
                cost = (sind(altit) - sind(lat) * sind(sdec)) / (cosd(lat) * cosd(sdec));
+               *ts_transit = t_utc->sse + (tsouth * 3600);
                if (cost >= 1.0) {
                        rc = -1;
                        t = 0.0;       /* Sun always below altit */
@@ -281,9 +283,9 @@ int timelib_astro_rise_set_altitude(timelib_time *t_loc, double lon, double lat,
                }
        }
 
-
-       /* Kill temporary time */
+       /* Kill temporary time and restore original sse */
        timelib_time_dtor(t_utc);
+       t_loc->sse = old_sse;
 
        return rc;
 }
index b60ec7a0f7634a1f631e46953b65caebf08224f0..c3ee77511f63a11e9dbc2dab70b45ee8cb032435 100644 (file)
@@ -1,4 +1,4 @@
-/* Generated by re2c 0.9.12.dev on Mon Dec 19 13:18:44 2005 */
+/* Generated by re2c 0.9.12 on Wed Jan  4 13:49:18 2006 */
 #line 1 "ext/date/lib/parse_date.re"
 /*
    +----------------------------------------------------------------------+
@@ -588,7 +588,7 @@ static timelib_tz_lookup_table* zone_search(const char *word, long gmtoffset, in
        timelib_tz_lookup_table  *tp, *first_found_elem;
        timelib_tz_lookup_table  *fmp;
 
-       if (strcasecmp("utc", word) == 0) {
+       if (strcasecmp("utc", word) == 0 || strcasecmp("gmt", word) == 0) {
                return timelib_timezone_utc;
        }
        
index d96364101ce0533b5f066edcc2ccde2fa9eabfb7..438367de238dc16867d09cbd78a67d1061b77d4e 100644 (file)
@@ -586,7 +586,7 @@ static timelib_tz_lookup_table* zone_search(const char *word, long gmtoffset, in
        timelib_tz_lookup_table  *tp, *first_found_elem;
        timelib_tz_lookup_table  *fmp;
 
-       if (strcasecmp("utc", word) == 0) {
+       if (strcasecmp("utc", word) == 0 || strcasecmp("gmt", word) == 0) {
                return timelib_timezone_utc;
        }
        
index 963e98f065f09680e16b9ccb1fd96c762ac45df8..737181da5c4345e5f2c2206e5e4b957329fbf0de 100644 (file)
@@ -364,3 +364,21 @@ timelib_time_offset *timelib_get_time_zone_info(timelib_sll ts, timelib_tzinfo *
 
        return tmp;
 }
+
+timelib_sll timelib_get_current_offset(timelib_time *t)
+{
+       timelib_time_offset *gmt_offset;
+                       
+       switch (t->zone_type) {
+               case TIMELIB_ZONETYPE_ABBR:
+               case TIMELIB_ZONETYPE_OFFSET:
+                       return t->z * 60;
+                       
+               case TIMELIB_ZONETYPE_ID:
+                       gmt_offset = timelib_get_time_zone_info(t->sse, t->tz_info);
+                       return gmt_offset->offset;
+
+               default:
+                       return 0;
+       }
+}
index 907a5883f9fce84bcf0f4b0ba65476cafd20bb80..ff30960b9c30b2847ce8d5e67f4202b0a26e5a4e 100644 (file)
@@ -71,6 +71,7 @@ int timelib_timezone_id_is_valid(char *timezone, timelib_tzdb *tzdb);
 timelib_tzinfo *timelib_parse_tzfile(char *timezone, timelib_tzdb *tzdb);
 int timelib_timestamp_is_in_dst(timelib_sll ts, timelib_tzinfo *tz);
 timelib_time_offset *timelib_get_time_zone_info(timelib_sll ts, timelib_tzinfo *tz);
+timelib_sll timelib_get_current_offset(timelib_time *t);
 void timelib_dump_tzinfo(timelib_tzinfo *tz);
 timelib_tzdb *timelib_builtin_db(void);
 timelib_tzdb_index_entry *timelib_timezone_builtin_identifiers_list(int *count);
@@ -96,6 +97,6 @@ void timelib_decimal_hour_to_hms(double h, int *hour, int *min, int *sec);
 
 /* from astro.c */
 double timelib_ts_to_juliandate(timelib_sll ts);
-int timelib_astro_rise_set_altitude(timelib_time *time, double lon, double lat, double altit, int upper_limb, double *h_rise, double *h_set, timelib_sll *ts_rise, timelib_sll *ts_set);
+int timelib_astro_rise_set_altitude(timelib_time *time, double lon, double lat, double altit, int upper_limb, double *h_rise, double *h_set, timelib_sll *ts_rise, timelib_sll *ts_set, timelib_sll *ts_transit);
 
 #endif
index a12474847e623a0d94ba8ea2c5bd24a80b92097a..4834b470d9253baabb2b86dd22d15576f5d554bf 100644 (file)
@@ -170,9 +170,6 @@ void timelib_unixtime2local(timelib_time *tm, timelib_sll ts)
        timelib_time_offset *gmt_offset;
        timelib_tzinfo      *tz = tm->tz_info;
 
-       tm->is_localtime = 1;
-       tm->have_zone = 1;
-
        switch (tm->zone_type) {
                case TIMELIB_ZONETYPE_ABBR:
                case TIMELIB_ZONETYPE_OFFSET: {
@@ -203,7 +200,11 @@ void timelib_unixtime2local(timelib_time *tm, timelib_sll ts)
                default:
                        tm->is_localtime = 0;
                        tm->have_zone = 0;
+                       return;
        }
+
+       tm->is_localtime = 1;
+       tm->have_zone = 1;
 }
 
 void timelib_set_timezone(timelib_time *t, timelib_tzinfo *tz)
index b4ae1d9ff19faa241e627c1732c4ab56141ce9b0..4a05042bbfe576881636d62701bc5ca43fa4fe11 100644 (file)
@@ -74,6 +74,11 @@ zend_function_entry date_functions[] = {
        /* Options and Configuration */
        PHP_FE(date_default_timezone_set, NULL)
        PHP_FE(date_default_timezone_get, NULL)
+
+       /* Astronomical functions */
+       PHP_FE(date_sunrise, NULL)
+       PHP_FE(date_sunset, NULL)
+       PHP_FE(date_sun_info, NULL)
        {NULL, NULL, NULL}
 };
 
@@ -113,9 +118,22 @@ ZEND_DECLARE_MODULE_GLOBALS(date)
 timelib_tzdb *php_date_global_timezone_db;
 int php_date_global_timezone_db_enabled;
 
+#define DATE_DEFAULT_LATITUDE "31.7667"
+#define DATE_DEFAULT_LONGITUDE "35.2333"
+
+/* on 90'35; common sunset declaration (start of sun body appear) */
+#define DATE_SUNSET_ZENITH "90.583333"
+
+/* on 90'35; common sunrise declaration (sun body disappeared) */
+#define DATE_SUNRISE_ZENITH "90.583333"
+
 /* {{{ INI Settings */
 PHP_INI_BEGIN()
        STD_PHP_INI_ENTRY("date.timezone", "", PHP_INI_ALL, OnUpdateString, default_timezone, zend_date_globals, date_globals)
+       PHP_INI_ENTRY("date.default_latitude",           DATE_DEFAULT_LATITUDE,        PHP_INI_ALL, NULL)
+       PHP_INI_ENTRY("date.default_longitude",          DATE_DEFAULT_LONGITUDE,       PHP_INI_ALL, NULL)
+       PHP_INI_ENTRY("date.sunset_zenith",              DATE_SUNSET_ZENITH,           PHP_INI_ALL, NULL)
+       PHP_INI_ENTRY("date.sunrise_zenith",             DATE_SUNRISE_ZENITH,          PHP_INI_ALL, NULL)
 PHP_INI_END()
 /* }}} */
 
@@ -235,6 +253,11 @@ PHP_RSHUTDOWN_FUNCTION(date)
        "methods and you are still getting this warning, you most likely " \
        "misspelled the timezone identifier. "
 
+#define SUNFUNCS_RET_TIMESTAMP 0
+#define SUNFUNCS_RET_STRING    1
+#define SUNFUNCS_RET_DOUBLE    2
+
+
 /* {{{ PHP_MINIT_FUNCTION */
 PHP_MINIT_FUNCTION(date)
 {
@@ -254,6 +277,10 @@ PHP_MINIT_FUNCTION(date)
        REGISTER_STRING_CONSTANT("DATE_RSS",     DATE_FORMAT_RFC1123, CONST_CS | CONST_PERSISTENT);
        REGISTER_STRING_CONSTANT("DATE_W3C",     DATE_FORMAT_ISO8601, CONST_CS | CONST_PERSISTENT);
 
+       REGISTER_LONG_CONSTANT("SUNFUNCS_RET_TIMESTAMP", SUNFUNCS_RET_TIMESTAMP, CONST_CS | CONST_PERSISTENT);
+       REGISTER_LONG_CONSTANT("SUNFUNCS_RET_STRING", SUNFUNCS_RET_STRING, CONST_CS | CONST_PERSISTENT);
+       REGISTER_LONG_CONSTANT("SUNFUNCS_RET_DOUBLE", SUNFUNCS_RET_DOUBLE, CONST_CS | CONST_PERSISTENT);
+
        php_date_global_timezone_db = NULL;
        php_date_global_timezone_db_enabled = 0;
        
@@ -1797,6 +1824,211 @@ PHP_FUNCTION(date_default_timezone_get)
 }
 /* }}} */
 
+/* {{{ php_do_date_sunrise_sunset
+ *  Common for date_sunrise() and date_sunset() functions
+ */
+static void php_do_date_sunrise_sunset(INTERNAL_FUNCTION_PARAMETERS, int calc_sunset)
+{
+       double latitude, longitude, zenith, gmt_offset = 0, altitude;
+       double h_rise, h_set, N;
+       timelib_sll rise, set, transit;
+       long time, retformat;
+       int             rs;
+       timelib_time   *t;
+       timelib_tzinfo *tzi;
+       char            retstr[6];
+       
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|ldddd", &time, &retformat, &latitude, &longitude, &zenith, &gmt_offset) == FAILURE) {
+               RETURN_FALSE;
+       }
+       
+       switch (ZEND_NUM_ARGS()) {
+               case 1:
+                       retformat = SUNFUNCS_RET_STRING;
+               case 2:
+                       latitude = INI_FLT("date.default_latitude");
+               case 3:
+                       longitude = INI_FLT("date.default_longitude");
+               case 4:
+                       if (calc_sunset) {
+                               zenith = INI_FLT("date.sunset_zenith");
+                       } else {
+                               zenith = INI_FLT("date.sunrise_zenith");
+                       }
+               case 5:
+               case 6:
+                       break;
+               default:
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid format");
+                       RETURN_FALSE;
+                       break;
+       }
+       if (retformat != SUNFUNCS_RET_TIMESTAMP &&
+               retformat != SUNFUNCS_RET_STRING &&
+               retformat != SUNFUNCS_RET_DOUBLE)
+       {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Wrong return format given, pick one of SUNFUNCS_RET_TIMESTAMP, SUNFUNCS_RET_STRING or SUNFUNCS_RET_DOUBLE");
+               RETURN_FALSE;
+       }
+       altitude = 90 - zenith;
+
+       /* Initialize time struct */
+       t = timelib_time_ctor();
+       tzi = get_timezone_info(TSRMLS_C);
+       t->tz_info = tzi;
+       t->zone_type = TIMELIB_ZONETYPE_ID;
+
+       if (ZEND_NUM_ARGS() <= 5) {
+               gmt_offset = timelib_get_current_offset(t) / 3600;
+       }
+
+       timelib_unixtime2local(t, time);
+       rs = timelib_astro_rise_set_altitude(t, longitude, latitude, altitude, altitude > -1 ? 1 : 0, &h_rise, &h_set, &rise, &set, &transit);
+
+       if (rs != 0) {
+               RETURN_FALSE;
+       }
+
+       if (retformat == SUNFUNCS_RET_TIMESTAMP) {
+               RETURN_LONG(calc_sunset ? set : rise);
+       }
+       N = (calc_sunset ? h_set : h_rise) + gmt_offset;
+       while (N > 24) {
+               N -= 24;
+       }
+       while (N < 0) {
+               N += 24;
+       }
+       switch (retformat) {
+               case SUNFUNCS_RET_STRING:
+                       sprintf(retstr, "%02d:%02d", (int) N, (int) (60 * (N - (int) N)));
+                       RETURN_STRINGL(retstr, 5, 1);
+                       break;
+               case SUNFUNCS_RET_DOUBLE:
+                       RETURN_DOUBLE(N);
+                       break;
+       }
+}
+/* }}} */
+
+/* {{{ proto mixed date_sunrise(mixed time [, int format [, float latitude [, float longitude [, float zenith [, float gmt_offset]]]]])
+   Returns time of sunrise for a given day and location */
+PHP_FUNCTION(date_sunrise)
+{
+       php_do_date_sunrise_sunset(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
+}
+/* }}} */
+
+/* {{{ proto mixed date_sunset(mixed time [, int format [, float latitude [, float longitude [, float zenith [, float gmt_offset]]]]])
+   Returns time of sunset for a given day and location */
+PHP_FUNCTION(date_sunset)
+{
+       php_do_date_sunrise_sunset(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
+}
+/* }}} */
+
+/* {{{ proto array date_sun_info(long time, float latitude, float longitude)
+   Returns an array with information about sun set/rise and twilight begin/end */
+PHP_FUNCTION(date_sun_info)
+{
+       long            time;
+       double          latitude, longitude;
+       timelib_time   *t, *t2;
+       timelib_tzinfo *tzi;
+       int             rs;
+       timelib_sll     rise, set, transit;
+       int             dummy;
+       double          ddummy;
+       
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ldd", &time, &latitude, &longitude) == FAILURE) {
+               RETURN_FALSE;
+       }
+       /* Initialize time struct */
+       t = timelib_time_ctor();
+       tzi = get_timezone_info(TSRMLS_C);
+       t->tz_info = tzi;
+       t->zone_type = TIMELIB_ZONETYPE_ID;
+       timelib_unixtime2local(t, time);
+
+       /* Setup */
+       t2 = timelib_time_ctor();
+       array_init(return_value);
+       
+       /* Get sun up/down and transit */
+       rs = timelib_astro_rise_set_altitude(t, latitude, longitude, -35.0/60, 1, &ddummy, &ddummy, &rise, &set, &transit);
+       switch (rs) {
+               case -1: /* always below */
+                       add_assoc_bool(return_value, "sunrise", 0);
+                       add_assoc_bool(return_value, "sunset", 0);
+                       break;
+               case 1: /* always above */
+                       add_assoc_bool(return_value, "sunrise", 1);
+                       add_assoc_bool(return_value, "sunset", 1);
+                       break;
+               default:
+                       t2->sse = rise;
+                       add_assoc_long(return_value, "sunrise", timelib_date_to_int(t2, &dummy));
+                       t2->sse = set;
+                       add_assoc_long(return_value, "sunset", timelib_date_to_int(t2, &dummy));
+       }
+       t2->sse = transit;
+       add_assoc_long(return_value, "transit", timelib_date_to_int(t2, &dummy));
+
+       /* Get civil twilight */
+       rs = timelib_astro_rise_set_altitude(t, latitude, longitude, -6.0, 0, &ddummy, &ddummy, &rise, &set, &transit);
+       switch (rs) {
+               case -1: /* always below */
+                       add_assoc_bool(return_value, "civil_twilight_begin", 0);
+                       add_assoc_bool(return_value, "civil_twilight_end", 0);
+                       break;
+               case 1: /* always above */
+                       add_assoc_bool(return_value, "civil_twilight_begin", 1);
+                       add_assoc_bool(return_value, "civil_twilight_end", 1);
+                       break;
+               default:
+                       t2->sse = rise;
+                       add_assoc_long(return_value, "civil_twilight_begin", timelib_date_to_int(t2, &dummy));
+                       t2->sse = set;
+                       add_assoc_long(return_value, "civil_twilight_end", timelib_date_to_int(t2, &dummy));
+       }
+
+       /* Get nautical twilight */
+       rs = timelib_astro_rise_set_altitude(t, latitude, longitude, -12.0, 0, &ddummy, &ddummy, &rise, &set, &transit);
+       switch (rs) {
+               case -1: /* always below */
+                       add_assoc_bool(return_value, "nautical_twilight_begin", 0);
+                       add_assoc_bool(return_value, "nautical_twilight_end", 0);
+                       break;
+               case 1: /* always above */
+                       add_assoc_bool(return_value, "nautical_twilight_begin", 1);
+                       add_assoc_bool(return_value, "nautical_twilight_end", 1);
+                       break;
+               default:
+                       t2->sse = rise;
+                       add_assoc_long(return_value, "nautical_twilight_begin", timelib_date_to_int(t2, &dummy));
+                       t2->sse = set;
+                       add_assoc_long(return_value, "nautical_twilight_end", timelib_date_to_int(t2, &dummy));
+       }
+
+       /* Get astronomical twilight */
+       rs = timelib_astro_rise_set_altitude(t, latitude, longitude, -18.0, 0, &ddummy, &ddummy, &rise, &set, &transit);
+       switch (rs) {
+               case -1: /* always below */
+                       add_assoc_bool(return_value, "astronomical_twilight_begin", 0);
+                       add_assoc_bool(return_value, "astronomical_twilight_end", 0);
+                       break;
+               case 1: /* always above */
+                       add_assoc_bool(return_value, "astronomical_twilight_begin", 1);
+                       add_assoc_bool(return_value, "astronomical_twilight_end", 1);
+                       break;
+               default:
+                       t2->sse = rise;
+                       add_assoc_long(return_value, "astronomical_twilight_begin", timelib_date_to_int(t2, &dummy));
+                       t2->sse = set;
+                       add_assoc_long(return_value, "astronomical_twilight_end", timelib_date_to_int(t2, &dummy));
+       }
+}
+/* }}} */
 /*
  * Local variables:
  * tab-width: 4
index 70d8bd860e317920b35e295cd9002bf27656a31d..bf486529d372928d0c88c4c64a3bc9e78698652c 100644 (file)
@@ -72,6 +72,11 @@ PHP_FUNCTION(timezone_abbreviations_list);
 PHP_FUNCTION(date_default_timezone_set);
 PHP_FUNCTION(date_default_timezone_get);
 
+/* Astro functions */
+PHP_FUNCTION(date_sunrise);
+PHP_FUNCTION(date_sunset);
+PHP_FUNCTION(date_sun_info);
+
 PHP_RINIT_FUNCTION(date);
 PHP_RSHUTDOWN_FUNCTION(date);
 PHP_MINIT_FUNCTION(date);
index 5943d37b4e6475c4143e97b4d37df924e7206b4f..e421c1386c4c4d11b5f4590685cb9ddc34b0ec03 100644 (file)
@@ -846,8 +846,6 @@ zend_function_entry basic_functions[] = {
 
        PHP_FE(output_add_rewrite_var,                                                                                  NULL)
        PHP_FE(output_reset_rewrite_vars,                                                                               NULL)
-       PHP_FE(date_sunrise,                                                                                                            NULL)
-       PHP_FE(date_sunset,                                                                                                                     NULL)
 
        {NULL, NULL, NULL}
 };
@@ -885,10 +883,6 @@ static PHP_INI_MH(OnUpdateSafeModeAllowedEnvVars)
 PHP_INI_BEGIN()
        PHP_INI_ENTRY_EX("safe_mode_protected_env_vars", SAFE_MODE_PROTECTED_ENV_VARS, PHP_INI_SYSTEM, OnUpdateSafeModeProtectedEnvVars, NULL)
        PHP_INI_ENTRY_EX("safe_mode_allowed_env_vars",   SAFE_MODE_ALLOWED_ENV_VARS,   PHP_INI_SYSTEM, OnUpdateSafeModeAllowedEnvVars,   NULL)
-       PHP_INI_ENTRY("date.default_latitude",           DATE_DEFAULT_LATITUDE,        PHP_INI_ALL, NULL)
-       PHP_INI_ENTRY("date.default_longitude",          DATE_DEFAULT_LONGITUDE,       PHP_INI_ALL, NULL)
-       PHP_INI_ENTRY("date.sunset_zenith",              DATE_SUNSET_ZENITH,           PHP_INI_ALL, NULL)
-       PHP_INI_ENTRY("date.sunrise_zenith",             DATE_SUNRISE_ZENITH,          PHP_INI_ALL, NULL)
 PHP_INI_END()
 
 
@@ -1045,10 +1039,6 @@ PHP_MINIT_FUNCTION(basic)
        REGISTER_LONG_CONSTANT("INI_SYSTEM", ZEND_INI_SYSTEM, CONST_CS | CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("INI_ALL",    ZEND_INI_ALL,    CONST_CS | CONST_PERSISTENT);
 
-       REGISTER_LONG_CONSTANT("SUNFUNCS_RET_TIMESTAMP", SUNFUNCS_RET_TIMESTAMP, CONST_CS | CONST_PERSISTENT);
-       REGISTER_LONG_CONSTANT("SUNFUNCS_RET_STRING", SUNFUNCS_RET_STRING, CONST_CS | CONST_PERSISTENT);
-       REGISTER_LONG_CONSTANT("SUNFUNCS_RET_DOUBLE", SUNFUNCS_RET_DOUBLE, CONST_CS | CONST_PERSISTENT);
-
        REGISTER_LONG_CONSTANT("PHP_URL_SCHEME", PHP_URL_SCHEME, CONST_CS | CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("PHP_URL_HOST", PHP_URL_HOST, CONST_CS | CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("PHP_URL_PORT", PHP_URL_PORT, CONST_CS | CONST_PERSISTENT);
index 86ceb9d5be36f3a31eafed24e9b42f2e454f304f..cc1f95f3132783e62729958cd958b1b9c61800b4 100644 (file)
@@ -489,7 +489,7 @@ PHP_NEW_EXTENSION(standard, array.c base64.c basic_functions.c browscap.c crc32.
                             incomplete_class.c url_scanner_ex.c ftp_fopen_wrapper.c \
                             http_fopen_wrapper.c php_fopen_wrapper.c credits.c css.c \
                             var_unserializer.c ftok.c sha1.c user_filters.c uuencode.c \
-                            filters.c proc_open.c sunfuncs.c streamsfuncs.c http.c)
+                            filters.c proc_open.c streamsfuncs.c http.c)
 
 PHP_ADD_MAKEFILE_FRAGMENT
 
index 0bed3ee3e387720ec7cb7e551cbb30d674faae11..e02e6965f8ed3a72221f1d1e0e2b9abbe795412f 100644 (file)
@@ -15,6 +15,6 @@ EXTENSION("standard", "array.c base64.c basic_functions.c browscap.c \
        versioning.c assert.c strnatcmp.c levenshtein.c incomplete_class.c \
        url_scanner_ex.c ftp_fopen_wrapper.c http_fopen_wrapper.c \
        php_fopen_wrapper.c credits.c css.c var_unserializer.c ftok.c sha1.c \
-       user_filters.c uuencode.c filters.c proc_open.c sunfuncs.c \
+       user_filters.c uuencode.c filters.c proc_open.c \
        streamsfuncs.c http.c", false /* never shared */);
 
index b79a3bd9e1dc312a32ac6b6e96250848579360c0..aae11ca83e0a74420709589c548b7aedd87f109b 100644 (file)
@@ -59,7 +59,6 @@
 #include "php_versioning.h"
 #include "php_ftok.h"
 #include "php_type.h"
-#include "php_sunfuncs.h"
 
 #define phpext_standard_ptr basic_functions_module_ptr
 PHP_MINIT_FUNCTION(standard_filters);
diff --git a/ext/standard/php_sunfuncs.h b/ext/standard/php_sunfuncs.h
deleted file mode 100644 (file)
index f8dcc02..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/* 
-   +----------------------------------------------------------------------+
-   | PHP Version 5                                                        |
-   +----------------------------------------------------------------------+
-   | Copyright (c) 1997-2006 The PHP Group                                |
-   +----------------------------------------------------------------------+
-   | This source file is subject to version 3.01 of the PHP license,      |
-   | that is bundled with this package in the file LICENSE, and is        |
-   | available through the world-wide-web at the following url:           |
-   | http://www.php.net/license/3_01.txt                                  |
-   | If you did not receive a copy of the PHP license and are unable to   |
-   | obtain it through the world-wide-web, please send a note to          |
-   | license@php.net so we can mail you a copy immediately.               |
-   +----------------------------------------------------------------------+
-   | Author: Moshe Doron <mosdoron@netvision.net.il>                      |
-   +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#ifndef PHP_SUNFUNCS_H
-#define PHP_SUNFUNCS_H
-
-/* default ini entries: */
-/* Jerusalem one. */
-#define DATE_DEFAULT_LATITUDE "31.7667"
-#define DATE_DEFAULT_LONGITUDE "35.2333"
-
-/* on 90'50; common jewish sunset declaration (start of sun body appear) */
-#define DATE_SUNSET_ZENITH "90.83"
-
-/* on 90'50; common jewish  sunrise declaration (sun body disappeared) */
-#define DATE_SUNRISE_ZENITH "90.83"
-
-#define SUNFUNCS_RET_TIMESTAMP 0
-#define SUNFUNCS_RET_STRING 1
-#define SUNFUNCS_RET_DOUBLE 2
-
-PHP_FUNCTION(date_sunrise);
-PHP_FUNCTION(date_sunset);
-
-#endif /* PHP_SUNFUNCS_H */
diff --git a/ext/standard/sunfuncs.c b/ext/standard/sunfuncs.c
deleted file mode 100644 (file)
index a62648d..0000000
+++ /dev/null
@@ -1,244 +0,0 @@
-/* 
-   +----------------------------------------------------------------------+
-   | PHP Version 5                                                        |
-   +----------------------------------------------------------------------+
-   | Copyright (c) 1997-2006 The PHP Group                                |
-   +----------------------------------------------------------------------+
-   | This source file is subject to version 3.01 of the PHP license,      |
-   | that is bundled with this package in the file LICENSE, and is        |
-   | available through the world-wide-web at the following url:           |
-   | http://www.php.net/license/3_01.txt                                  |
-   | If you did not receive a copy of the PHP license and are unable to   |
-   | obtain it through the world-wide-web, please send a note to          |
-   | license@php.net so we can mail you a copy immediately.               |
-   +----------------------------------------------------------------------+
-   | Author: Moshe Doron <mosdoron@netvision.net.il>                      |
-   +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-/*
-       The sun position algorithm taken from the 'US Naval Observatory's
-       Almanac for Computers', implemented by Ken Bloom <kekabloom@ucdavis.edu>
-       for the zmanim project <http://sourceforge.net/projects/zmanim/>
-       and finally converted to C by Moshe Doron <mosdoron@netvision.net.il>.
-*/
-
-#include "php.h"
-#include "php_sunfuncs.h"
-#include "php_ini.h"
-#include "ext/date/php_date.h"
-
-#include <assert.h>
-#include <math.h>
-#include <stdlib.h>
-
-/* {{{ macros and constants
- */
-#ifndef M_PI
-#define M_PI 3.14159265358979323846
-#endif
-
-#define to_rad(degrees) (degrees * M_PI / 180)
-#define to_rad_with_min(degrees) (degrees + minutes / 60)
-#define to_deg(rad) (rad * 180 / M_PI)
-/* }}} */
-
-/* {{{ php_sunrise_sunset
-   returns time in UTC */
-static double php_sunrise_sunset(long N, double latitude, double longitude, double zenith, int calc_sunset)
-{
-       double lngHour, t, M, L, Lx, RA, RAx, Lquadrant, RAquadrant, sinDec, cosDec, cosH, H, T, UT, UTx;
-
-       /* step 1: First calculate the day of the year 
-       int N = theday - date(1, 1, theday.year()) + 1;
-       */
-       
-       /* step 2: convert the longitude to hour value and calculate an approximate time */
-       lngHour = longitude / 15;
-       
-       /* use 18 for sunset instead of 6 */
-       if (calc_sunset) {
-               t = (double) N + ((18 - lngHour) / 24);         /* Sunset */
-       } else {
-               t = (double) N + ((6 - lngHour) / 24);          /* Sunrise */
-       }
-       
-       /* step 3: calculate the sun's mean anomaly */
-       M = (0.9856 * t) - 3.289;
-
-       /* step 4: calculate the sun's true longitude */
-       L = M + (1.916 * sin(to_rad(M))) + (0.020 * sin (to_rad(2 * M))) + 282.634;
-
-       while (L < 0) {
-               Lx = L + 360;
-               assert (Lx != L); /* askingtheguru: realy needed? */
-               L = Lx;
-       }
-
-       while (L >= 360) {
-               Lx = L - 360;
-               assert (Lx != L); /* askingtheguru: realy needed? */
-               L = Lx;
-       }
-
-       /* step 5a: calculate the sun's right ascension */
-       RA = to_deg(atan(0.91764 * tan(to_rad(L))));
-
-       while (RA < 0) {
-               RAx = RA + 360;
-               assert (RAx != RA);  /* askingtheguru: realy needed? */
-               RA = RAx;
-       }
-
-       while (RA >= 360) {
-               RAx = RA - 360;
-               assert (RAx != RA);  /* askingtheguru: realy needed? */
-               RA = RAx;
-       }
-       
-       /* step 5b: right ascension value needs to be in the same quadrant as L */
-       Lquadrant = floor(L / 90) * 90;
-       RAquadrant = floor(RA / 90) * 90;
-       RA = RA + (Lquadrant - RAquadrant);
-
-       /* step 5c: right ascension value needs to be converted into hours */
-       RA /= 15;
-
-       /* step 6: calculate the sun's declination */
-       sinDec = 0.39782 * sin(to_rad(L));
-       cosDec = cos(asin(sinDec));
-
-       /* step 7a: calculate the sun's local hour angle */
-       cosH = (cos(to_rad(zenith)) - (sinDec * sin(to_rad(latitude)))) / (cosDec * cos(to_rad(latitude)));
-
-       /* XXX: What's the use of this block.. ?
-        * if (!calc_sunset && cosH > 1 || calc_sunset && cosH < -1) {
-        *    throw doesnthappen(); 
-        * }
-        */
-               
-       /* step 7b: finish calculating H and convert into hours */
-       if (calc_sunset) {
-               H = to_deg(acos(cosH));                 /* Sunset */
-       } else {
-               H = 360 - to_deg(acos(cosH));   /* Sunrise */
-       }
-       H = H / 15;
-
-       /* step 8: calculate local mean time */
-       T = H + RA - (0.06571 * t) - 6.622;
-
-       /* step 9: convert to UTC */
-       UT = T - lngHour;
-
-       while (UT < 0) {
-               UTx = UT + 24;
-               assert (UTx != UT); /* askingtheguru: realy needed? */
-               UT = UTx;
-       }
-
-       while (UT >= 24) {
-               UTx = UT - 24;
-               assert (UTx != UT); /* askingtheguru: realy needed? */
-               UT = UTx;
-       }
-       
-       return UT;
-}
-/* }}} */
-
-/* {{{ php_do_date_sunrise_sunset
- *  Common for date_sunrise() and date_sunset() functions
- */
-static void php_do_date_sunrise_sunset(INTERNAL_FUNCTION_PARAMETERS, int calc_sunset)
-{
-       zval *date;
-       double latitude, longitude, zenith, gmt_offset, ret;
-       int time, N;
-       long retformat;
-       char retstr[6];
-       
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|ldddd", &date, &retformat, &latitude, &longitude, &zenith, &gmt_offset) == FAILURE) {
-               RETURN_FALSE;
-       }
-       
-       switch (Z_TYPE_P(date)) {
-               case IS_LONG:
-                       time = Z_LVAL_P(date);
-                       break;
-               case IS_STRING:
-                       /* todo: more user friendly format */
-               default:
-                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "date must be timestamp for now");
-                       RETURN_FALSE;
-       }
-
-       N = php_idate('z', time, 0) + 1;
-       
-       switch (ZEND_NUM_ARGS()) {
-               case 1:
-                       retformat = SUNFUNCS_RET_STRING;
-               case 2:
-                       latitude = INI_FLT("date.default_latitude");
-               case 3:
-                       longitude = INI_FLT("date.default_longitude");
-               case 4:
-                       if (calc_sunset) {
-                               zenith = INI_FLT("date.sunset_zenith");
-                       } else {
-                               zenith = INI_FLT("date.sunrise_zenith");
-                       }
-               case 5:
-                       gmt_offset = php_idate('Z', time, 0) / 3600;
-               case 6:
-                       break;
-               default:
-                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid format");
-                       RETURN_FALSE;
-                       break;
-       }
-       
-       ret = php_sunrise_sunset(N, latitude, longitude, zenith, calc_sunset) + gmt_offset;
-
-       switch (retformat) {
-               case SUNFUNCS_RET_TIMESTAMP:
-                       RETURN_LONG((int) (time - (time % (24 * 3600))) + (int) (3600 * ret));
-                       break;
-               case SUNFUNCS_RET_STRING:
-                       N = (int) ret;
-                       sprintf(retstr, "%02d:%02d", N, (int) (60 * (ret - (double) N)));
-                       RETVAL_STRINGL(retstr, 5, 1);
-                       break;
-               case SUNFUNCS_RET_DOUBLE:
-                       RETURN_DOUBLE(ret);
-                       break;
-       }
-}
-/* }}} */
-
-/* {{{ proto mixed date_sunrise(mixed time [, int format [, float latitude [, float longitude [, float zenith [, float gmt_offset]]]]])
-   Returns time of sunrise for a given day and location */
-PHP_FUNCTION(date_sunrise)
-{
-       php_do_date_sunrise_sunset(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
-}
-/* }}} */
-
-/* {{{ proto mixed date_sunset(mixed time [, int format [, float latitude [, float longitude [, float zenith [, float gmt_offset]]]]])
-   Returns time of sunset for a given day and location */
-PHP_FUNCTION(date_sunset)
-{
-       php_do_date_sunrise_sunset(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
-}
-/* }}} */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 fdm=marker
- * vim<600: sw=4 ts=4
- */
index a9711ffc34ee5abc8b12767d39299d2f9146a9a9..6ccd128173ad4683e66a7713b653e6b7b32d6c33 100644 (file)
@@ -18,27 +18,27 @@ for($a=1;$a<=12;$a++){
 }
 ?>
 --EXPECT--
-1041316748 06:39 6.652455761896
-1041353169 16:46 16.76937486746
-1043994763 06:32 6.54537029266
-1044033183 17:13 17.21752470874
-1046412416 06:06 6.115652675685
-1046453799 17:36 17.6108549623
-1049088501 05:28 5.472742029069
-1049133501 17:58 17.97255258437
-1051678444 04:54 4.901229982859
-1051726729 18:18 18.31368876948
-1054355667 04:34 4.57442928945
-1054406363 18:39 18.65640094324
-1056947818 04:36 4.616120450519
-1056998911 18:48 18.80887165777
-1059627264 04:54 4.906882509836
-1059676557 18:35 18.59928600203
-1062306852 05:14 5.236889557074
-1062353017 18:03 18.06054178788
-1064899952 05:32 5.542366581139
-1064942681 17:24 17.41150561492
-1067579698 05:54 5.916208842058
-1067619001 16:50 16.83369857063
-1070173246 06:20 6.34622155207
-1070210100 16:35 16.58358905554
+1041395864 06:37 6.629013145891
+1041432452 16:47 16.79245111439
+1044073855 06:30 6.515408927984
+1044112463 17:14 17.23987028904
+1046491495 06:04 6.082214503339
+1046533075 17:37 17.63201103534
+1049167581 05:26 5.439443811173
+1049212774 17:59 17.99303572948
+1051757532 04:52 4.870193412616
+1051806007 18:20 18.33539050867
+1054434776 04:32 4.548982718277
+1054485647 18:40 18.67981294906
+1057026949 04:35 4.597195637274
+1057078197 18:49 18.83256339675
+1059706409 04:53 4.891657508917
+1059755837 18:37 18.62144070428
+1062385999 05:13 5.222095112101
+1062432291 18:04 18.08095716848
+1064979098 05:31 5.527319921542
+1065021952 17:25 17.43133913592
+1067658845 05:54 5.901629287093
+1067698274 16:51 16.85390245353
+1070252387 06:19 6.329924268934
+1070289382 16:36 16.60631260094