예제 #1
0
function lastDay($year, $month)
{
    $days = array('01' => '31', '02' => '28', '03' => '31', '04' => '30', '05' => '31', '06' => '30', '07' => '31', '08' => '31', '09' => '30', '10' => '31', '11' => '30', '12' => '31');
    if (isLeapYear($year) && $month == 2) {
        return '29';
    } else {
        return $days[$month];
    }
}
function getJewishMonthName($month, $year)
{
    $monthNames = array("Tishrei", "Cheshvan", "Kislev", "Teves", "Shevat", "Adar I", "Adar II", "Nisan", "Iyar", "Sivan", "Tamuz", "Av", "Elul", "Adar");
    if ($month == 6) {
        if (isLeapYear($year)) {
            return $monthNames[5];
        } else {
            return $monthNames[13];
        }
    } else {
        if (isset($monthNames[$month - 1])) {
            return $monthNames[$month - 1];
        } else {
            return $monthNames[$month];
        }
        //comment why this is neccesary
    }
}
예제 #3
0
function getDaysOfMonth($strDate)
{
    //--- split the date
    $arrDate = split("[/.-]", $strDate);
    $strMonth = $arrDate[1];
    $strYear = $arrdate[2];
    //--- get the days of the month
    $nMonthLength = 0;
    if ($strMonth == 1 || $strMonth == 3 || $strMonth == 5 || $strMonth == 7 || $strMonth == 8 || $strMonth == 10 || $strMonth == 12) {
        $nMonthLength = 31;
    } else {
        if ($strMonth == 2) {
            if (isLeapYear($strYear)) {
                $nMonthLength = 29;
            } else {
                $nMonthLength = 28;
            }
        } else {
            $nMonthLength = 30;
        }
    }
    return $nMonthLength;
}
예제 #4
0
/**
 * RELATIVE DATES
 *
 * custom relative dates for comments and posts
 * @deprecated since 7.0
 * @since 6.0
 */
