Exemplo n.º 1
0
function GetData($val)
{
    $jd = GregorianToJD(1, 1, 1970);
    $gregorian = JDToGregorian($jd + intval($val) - 25569);
    return $gregorian;
    /**显示格式为 “月/日/年” */
}
Exemplo n.º 2
0
 function JDtoYMD($date, &$year, &$month, &$day)
 {
     $string = JDToGregorian($date);
     $month = strtok($string, " -/");
     $day = strtok(" -/");
     $year = strtok(" -/");
 }
Exemplo n.º 3
0
 /**
  * 规范读入的时间,该函数暂时未用到
  * @param unknown $val
  * @return string
  */
 function GetData($val)
 {
     $jd = GregorianToJD(1, 1, 1970);
     $gregorian = JDToGregorian($jd + intval($val) - 25569);
     return $gregorian;
     /**
      * 格林威治时间的转换
      */
 }
Exemplo n.º 4
0
function excelTime($days, $time = false)
{
    if (is_numeric($days)) {
        //based on 1900-1-1
        $jd = GregorianToJD(1, 1, 1970);
        $gregorian = JDToGregorian($jd + intval($days) - 25569);
        $myDate = explode('/', $gregorian);
        $myDateStr = str_pad($myDate[2], 4, '0', STR_PAD_LEFT) . "-" . str_pad($myDate[0], 2, '0', STR_PAD_LEFT) . "-" . str_pad($myDate[1], 2, '0', STR_PAD_LEFT) . ($time ? " 00:00:00" : '');
        return $myDateStr;
    }
    return $days;
}
Exemplo n.º 5
0
function insertToEventTable($eventName, $eventDate, $duration)
{
    $calendar->insert_pistahan($eventDate, $eventName);
    // adjust duration
    $duration -= 1;
    // if duration is already 0, then exit. else call the function again to continue the insert
    if ($duration == 0) {
        return;
    }
    $eventDate = JDToGregorian(GregorianToJD(date("m", strtotime($eventDate)), date('j', strtotime($eventDate)), date('Y', strtotime($eventDate))) - 1);
    insertToEventTable($eventName, $eventDate, $duration);
    return;
}
Exemplo n.º 6
0
function excelTime($days, $time = false)
{
    // 如果需要导入年月日的时候采用,第一参数是PHPExcel取出来的,第二参数给false就行了
    // 把phpexcel读出的日期数据转换成xxxx-m-y
    if (is_numeric($days)) {
        $jd = GregorianToJD(1, 1, 1970);
        $gregorian = JDToGregorian($jd + intval($days) - 25569);
        $myDate = explode('/', $gregorian);
        $myDateStr = str_pad($myDate[2], 4, '0', STR_PAD_LEFT) . "-" . str_pad($myDate[0], 2, '0', STR_PAD_LEFT) . "-" . str_pad($myDate[1], 2, '0', STR_PAD_LEFT) . ($time ? " 00:00:00" : '');
        return $myDateStr;
    }
    return $days;
}
Exemplo n.º 7
0
 public function gawa_ng_kalendaryo($year)
 {
     $numberOfDays = 390;
     $newdayofweek = 1;
     $weekNumber = 1;
     $days = "+0 days";
     // check table for the last date on the the table
     $query = "SELECT juliandate FROM fiscalcalendar ORDER BY juliandate desc Limit 1";
     $result = fetch_record($query);
     if ($result['juliandate'] == 0) {
         $juliandate = gregoriantojd(01, 01, date('Y', strtotime($year)));
     } else {
         $juliandate = $result['juliandate'] + 1;
     }
     // $juliandate = gregoriantojd(01,01,date('Y',strtotime($days)));
     echo "<table border='5px'><thead><td>Julian Date</td><td>Gregorian Date</td><td>end of week</td><td>end of month</td><td>week#</td></thead><tbody>";
     for ($i = 0; $i <= $numberOfDays; $i++) {
         // check for end of week
         $days = JDToGregorian($juliandate);
         if (date('N', strtotime($days)) == 7) {
             $endOfWeek = 'Y';
         } else {
             $endOfWeek = 'N';
         }
         // end of year
         if (date("m", strtotime($days)) == 12 && date("j", strtotime($days)) == date("t", strtotime($days))) {
             $endofyear = 'Y';
         } else {
             $endofyear = 'N';
         }
         // end of month
         if (date("j", strtotime($days)) == date("t", strtotime($days))) {
             $endofmonth = 'Y';
         } else {
             $endofmonth = 'N';
         }
         if (date("j", strtotime($days)) == 1) {
             $weekNumber = 1;
             $newdayofweek = date('N', strtotime($days));
         } else {
             if ($newdayofweek == date('N', strtotime($days))) {
                 $weekNumber += 1;
             }
         }
         echo "<tr>" . $juliandate . '</td><td>' . JDToGregorian($juliandate) . '</td><td>' . $endOfWeek . '</td><td>' . $endofmonth . '</td><td>' . $weekNumber . '</td></tr>';
         $query = "INSERT INTO fiscalcalendar (juliandate,fdate, fmonth, fday, fyear, endOfWeek, endofmonth,  dayOfWeek, weekNumber) VALUES('" . $juliandate . "','" . date("y-m-d", strtotime($days)) . "'," . date("m", strtotime($days)) . "," . date('j', strtotime($days)) . "," . date('Y', strtotime($days)) . ",'" . $endOfWeek . "','" . $endofmonth . "','" . date('N', strtotime($days)) . "'," . $weekNumber . ")";
         $result = run_mysql_query($query);
         $juliandate += 1;
     }
 }
