/[dtapublic]/to_be_filed/webprojs/php_libraries/php_library/pamc_gen_a/time/timeraw.inc
ViewVC logotype

Contents of /to_be_filed/webprojs/php_libraries/php_library/pamc_gen_a/time/timeraw.inc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 35 - (show annotations) (download)
Sat Oct 8 23:35:33 2016 UTC (8 years, 1 month ago) by dashley
File size: 4574 byte(s)
Initial commit.
1 <?php
2 //$Header: /hl/cvsroots/gpl01/gpl01/webprojs/pamc/gen_a/sw/phplib/time/timeraw.inc,v 1.2 2007/06/24 03:38:09 dashley Exp $
3 //--------------------------------------------------------------------------------
4 //timeraw.inc -- PAMC functions for accessing low-level system time.
5 //Copyright (C) 2007 David T. Ashley
6 //--------------------------------------------------------------------------------
7 //This program is free software; you can redistribute it and/or
8 //modify it under the terms of the GNU General Public License
9 //as published by the Free Software Foundation; either version 2
10 //of the License, or (at your option) any later version.
11 //
12 //This program is distributed in the hope that it will be useful,
13 //but WITHOUT ANY WARRANTY; without even the implied warranty of
14 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 //GNU General Public License for more details.
16 //
17 //You should have received a copy of the GNU General Public License
18 //along with this program; if not, write to the Free Software
19 //Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 //--------------------------------------------------------------------------------
21 //Author contact information:
22 // David T. Ashley
23 // P.O. Box 918
24 // Marshall, Michigan, 49068
25 // dta@e3ft.com
26 //--------------------------------------------------------------------------------
27 //This source file provides raw time related code. This file is a wrapper
28 //around the built-in PHP functions to provide more flexibility as we get
29 //near the Unix epoch. All functions that obtain from the machine time must
30 //go through this module.
31 //--------------------------------------------------------------------------------
32 //Returns the current Unix time as an array of:
33 // a)A decimal string representing the seconds since the Unix epoch. A string
34 // representation is used because then this function can be modified as the
35 // Unix epoch grows closer (but, we'll probably all be using 64-bit machines
36 // by then). The string representation must not exceed 11 characters (but
37 // this should not be a problem until after 5,000 A.D.).
38 //
39 // b)An integer representing the nanoseconds of the fractional part of the
40 // Unix time. An integer is used because the fractional part of the time
41 // is not affected by the Unix epoch issue.
42 //
43 //
44 function TIMERAW_time_precision_mixed_array_2()
45 {
46 //Get the high-precision time microseconds and seconds.
47 list($usec, $sec) = explode(" ", microtime());
48
49 //Convert the integer seconds time to a string.
50 $string_sec = sprintf("%d", $sec);
51
52 //Convert the microseconds to an integer giving the
53 //integer number of microseconds. The original value is in fractional
54 //seconds (a float).
55 $usec = $usec * 1000000.0;
56 $usec = (int) $usec;
57
58 //Convert microseconds to nanoseconds.
59 $nsec = $usec * 1000;
60
61 //Stuff the return array and return.
62 $rv[0] = (string) $string_sec;
63 $rv[1] = (int) $nsec;
64 return($rv);
65 }
66 //--------------------------------------------------------------------------------
67 //Returns the raw time, except that whole integer time values too near midnight
68 //UTC won't be allowed. The reason for this behavior is to prevent a leap second
69 //from allowing us to dwell in the same integer second twice, which would create
70 //the possibility of sequential events having reversed timestamps or generating a
71 //non-unique SGUID. The mechanism for failing to return these values potentially
72 //corrupted by a leap second is that if one is the present time, sleep() will be
73 //done to get out of the window. This will potentially delay a web page load or
74 //maintenance script by up to approximately 4 seconds.
75 //
76 //Leap seconds, if they are injected or removed, will occur at midnight UTC.
77 //
78 function TIMERAW_time_precision_mixed_array_2_noleap()
79 {
80 $rv = TIMERAW_time_precision_mixed_array_2();
81 $seconds_modulus = bcmod($rv[0], "86400");
82
83 while (
84 (bccomp($seconds_modulus, "2") == -1)
85 ||
86 (bccomp($seconds_modulus, "86397") == 1)
87 )
88 {
89 sleep(1);
90 $rv = TIMERAW_time_precision_mixed_array_2();
91 $seconds_modulus = bcmod($rv[0], "86400");
92 }
93
94 return($rv);
95 }
96 //--------------------------------------------------------------------------------
97 //End of $RCSfile: timeraw.inc,v $.
98 //--------------------------------------------------------------------------------
99 ?>

dashley@gmail.com
ViewVC Help
Powered by ViewVC 1.1.25