function relativeDate($posted_date)
{
    $tz = 0;
    // change this if your web server and weblog are in different timezones
    $month = substr($posted_date, 4, 2);
    if ($month == "02") {
        // february
        // check for leap year
        $leapYear = isLeapYear(substr($posted_date, 0, 4));
        if ($leapYear) {
            $month_in_seconds = 2505600;
        } else {
            $month_in_seconds = 2419200;
        }
    } else {
        // not february
        // check to see if the month has 30/31 days in it
        if ($month == "04" or $month == "06" or $month == "09" or $month == "11") {
            $month_in_seconds = 2592000;
        } else {
            $month_in_seconds = 2678400;
        }
        // 31 day month;
    }
    /* 
    some parts of this implementation borrowed from:
    http://maniacalrage.net/archives/2004/02/relativedatesusing/ 
    */
    $in_seconds = strtotime(substr($posted_date, 0, 8) . ' ' . substr($posted_date, 8, 2) . ':' . substr($posted_date, 10, 2) . ':' . substr($posted_date, 12, 2));
    $diff = time() - ($in_seconds + $tz * 3600);
    $months = floor($diff / $month_in_seconds);
    $diff -= $months * 2419200;
    $weeks = floor($diff / 604800);
    $diff -= $weeks * 604800;
    $days = floor($diff / 86400);
    $diff -= $days * 86400;
    $hours = floor($diff / 3600);
    $diff -= $hours * 3600;
    $minutes = floor($diff / 60);
    $diff -= $minutes * 60;
    $seconds = $diff;
    if ($months > 0) {
        // over a month old, just show date ("Month, Day Year")
        echo '';
        the_time('F jS, Y');
    } else {
        if ($weeks > 0) {
            // weeks and days
            $relative_date .= ($relative_date ? ', ' : '') . $weeks . ' ' . stripslashes(__('week', 'bizzthemes')) . '' . ($weeks > 1 ? '' . stripslashes(__('s', 'bizzthemes')) . '' : '');
            $relative_date .= $days > 0 ? ($relative_date ? ', ' : '') . $days . ' ' . stripslashes(__('day', 'bizzthemes')) . '' . ($days > 1 ? '' . stripslashes(__('s', 'bizzthemes')) . '' : '') : '';
        } elseif ($days > 0) {
            // days and hours
            $relative_date .= ($relative_date ? ', ' : '') . $days . ' ' . stripslashes(__('day', 'bizzthemes')) . '' . ($days > 1 ? '' . stripslashes(__('s', 'bizzthemes')) . '' : '');
            $relative_date .= $hours > 0 ? ($relative_date ? ', ' : '') . $hours . ' ' . stripslashes(__('hour', 'bizzthemes')) . '' . ($hours > 1 ? '' . stripslashes(__('s', 'bizzthemes')) . '' : '') : '';
        } elseif ($hours > 0) {
            // hours and minutes
            $relative_date .= ($relative_date ? ', ' : '') . $hours . ' ' . stripslashes(__('hour', 'bizzthemes')) . '' . ($hours > 1 ? '' . stripslashes(__('s', 'bizzthemes')) . '' : '');
            $relative_date .= $minutes > 0 ? ($relative_date ? ', ' : '') . $minutes . ' ' . stripslashes(__('minute', 'bizzthemes')) . '' . ($minutes > 1 ? '' . stripslashes(__('s', 'bizzthemes')) . '' : '') : '';
        } elseif ($minutes > 0) {
            // minutes only
            $relative_date .= ($relative_date ? ', ' : '') . $minutes . ' ' . stripslashes(__('minute', 'bizzthemes')) . '' . ($minutes > 1 ? '' . stripslashes(__('s', 'bizzthemes')) . '' : '');
        } else {
            // seconds only
            $relative_date .= ($relative_date ? ', ' : '') . $seconds . ' ' . stripslashes(__('minute', 'bizzthemes')) . '' . ($seconds > 1 ? '' . stripslashes(__('s', 'bizzthemes')) . '' : '');
        }
        // show relative date and add proper verbiage
        echo '' . stripslashes(__('Posted', 'bizzthemes')) . ' ' . $relative_date . ' ' . stripslashes(__('ago', 'bizzthemes')) . '';
    }
}
예제 #5
0
function gregorianToISO($day, $month, $year)
{
    $mnth = array(0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334);
    $y_isleap = isLeapYear($year);
    $y_1_isleap = isLeapYear($year - 1);
    $day_of_year_number = $day + $mnth[$month - 1];
    if ($y_isleap && $month > 2) {
        $day_of_year_number++;
    }
    // find Jan 1 weekday (monday = 1, sunday = 7)
    $yy = ($year - 1) % 100;
    $c = $year - 1 - $yy;
    $g = $yy + intval($yy / 4);
    $jan1_weekday = 1 + intval(($c / 100 % 4 * 5 + $g) % 7);
    // JGH added next if/else to compensate for week begins on Sunday
    if (!$GLOBALS["WEEK_START"] && $jan1_weekday < 7) {
        $jan1_weekday++;
    } elseif (!$GLOBALS["WEEK_START"] && $jan1_weekday == 7) {
        $jan1_weekday = 1;
    }
    // weekday for year-month-day
    $h = $day_of_year_number + ($jan1_weekday - 1);
    $weekday = 1 + intval(($h - 1) % 7);
    // find if Y M D falls in YearNumber Y-1, WeekNumber 52 or
    if ($day_of_year_number <= 8 - $jan1_weekday && $jan1_weekday > 4) {
        $yearnumber = $year - 1;
        if ($jan1_weekday == 5 || $jan1_weekday == 6 && $y_1_isleap) {
            $weeknumber = 53;
        } else {
            $weeknumber = 52;
        }
    } else {
        $yearnumber = $year;
    }
    // find if Y M D falls in YearNumber Y+1, WeekNumber 1
    if ($yearnumber == $year) {
        if ($y_isleap) {
            $i = 366;
        } else {
            $i = 365;
        }
        if ($i - $day_of_year_number < 4 - $weekday) {
            $yearnumber++;
            $weeknumber = 1;
        }
    }
    // find if Y M D falls in YearNumber Y, WeekNumber 1 through 53
    if ($yearnumber == $year) {
        $j = $day_of_year_number + (7 - $weekday) + ($jan1_weekday - 1);
        $weeknumber = intval($j / 7);
        if ($jan1_weekday > 4) {
            $weeknumber--;
        }
    }
    // put it all together
    if ($weeknumber < 10) {
        $weeknumber = '0' . $weeknumber;
    }
    return "{$yearnumber}-{$weeknumber}-{$weekday}";
}
	<link rel="stylesheet" type="text/css" href="http://web-backend.local/css/directory.css">
	<link rel="stylesheet" type="text/css" href="http://web-backend.local/css/facade.css">