Exemplo n.º 8
0
function excelTime($date, $time = false)
{
    if (function_exists('GregorianToJD')) {
        if (is_numeric($date)) {
            $jd = GregorianToJD(1, 1, 1970);
            $gregorian = JDToGregorian($jd + intval($date) - 25569);
            $date = explode('/', $gregorian);
            $date_str = str_pad($date[2], 4, '0', STR_PAD_LEFT) . "-" . str_pad($date[0], 2, '0', STR_PAD_LEFT) . "-" . str_pad($date[1], 2, '0', STR_PAD_LEFT) . ($time ? " 00:00:00" : '');
            return $date_str;
        }
    } else {
        $date = $date > 25568 ? $date + 1 : 25569;
        /* There was a bug if Converting date before 1-1-1970 (tstamp 0) */
        $ofs = (70 * 365 + 17 + 2) * 86400;
        $date = date("Y-m-d", $date * 86400 - $ofs) . ($time ? " 00:00:00" : '');
    }
    return $date;
}
Exemplo n.º 9
0
 $dateinc = sprintf("%04d/%02d/%02d", $dd[2], $dd[0], $dd[1]);
 // next day date
 //day before
 $gregorian = JDToGregorian($jd - 1);
 // mm/dd/yyyy
 $dd = split("/", $gregorian);
 $datedec = sprintf("%04d/%02d/%02d", $dd[2], $dd[0], $dd[1]);
 // previous day date
 //next two day
 $gregorian = JDToGregorian($jd + 2);
 // mm/dd/yyyy
 $dd = split("/", $gregorian);
 $dateinc2 = sprintf("%04d/%02d/%02d", $dd[2], $dd[0], $dd[1]);
 // next day date
 //next three day
 $gregorian = JDToGregorian($jd + 3);
 // mm/dd/yyyy
 $dd = split("/", $gregorian);
 $dateinc3 = sprintf("%04d/%02d/%02d", $dd[2], $dd[0], $dd[1]);
 // next day date
 //		echo "$datedec, |$date|, $dateinc, $dateinc2, $dateinc3\n";
 $buffer = fgets($f2);
 $j = 0;
 while (substr($buffer, 0, 1) == " " and strlen($buffer) > 6) {
     $out = "";
     //echo " $date-$buffer\n";
     #time_start
     if (strlen(trim(substr($buffer, 1, 4))) == 4) {
         $out .= $date . " " . substr($buffer, 1, 2) . ":" . substr($buffer, 3, 2) . ":00\t";
         $et = substr($buffer, 1, 2) + substr($buffer, 3, 2) / 60;
         $m_start = substr($buffer, 1, 2) * 60 + substr($buffer, 3, 2);
Exemplo n.º 10
0
 public function setLocalDateAndTime($id, $date, $time)
 {
     global $objDatabase, $objLocation;
     if ($time >= 0) {
         $timezone = $objLocation->getLocationPropertyFromId($this->getDsObservationProperty($id, 'locationid'), 'timezone');
         $datearray = sscanf($date, "%4d%2d%2d");
         $dateTimeZone = new DateTimeZone($timezone);
         $date = sprintf("%02d", $datearray[1]) . "/" . sprintf("%02d", $datearray[2]) . "/" . $datearray[0];
         $dateTime = new DateTime($date, $dateTimeZone);
         // Returns the timedifference in seconds
         $timedifference = $dateTimeZone->getOffset($dateTime);
         $timedifference = $timedifference / 3600.0;
         $timestr = sscanf(sprintf("%04d", $time), "%2d%2d");
         $jd = cal_to_jd(CAL_GREGORIAN, $datearray[1], $datearray[2], $datearray[0]);
         $hours = $timestr[0] - (int) $timedifference;
         $timedifferenceminutes = ($timedifference - (int) $timedifference) * 60;
         $minutes = $timestr[1] - $timedifferenceminutes;
         if ($minutes < 0) {
             $hours = $hours - 1;
             $minutes = $minutes + 60;
         }
         if ($minutes > 60) {
             $hours = $hours + 1;
             $minutes = $minutes - 60;
         }
         if ($hours < 0) {
             $hours = $hours + 24;
             $jd = $jd - 1;
         }
         if ($hours >= 24) {
             $hours = $hours - 24;
             $jd = $jd + 1;
         }
         $time = $hours * 100 + $minutes;
         $dte = JDToGregorian($jd);
         sscanf($dte, "%2d/%2d/%4d", $month, $day, $year);
         $date = $year . sprintf("%02d", $month) . sprintf("%02d", $day);
     }
     $objDatabase->execSQL("UPDATE observations SET date = \"" . $date . "\" WHERE id = \"" . $id . "\"");
     $objDatabase->execSQL("UPDATE observations SET time = \"" . $time . "\" WHERE id = \"" . $id . "\"");
 }
Exemplo n.º 11
0
 function print_nice_date($jd)
 {
     // format of Thursday, Septemeber 22nd 2012
     if ($jd == 0) {
         return '';
     }
     $date = explode("/", JDToGregorian($jd));
     $output = jddayofweek($jd, 1) . ", " . jdmonthname($jd, 3) . " {$date[1]}, {$date[2]}";
     return $output;
 }
Exemplo n.º 12
0
    if (date("m", strtotime($days)) == 12 && date("j", strtotime($days)) == date("t", strtotime($days))) {
        $endofyear = 'Y';
    } else {
        $endofyear = 'N';
    }
    // end of month
    if (date("j", strtotime($days)) == date("t", strtotime($days))) {
        $endofmonth = 'Y';
    } else {
        $endofmonth = 'N';
    }
    if (date("j", strtotime($days)) == 1) {
        $weekNumber = 1;
        $newdayofweek = date('N', strtotime($days));
    } else {
        if ($newdayofweek == date('N', strtotime($days))) {
            $weekNumber += 1;
        }
    }
    echo "<tr>";
    echo "<td>" . $juliandate . '</td>';
    echo "<td>" . JDToGregorian($juliandate) . '</td>';
    echo '<td>' . $endOfWeek . '</td>';
    echo '<td>' . $endofmonth . '</td>';
    echo '<td>' . $weekNumber . '</td>';
    echo '</tr>';
    $query = "INSERT INTO fiscalcalendar (\n\t\tjuliandate,\n\t\tfdate, \n\t\tfmonth, \n\t\tfday, \n\t\tfyear, \n\t\tendOfWeek, \n\t\tendofmonth,  \n\t\tdayOfWeek, \n\t\tweekNumber) VALUES('" . $juliandate . "','" . date("y-m-d", strtotime($days)) . "'," . date("m", strtotime($days)) . "," . date('j', strtotime($days)) . "," . date('Y', strtotime($days)) . ",'" . $endOfWeek . "','" . $endofmonth . "','" . date('N', strtotime($days)) . "'," . $weekNumber . ")";
    // echo $query;die;
    $result = run_mysql_query($query);
    $juliandate += 1;
}
Exemplo n.º 13
0
 $dateinc = sprintf("%04d/%02d/%02d", $dd[2], $dd[0], $dd[1]);
 // next day date
 //day before
 $gregorian = JDToGregorian($jd - 1);
 // mm/dd/yyyy
 $dd = split("/", $gregorian);
 $datedec = sprintf("%04d/%02d/%02d", $dd[2], $dd[0], $dd[1]);
 // previous day date
 //next two day
 $gregorian = JDToGregorian($jd + 2);
 // mm/dd/yyyy
 $dd = split("/", $gregorian);
 $dateinc2 = sprintf("%04d/%02d/%02d", $dd[2], $dd[0], $dd[1]);
 // next day date
 //next three day
 $gregorian = JDToGregorian($jd + 2);
 // mm/dd/yyyy
 $dd = split("/", $gregorian);
 $dateinc3 = sprintf("%04d/%02d/%02d", $dd[2], $dd[0], $dd[1]);
 // next day date
 if (checkdate($mo, $d, $y)) {
     $date = sprintf("%04d/%02d/%02d", $y, $mo, $d);
 } else {
     $date = "";
 }
 //start time
 if (strlen(trim(substr($buffer, 13, 4))) == 4) {
     $m_start = substr($buffer, 13, 2) * 60 + substr($buffer, 15, 2);
     //start time in minutes
     if (substr($buffer, 13, 2) < 24) {
         $buf[$i++] = $date . " " . substr($buffer, 13, 2) . ":" . substr($buffer, 15, 2) . ":00";
 /**
  * Converts number of days since 24th November, 4714 B.C. (in the proleptic
  * Gregorian calendar, which is year -4713 using 'Astronomical' year
  * numbering) to Gregorian calendar date.
  *
  * Returned date belongs to the proleptic Gregorian calendar, using
  * 'Astronomical' year numbering.
  *
  * The algorithm is valid for all years (positive and negative), and
  * also for years preceding 4714 B.C. (i.e. for negative 'Julian Days'),
  * and so the only limitation is platform-dependent (for 32-bit systems
  * the maximum year would be something like about 1,465,190 A.D.).
  *
  * N.B. Monday, 24th November, 4714 B.C. is Julian Day '0'.
  *
  * Algorithm is from PEAR::Date_Calc
  *
  * @author Monte Ohrt <*****@*****.**>
  * @author Pierre-Alain Joye <*****@*****.**>
  * @author Daniel Convissor <*****@*****.**>
  * @author C.A. Woodcock <*****@*****.**>
  *
  * @param int    $days   the number of days since 24th November, 4714 B.C.
  * @param string $format the string indicating how to format the output
  *
  * @return  Horde_Date  A Horde_Date object representing the date.
  */
 public static function fromDays($days)
 {
     if (function_exists('JDToGregorian')) {
         list($month, $day, $year) = explode('/', JDToGregorian($days));
     } else {
         $days = intval($days);
         $days -= 1721119;
         $century = floor((4 * $days - 1) / 146097);
         $days = floor(4 * $days - 1 - 146097 * $century);
         $day = floor($days / 4);
         $year = floor((4 * $day + 3) / 1461);
         $day = floor(4 * $day + 3 - 1461 * $year);
         $day = floor(($day + 4) / 4);
         $month = floor((5 * $day - 3) / 153);
         $day = floor(5 * $day - 3 - 153 * $month);
         $day = floor(($day + 5) / 5);
         $year = $century * 100 + $year;
         if ($month < 10) {
             $month += 3;
         } else {
             $month -= 9;
             ++$year;
         }
     }
     return new Horde_Date($year, $month, $day);
 }
Exemplo n.º 15
0
 /**
  *@date 2010-7-22
  *@time 上午10:45:39
  */
 function excel_time($days = '40368')
 {
     //function
     if (is_numeric($days)) {
         $jd = gregoriantojd(1, 1, 1970);
         $gregorian = JDToGregorian($jd + intval($days) - 25569);
         $myDate = explode('/', $gregorian);
         $myDateStr = str_pad($myDate[2], 4, '0', STR_PAD_LEFT) . "-" . str_pad($myDate[0], 2, '0', STR_PAD_LEFT) . "-" . str_pad($myDate[1], 2, '0', STR_PAD_LEFT) . ($time ? " 00:00:00" : '');
         return $myDateStr;
     } else {
         return $days;
     }
 }
Exemplo n.º 16
0
 function excelTime($date, $time = false)
 {
     if (is_numeric($date)) {
         $jd = GregorianToJD(1, 1, 1970);
         $gregorian = JDToGregorian($jd + intval($date) - 25569);
         $date = explode('/', $gregorian);
         $date_str = str_pad($date[2], 4, '0', STR_PAD_LEFT) . "-" . str_pad($date[0], 2, '0', STR_PAD_LEFT) . "-" . str_pad($date[1], 2, '0', STR_PAD_LEFT) . ($time ? " 00:00:00" : '');
         return $date_str;
     }
     return $date;
 }
Exemplo n.º 17
0
if ($daytag != 1 || $week != 1) {
    $JDday = GregorianToJD($month, $day, $year);
    if ($daytag == "0") {
        $JDday -= 6;
    } else {
        $JDday = $JDday - ($daytag - 1);
    }
    switch ($week) {
        case 2:
            $JDday += 7;
            break;
        case 3:
            $JDday += 14;
            break;
    }
    $datebuf = JDToGregorian($JDday);
    //echo $datebuf;
    $arraybuf = explode("/", $datebuf);
    $month = $arraybuf[0];
    $day = $arraybuf[1];
    $year = $arraybuf[2];
    $daytag = date("w", mktime(0, 0, 0, $month, $day, $year));
}
if (!$mday) {
    if ($week == 1) {
        $mday = date(d);
        $mmonth = date(m);
        $myear = date(Y);
    } else {
        $mday = $day;
        $mmonth = $month;
Exemplo n.º 18
0
 /**
  * This will convert given Hijri date (Islamic calendar) into Gregorian date
  *          
  * @param integer $Y Hijri year (Islamic calendar)
  * @param integer $M Hijri month (Islamic calendar)
  * @param integer $D Hijri day (Islamic calendar)
  *      
  * @return array Gregorian date [int Year, int Month, int Day]
  * @author Khaled Al-Sham'aa <*****@*****.**>
  */
 protected function convertDate($Y, $M, $D)
 {
     if (function_exists('GregorianToJD')) {
         $str = JDToGregorian($this->islamicToJd($Y, $M, $D));
     } else {
         $str = $this->jdToGreg($this->islamicToJd($Y, $M, $D));
     }
     list($month, $day, $year) = explode('/', $str);
     return array($year, $month, $day);
 }
Exemplo n.º 19
0
 function getLocalDate($id)
 {
     global $objDatabase;
     $locations = new Locations();
     $sql = "SELECT * FROM cometobservations WHERE id = \"{$id}\"";
     $run = $objDatabase->selectRecordset($sql);
     $get = $run->fetch(PDO::FETCH_OBJ);
     if ($get) {
         $date = $get->date;
         $time = $get->time;
         $loc = $get->locationid;
         if ($loc) {
             if ($time >= 0) {
                 $date = sscanf($date, "%4d%2d%2d");
                 $timezone = $locations->getLocationPropertyFromId($loc, 'timezone');
                 $dateTimeZone = new DateTimeZone($timezone);
                 $datestr = sprintf("%02d", $date[1]) . "/" . sprintf("%02d", $date[2]) . "/" . $date[0];
                 $dateTime = new DateTime($datestr, $dateTimeZone);
                 // Geeft tijdsverschil terug in seconden
                 $timedifference = $dateTimeZone->getOffset($dateTime);
                 $timedifference = $timedifference / 3600.0;
                 $jd = cal_to_jd(CAL_GREGORIAN, $date[1], $date[2], $date[0]);
                 $time = sscanf(sprintf("%04d", $time), "%2d%2d");
                 $hours = $time[0] + (int) $timedifference;
                 $minutes = $time[1];
                 // We are converting from UT to local time -> we should add the time difference!
                 $timedifferenceminutes = ($timedifference - (int) $timedifference) * 60;
                 $minutes = $minutes + $timedifferenceminutes;
                 if ($minutes < 0) {
                     $hours = $hours - 1;
                     $minutes = $minutes + 60;
                 } else {
                     if ($minutes > 60) {
                         $hours = $hours + 1;
                         $minutes = $minutes - 60;
                     }
                 }
                 if ($hours < 0) {
                     $hours = $hours + 24;
                     $jd = $jd - 1;
                 }
                 if ($hours >= 24) {
                     $hours = $hours - 24;
                     $jd = $jd + 1;
                 }
                 $dte = JDToGregorian($jd);
                 sscanf($dte, "%2d/%2d/%4d", $month, $day, $year);
                 $date = sprintf("%d%02d%02d", $year, $month, $day);
             }
         }
     }
     return $date;
 }