</head>

<body class="web-backend-inleiding">
	
	<section class="body">

		<h1>Voorbeeld van functie met &eacute;&eacute;n parameter</h1>

		<p>Is dit cijfer een schrikkeljaar?</p>

		<ul>
			<li>1800: <?php 
echo isLeapYear(1800) ? "ja" : "nee";
?>
</li>
			<li>2000: <?php 
echo isLeapYear(2000) ? "ja" : "nee";
?>
</li>
			<li>2012: <?php 
echo isLeapYear(2012) ? "ja" : "nee";
?>
</li>
		</ul>

	</section>

</body>
</html>
function gregorianToISO($day, $month, $year)
{
    global $WEEK_START;
    $mnth = array(0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334);
    $y_isleap = isLeapYear($year);
    $day_of_year_number = $day + $mnth[$month - 1];
    if ($y_isleap && $month > 2) {
        $day_of_year_number++;
    }
    // Find Jan 1 weekday (Monday = 1, Sunday = 7).
    $yy = ($year - 1) % 100;
    $jan1_weekday = 1 + intval((($year - 1 - $yy / 100) % 4 * 5 + $yy + intval($yy / 4)) % 7);
    // JGH added next if/else to compensate for week begins on Sunday.
    if (!$WEEK_START) {
        if ($jan1_weekday < 7) {
            $jan1_weekday++;
        } elseif ($jan1_weekday == 7) {
            $jan1_weekday = 1;
        }
    }
    // Weekday for year-month-day.
    $weekday = 1 + intval(($day_of_year_number + ($jan1_weekday - 1) - 1) % 7);
    $yearnumber = $year;
    // Find if Y M D falls in YearNumber Y-1, WeekNumber 52.
    if ($day_of_year_number <= 8 - $jan1_weekday && $jan1_weekday > 4) {
        $weeknumber = $jan1_weekday == 5 || $jan1_weekday == 6 && isLeapYear($year - 1) ? 53 : 52;
        $yearnumber--;
    }
    // Find if Y M D falls in YearNumber Y+1, WeekNumber 1.
    if ($yearnumber == $year) {
        $i = 365;
        if ($y_isleap) {
            $i++;
        }
        if ($i - $day_of_year_number < 4 - $weekday) {
            $weeknumber = 1;
            $yearnumber++;
        }
    }
    // Find if Y M D falls in YearNumber Y, WeekNumber 1 through 53.
    if ($yearnumber == $year) {
        $weeknumber = intval(($day_of_year_number + (7 - $weekday) + ($jan1_weekday - 1)) / 7);
        if ($jan1_weekday > 4) {
            $weeknumber--;
        }
    }
    // Put it all together.
    if ($weeknumber < 10) {
        $weeknumber = '0' . $weeknumber;
    }
    return "{$yearnumber}-{$weeknumber}-{$weekday}";
}
예제 #8
0
/**
* Return the days in a month
* Given an integer month number 1-12, and an optional
* year (defaults to current) this function returns
* the number of days in the given month.
* @param integer $monthno  Month no. 1 - 12
* @param integer $year     Year
* @return integer Number of days in month
*/
function daysinmonth($monthno, $year = 0)
{
    global $monthlengths;
    $numdays = 0;
    if ($monthno >= 1 && $monthno <= 12) {
        $numdays = $monthlengths[$monthno];
        // The leap year crappola..
        if ($monthno == 2) {
            if ($year == 0) {
                $datetoday = getdate();
                $year = $datetoday["year"];
            }
            if (isLeapYear($year)) {
                $numdays += 1;
            }
        }
    }
    return $numdays;
}
function Generate_Date_Range($station_id, $Past_year)
{
    global $No_Past_year;
    $Current_Month = Date('m');
    $Current_Year = Date('Y');
    $Last_Year = Date('Y', strtotime('-' . $No_Past_year . 'years'));
    $Last_Month = Date('m', strtotime('-' . $No_Past_year . 'years'));
    foreach ($Past_year as $year) {
        $Total_Month = 12;
        $Month = 1;
        if ((int) $Last_Year == (int) $year) {
            $Month = (int) $Last_Month;
        }
        while ($Month <= $Total_Month) {
            if ($Month == (int) $Last_Month && $year == (int) $Last_Year) {
                $first_day = Date('d', strtotime('-' . $No_Past_year . 'years'));
                $Start_timestamp = strtotime($first_day . '-' . $Month . '-' . $year);
                $last_day = Date('d', strtotime('last day of' . $Month . 'month'));
                $End_timestamp = strtotime($last_day . '-' . $Month . '-' . $year);
                $End_timestamp = strtotime('+1 day', $End_timestamp);
            } else {
                if ($Month == (int) $Current_Month && $year == (int) $Current_Year) {
                    $last_day = Date('d');
                    $End_timestamp = strtotime($last_day . '-' . $Month . '-' . $year);
                    $End_timestamp = strtotime('+1 day', $End_timestamp);
                    $first_day = Date('d', strtotime('first day of' . $Month . 'month'));
                    $Start_timestamp = strtotime($first_day . '-' . $Month . '-' . $year);
                    $Total_Month = $Current_Month;
                } else {
                    if ($Month == 2 && isLeapYear($year)) {
                        $End_timestamp = strtotime('29-' . $Month . '-' . $year);
                        $End_timestamp = strtotime('+1 day', $End_timestamp);
                        $first_day = Date('d', strtotime('first day of' . $Month . 'month'));
                        $Start_timestamp = strtotime($first_day . '-' . $Month . '-' . $year);
                    } else {
                        $last_day = Date('d', strtotime('last day of' . $Month . 'month'));
                        $End_timestamp = strtotime($last_day . '-' . $Month . '-' . $year);
                        $End_timestamp = strtotime('+1 day', $End_timestamp);
                        $first_day = Date('d', strtotime('first day of' . $Month . 'month'));
                        $Start_timestamp = strtotime($first_day . '-' . $Month . '-' . $year);
                    }
                }
            }
            $jsonResult = Fetch_Data($station_id, $Start_timestamp, $End_timestamp);
            $result = json_decode($jsonResult, true);
            $totalResult = $result['cnt'];
            $count = 0;
            Write_Weather_Header($year, $Month);
            while ($count < $totalResult) {
                $array = convertMultiDimJsonToAssoc($result['list'][$count]);
                Write_Weather_Data($array, $year, $Month);
                $count++;
            }
            $Month++;
        }
    }
}
예제 #10
0
function parseDate($value)
{
    //сделано для возможности проставить прочерк
    if ('-' == $value) {
        return '-';
    }
    if (strlen($value) < 10) {
        return "NULL";
    }
    if ($value[2] != '.') {
        return "NULL";
    }
    if ($value[5] != '.') {
        return "NULL";
    }
    $day = substr($value, 0, 2);
    $month = substr($value, 3, 2);
    $year = substr($value, 6, 4);
    $_day = $day;
    $_month = $month;
    $_year = $year;
    settype($_day, 'integer');
    settype($_month, 'integer');
    settype($_year, 'integer');
    $_month = $_month - 1;
    $days = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
    if ($_year < 1900 || $_year > 2009) {
        return "NULL";
    }
    if ($_month < 0 || $_month > 11) {
        return "NULL";
    }
    if ($_day < 1 || $_month != 1 && $_day > $days[$_month] || $_month == 1 && isLeapYear($_year) && $_day > 29 || $_month == 1 && !isLeapYear($_year) && $_day > 28) {
        return "NULL";
    }
    return $day . '.' . $month . '.' . $year;
}