text:
<?php

/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
    /**
     * @ignore
     */
    define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
    require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
}

/**
 * PHPExcel_Calculation_DateTime
 *
 * @category    PHPExcel
 * @package        PHPExcel_Calculation
 * @copyright    Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
 */
class PHPExcel_Calculation_DateTime
{

    /**
     * Identify if a year is a leap year or not
     *
     * @param    integer $year The year to test
     * @return    boolean            TRUE if the year is a leap year, otherwise FALSE
     */
    public static function _isLeapYear($year)
    {
        return ((($year % 4) == 0) && (($year % 100) != 0) || (($year % 400) == 0));
    } //	function _isLeapYear()

    /**
     * Return the number of days between two dates based on a 360 day calendar
     *
     * @param    integer $startDay Day of month of the start date
     * @param    integer $startMonth Month of the start date
     * @param    integer $startYear Year of the start date
     * @param    integer $endDay Day of month of the start date
     * @param    integer $endMonth Month of the start date
     * @param    integer $endYear Year of the start date
     * @param    boolean $methodUS Whether to use the US method or the European method of calculation
     * @return    integer    Number of days between the start date and the end date
     */
    private static function _dateDiff360($startDay, $startMonth, $startYear, $endDay, $endMonth, $endYear, $methodUS)
    {
        if ($startDay == 31) {
            --$startDay;
        } elseif ($methodUS && ($startMonth == 2 && ($startDay == 29 || ($startDay == 28 && !self::_isLeapYear($startYear))))) {
            $startDay = 30;
        }
        if ($endDay == 31) {
            if ($methodUS && $startDay != 30) {
                $endDay = 1;
                if ($endMonth == 12) {
                    ++$endYear;
                    $endMonth = 1;
                } else {
                    ++$endMonth;
                }
            } else {
                $endDay = 30;
            }
        }

        return $endDay + $endMonth * 30 + $endYear * 360 - $startDay - $startMonth * 30 - $startYear * 360;
    } //	function _dateDiff360()

    /**
     * _getDateValue
     *
     * @param    string $dateValue
     * @return    mixed    Excel date/time serial value, or string if error
     */
    public static function _getDateValue($dateValue)
    {
        if (!is_numeric($dateValue)) {
            if ((is_string($dateValue)) &&
                (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC)
            ) {
                return PHPExcel_Calculation_Functions::VALUE();
            }
            if ((is_object($dateValue)) && ($dateValue instanceof DateTime)) {
                $dateValue = PHPExcel_Shared_Date::PHPToExcel($dateValue);
            } else {
                $saveReturnDateType = PHPExcel_Calculation_Functions::getReturnDateType();
                PHPExcel_Calculation_Functions::setReturnDateType(PHPExcel_Calculation_Functions::RETURNDATE_EXCEL);
                $dateValue = self::DATEVALUE($dateValue);
                PHPExcel_Calculation_Functions::setReturnDateType($saveReturnDateType);
            }
        }
        return $dateValue;
    } //	function _getDateValue()

    /**
     * _getTimeValue
     *
     * @param    string $timeValue
     * @return    mixed    Excel date/time serial value, or string if error
     */
    private static function _getTimeValue($timeValue)
    {
        $saveReturnDateType = PHPExcel_Calculation_Functions::getReturnDateType();
        PHPExcel_Calculation_Functions::setReturnDateType(PHPExcel_Calculation_Functions::RETURNDATE_EXCEL);
        $timeValue = self::TIMEVALUE($timeValue);
        PHPExcel_Calculation_Functions::setReturnDateType($saveReturnDateType);
        return $timeValue;
    } //	function _getTimeValue()

    private static function _adjustDateByMonths($dateValue = 0, $adjustmentMonths = 0)
    {
        // Execute function
        $PHPDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($dateValue);
        $oMonth = (int)$PHPDateObject->format('m');
        $oYear = (int)$PHPDateObject->format('Y');

        $adjustmentMonthsString = (string)$adjustmentMonths;
        if ($adjustmentMonths > 0) {
            $adjustmentMonthsString = '+' . $adjustmentMonths;
        }
        if ($adjustmentMonths != 0) {
            $PHPDateObject->modify($adjustmentMonthsString . ' months');
        }
        $nMonth = (int)$PHPDateObject->format('m');
        $nYear = (int)$PHPDateObject->format('Y');

        $monthDiff = ($nMonth - $oMonth) + (($nYear - $oYear) * 12);
        if ($monthDiff != $adjustmentMonths) {
            $adjustDays = (int)$PHPDateObject->format('d');
            $adjustDaysString = '-' . $adjustDays . ' days';
            $PHPDateObject->modify($adjustDaysString);
        }
        return $PHPDateObject;
    } //	function _adjustDateByMonths()

    /**
     * DATETIMENOW
     *
     * Returns the current date and time.
     * The NOW function is useful when you need to display the current date and time on a worksheet or
     * calculate a value based on the current date and time, and have that value updated each time you
     * open the worksheet.
     *
     * NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the date
     * and time format of your regional settings. PHPExcel does not change cell formatting in this way.
     *
     * Excel Function:
     *        NOW()
     *
     * @access    public
     * @category Date/Time Functions
     * @return    mixed    Excel date/time serial value, PHP date/time serial value or PHP date/time object,
     *                        depending on the value of the ReturnDateType flag
     */
    public static function DATETIMENOW()
    {
        $saveTimeZone = date_default_timezone_get();
        date_default_timezone_set('UTC');
        $retValue = False;
        switch (PHPExcel_Calculation_Functions::getReturnDateType()) {
            case PHPExcel_Calculation_Functions::RETURNDATE_EXCEL :
                $retValue = (float)PHPExcel_Shared_Date::PHPToExcel(time());
                break;
            case PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC :
                $retValue = (integer)time();
                break;
            case PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT :
                $retValue = new DateTime();
                break;
        }
        date_default_timezone_set($saveTimeZone);

        return $retValue;
    } //	function DATETIMENOW()

    /**
     * DATENOW
     *
     * Returns the current date.
     * The NOW function is useful when you need to display the current date and time on a worksheet or
     * calculate a value based on the current date and time, and have that value updated each time you
     * open the worksheet.
     *
     * NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the date
     * and time format of your regional settings. PHPExcel does not change cell formatting in this way.
     *
     * Excel Function:
     *        TODAY()
     *
     * @access    public
     * @category Date/Time Functions
     * @return    mixed    Excel date/time serial value, PHP date/time serial value or PHP date/time object,
     *                        depending on the value of the ReturnDateType flag
     */
    public static function DATENOW()
    {
        $saveTimeZone = date_default_timezone_get();
        date_default_timezone_set('UTC');
        $retValue = False;
        $excelDateTime = floor(PHPExcel_Shared_Date::PHPToExcel(time()));
        switch (PHPExcel_Calculation_Functions::getReturnDateType()) {
            case PHPExcel_Calculation_Functions::RETURNDATE_EXCEL :
                $retValue = (float)$excelDateTime;
                break;
            case PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC :
                $retValue = (integer)PHPExcel_Shared_Date::ExcelToPHP($excelDateTime);
                break;
            case PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT :
                $retValue = PHPExcel_Shared_Date::ExcelToPHPObject($excelDateTime);
                break;
        }
        date_default_timezone_set($saveTimeZone);

        return $retValue;
    } //	function DATENOW()

    /**
     * DATE
     *
     * The DATE function returns a value that represents a particular date.
     *
     * NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the date
     * format of your regional settings. PHPExcel does not change cell formatting in this way.
     *
     * Excel Function:
     *        DATE(year,month,day)
     *
     * PHPExcel is a lot more forgiving than MS Excel when passing non numeric values to this function.
     * A Month name or abbreviation (English only at this point) such as 'January' or 'Jan' will still be accepted,
     *     as will a day value with a suffix (e.g. '21st' rather than simply 21); again only English language.
     *
     * @access    public
     * @category Date/Time Functions
     * @param    integer $year The value of the year argument can include one to four digits.
     *                                Excel interprets the year argument according to the configured
     *                                date system: 1900 or 1904.
     *                                If year is between 0 (zero) and 1899 (inclusive), Excel adds that
     *                                value to 1900 to calculate the year. For example, DATE(108,1,2)
     *                                returns January 2, 2008 (1900+108).
     *                                If year is between 1900 and 9999 (inclusive), Excel uses that
     *                                value as the year. For example, DATE(2008,1,2) returns January 2,
     *                                2008.
     *                                If year is less than 0 or is 10000 or greater, Excel returns the
     *                                #NUM! error value.
     * @param    integer $month A positive or negative integer representing the month of the year
     *                                from 1 to 12 (January to December).
     *                                If month is greater than 12, month adds that number of months to
     *                                the first month in the year specified. For example, DATE(2008,14,2)
     *                                returns the serial number representing February 2, 2009.
     *                                If month is less than 1, month subtracts the magnitude of that
     *                                number of months, plus 1, from the first month in the year
     *                                specified. For example, DATE(2008,-3,2) returns the serial number
     *                                representing September 2, 2007.
     * @param    integer $day A positive or negative integer representing the day of the month
     *                                from 1 to 31.
     *                                If day is greater than the number of days in the month specified,
     *                                day adds that number of days to the first day in the month. For
     *                                example, DATE(2008,1,35) returns the serial number representing
     *                                February 4, 2008.
     *                                If day is less than 1, day subtracts the magnitude that number of
     *                                days, plus one, from the first day of the month specified. For
     *                                example, DATE(2008,1,-15) returns the serial number representing
     *                                December 16, 2007.
     * @return    mixed    Excel date/time serial value, PHP date/time serial value or PHP date/time object,
     *                        depending on the value of the ReturnDateType flag
     */
    public static function DATE($year = 0, $month = 1, $day = 1)
    {
        $year = PHPExcel_Calculation_Functions::flattenSingleValue($year);
        $month = PHPExcel_Calculation_Functions::flattenSingleValue($month);
        $day = PHPExcel_Calculation_Functions::flattenSingleValue($day);

        if (($month !== NULL) && (!is_numeric($month))) {
            $month = PHPExcel_Shared_Date::monthStringToNumber($month);
        }

        if (($day !== NULL) && (!is_numeric($day))) {
            $day = PHPExcel_Shared_Date::dayStringToNumber($day);
        }

        $year = ($year !== NULL) ? PHPExcel_Shared_String::testStringAsNumeric($year) : 0;
        $month = ($month !== NULL) ? PHPExcel_Shared_String::testStringAsNumeric($month) : 0;
        $day = ($day !== NULL) ? PHPExcel_Shared_String::testStringAsNumeric($day) : 0;
        if ((!is_numeric($year)) ||
            (!is_numeric($month)) ||
            (!is_numeric($day))
        ) {
            return PHPExcel_Calculation_Functions::VALUE();
        }
        $year = (integer)$year;
        $month = (integer)$month;
        $day = (integer)$day;

        $baseYear = PHPExcel_Shared_Date::getExcelCalendar();
        // Validate parameters
        if ($year < ($baseYear - 1900)) {
            return PHPExcel_Calculation_Functions::NaN();
        }
        if ((($baseYear - 1900) != 0) && ($year < $baseYear) && ($year >= 1900)) {
            return PHPExcel_Calculation_Functions::NaN();
        }

        if (($year < $baseYear) && ($year >= ($baseYear - 1900))) {
            $year += 1900;
        }

        if ($month < 1) {
            //	Handle year/month adjustment if month < 1
            --$month;
            $year += ceil($month / 12) - 1;
            $month = 13 - abs($month % 12);
        } elseif ($month > 12) {
            //	Handle year/month adjustment if month > 12
            $year += floor($month / 12);
            $month = ($month % 12);
        }

        // Re-validate the year parameter after adjustments
        if (($year < $baseYear) || ($year >= 10000)) {
            return PHPExcel_Calculation_Functions::NaN();
        }

        // Execute function
        $excelDateValue = PHPExcel_Shared_Date::FormattedPHPToExcel($year, $month, $day);
        switch (PHPExcel_Calculation_Functions::getReturnDateType()) {
            case PHPExcel_Calculation_Functions::RETURNDATE_EXCEL :
                return (float)$excelDateValue;
            case PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC :
                return (integer)PHPExcel_Shared_Date::ExcelToPHP($excelDateValue);
            case PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT :
                return PHPExcel_Shared_Date::ExcelToPHPObject($excelDateValue);
        }
    } //	function DATE()

    /**
     * TIME
     *
     * The TIME function returns a value that represents a particular time.
     *
     * NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the time
     * format of your regional settings. PHPExcel does not change cell formatting in this way.
     *
     * Excel Function:
     *        TIME(hour,minute,second)
     *
     * @access    public
     * @category Date/Time Functions
     * @param    integer $hour A number from 0 (zero) to 32767 representing the hour.
     *                                    Any value greater than 23 will be divided by 24 and the remainder
     *                                    will be treated as the hour value. For example, TIME(27,0,0) =
     *                                    TIME(3,0,0) = .125 or 3:00 AM.
     * @param    integer $minute A number from 0 to 32767 representing the minute.
     *                                    Any value greater than 59 will be converted to hours and minutes.
     *                                    For example, TIME(0,750,0) = TIME(12,30,0) = .520833 or 12:30 PM.
     * @param    integer $second A number from 0 to 32767 representing the second.
     *                                    Any value greater than 59 will be converted to hours, minutes,
     *                                    and seconds. For example, TIME(0,0,2000) = TIME(0,33,22) = .023148
     *                                    or 12:33:20 AM
     * @return    mixed    Excel date/time serial value, PHP date/time serial value or PHP date/time object,
     *                        depending on the value of the ReturnDateType flag
     */
    public static function TIME($hour = 0, $minute = 0, $second = 0)
    {
        $hour = PHPExcel_Calculation_Functions::flattenSingleValue($hour);
        $minute = PHPExcel_Calculation_Functions::flattenSingleValue($minute);
        $second = PHPExcel_Calculation_Functions::flattenSingleValue($second);

        if ($hour == '') {
            $hour = 0;
        }
        if ($minute == '') {
            $minute = 0;
        }
        if ($second == '') {
            $second = 0;
        }

        if ((!is_numeric($hour)) || (!is_numeric($minute)) || (!is_numeric($second))) {
            return PHPExcel_Calculation_Functions::VALUE();
        }
        $hour = (integer)$hour;
        $minute = (integer)$minute;
        $second = (integer)$second;

        if ($second < 0) {
            $minute += floor($second / 60);
            $second = 60 - abs($second % 60);
            if ($second == 60) {
                $second = 0;
            }
        } elseif ($second >= 60) {
            $minute += floor($second / 60);
            $second = $second % 60;
        }
        if ($minute < 0) {
            $hour += floor($minute / 60);
            $minute = 60 - abs($minute % 60);
            if ($minute == 60) {
                $minute = 0;
            }
        } elseif ($minute >= 60) {
            $hour += floor($minute / 60);
            $minute = $minute % 60;
        }

        if ($hour > 23) {
            $hour = $hour % 24;
        } elseif ($hour < 0) {
            return PHPExcel_Calculation_Functions::NaN();
        }

        // Execute function
        switch (PHPExcel_Calculation_Functions::getReturnDateType()) {
            case PHPExcel_Calculation_Functions::RETURNDATE_EXCEL :
                $date = 0;
                $calendar = PHPExcel_Shared_Date::getExcelCalendar();
                if ($calendar != PHPExcel_Shared_Date::CALENDAR_WINDOWS_1900) {
                    $date = 1;
                }
                return (float)PHPExcel_Shared_Date::FormattedPHPToExcel($calendar, 1, $date, $hour, $minute, $second);
            case PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC :
                return (integer)PHPExcel_Shared_Date::ExcelToPHP(PHPExcel_Shared_Date::FormattedPHPToExcel(1970, 1, 1, $hour, $minute, $second)); // -2147468400; //	-2147472000 + 3600
            case PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT :
                $dayAdjust = 0;
                if ($hour < 0) {
                    $dayAdjust = floor($hour / 24);
                    $hour = 24 - abs($hour % 24);
                    if ($hour == 24) {
                        $hour = 0;
                    }
                } elseif ($hour >= 24) {
                    $dayAdjust = floor($hour / 24);
                    $hour = $hour % 24;
                }
                $phpDateObject = new DateTime('1900-01-01 ' . $hour . ':' . $minute . ':' . $second);
                if ($dayAdjust != 0) {
                    $phpDateObject->modify($dayAdjust . ' days');
                }
                return $phpDateObject;
        }
    } //	function TIME()

    /**
     * DATEVALUE
     *
     * Returns a value that represents a particular date.
     * Use DATEVALUE to convert a date represented by a text string to an Excel or PHP date/time stamp
     * value.
     *
     * NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the date
     * format of your regional settings. PHPExcel does not change cell formatting in this way.
     *
     * Excel Function:
     *        DATEVALUE(dateValue)
     *
     * @access    public
     * @category Date/Time Functions
     * @param    string $dateValue Text that represents a date in a Microsoft Excel date format.
     *                                    For example, "1/30/2008" or "30-Jan-2008" are text strings within
     *                                    quotation marks that represent dates. Using the default date
     *                                    system in Excel for Windows, date_text must represent a date from
     *                                    January 1, 1900, to December 31, 9999. Using the default date
     *                                    system in Excel for the Macintosh, date_text must represent a date
     *                                    from January 1, 1904, to December 31, 9999. DATEVALUE returns the
     *                                    #VALUE! error value if date_text is out of this range.
     * @return    mixed    Excel date/time serial value, PHP date/time serial value or PHP date/time object,
     *                        depending on the value of the ReturnDateType flag
     */
    public static function DATEVALUE($dateValue = 1)
    {
        $dateValue = trim(PHPExcel_Calculation_Functions::flattenSingleValue($dateValue), '"');
        //	Strip any ordinals because they're allowed in Excel (English only)
        $dateValue = preg_replace('/(\d)(st|nd|rd|th)([ -\/])/Ui', '$1$3', $dateValue);
        //	Convert separators (/ . or space) to hyphens (should also handle dot used for ordinals in some countries, e.g. Denmark, Germany)
        $dateValue = str_replace(array('/', '.', '-', '  '), array(' ', ' ', ' ', ' '), $dateValue);

        $yearFound = false;
        $t1 = explode(' ', $dateValue);
        foreach ($t1 as &$t) {
            if ((is_numeric($t)) && ($t > 31)) {
                if ($yearFound) {
                    return PHPExcel_Calculation_Functions::VALUE();
                } else {
                    if ($t < 100) {
                        $t += 1900;
                    }
                    $yearFound = true;
                }
            }
        }
        if ((count($t1) == 1) && (strpos($t, ':') != false)) {
            //	We've been fed a time value without any date
            return 0.0;
        } elseif (count($t1) == 2) {
            //	We only have two parts of the date: either day/month or month/year
            if ($yearFound) {
                array_unshift($t1, 1);
            } else {
                array_push($t1, date('Y'));
            }
        }
        unset($t);
        $dateValue = implode(' ', $t1);

        $PHPDateArray = date_parse($dateValue);
        if (($PHPDateArray === False) || ($PHPDateArray['error_count'] > 0)) {
            $testVal1 = strtok($dateValue, '- ');
            if ($testVal1 !== False) {
                $testVal2 = strtok('- ');
                if ($testVal2 !== False) {
                    $testVal3 = strtok('- ');
                    if ($testVal3 === False) {
                        $testVal3 = strftime('%Y');
                    }
                } else {
                    return PHPExcel_Calculation_Functions::VALUE();
                }
            } else {
                return PHPExcel_Calculation_Functions::VALUE();
            }
            $PHPDateArray = date_parse($testVal1 . '-' . $testVal2 . '-' . $testVal3);
            if (($PHPDateArray === False) || ($PHPDateArray['error_count'] > 0)) {
                $PHPDateArray = date_parse($testVal2 . '-' . $testVal1 . '-' . $testVal3);
                if (($PHPDateArray === False) || ($PHPDateArray['error_count'] > 0)) {
                    return PHPExcel_Calculation_Functions::VALUE();
                }
            }
        }

        if (($PHPDateArray !== False) && ($PHPDateArray['error_count'] == 0)) {
            // Execute function
            if ($PHPDateArray['year'] == '') {
                $PHPDateArray['year'] = strftime('%Y');
            }
            if ($PHPDateArray['year'] < 1900)
                return PHPExcel_Calculation_Functions::VALUE();
            if ($PHPDateArray['month'] == '') {
                $PHPDateArray['month'] = strftime('%m');
            }
            if ($PHPDateArray['day'] == '') {
                $PHPDateArray['day'] = strftime('%d');
            }
            $excelDateValue = floor(PHPExcel_Shared_Date::FormattedPHPToExcel($PHPDateArray['year'], $PHPDateArray['month'], $PHPDateArray['day'], $PHPDateArray['hour'], $PHPDateArray['minute'], $PHPDateArray['second']));

            switch (PHPExcel_Calculation_Functions::getReturnDateType()) {
                case PHPExcel_Calculation_Functions::RETURNDATE_EXCEL :
                    return (float)$excelDateValue;
                case PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC :
                    return (integer)PHPExcel_Shared_Date::ExcelToPHP($excelDateValue);
                case PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT :
                    return new DateTime($PHPDateArray['year'] . '-' . $PHPDateArray['month'] . '-' . $PHPDateArray['day'] . ' 00:00:00');
            }
        }
        return PHPExcel_Calculation_Functions::VALUE();
    } //	function DATEVALUE()

    /**
     * TIMEVALUE
     *
     * Returns a value that represents a particular time.
     * Use TIMEVALUE to convert a time represented by a text string to an Excel or PHP date/time stamp
     * value.
     *
     * NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the time
     * format of your regional settings. PHPExcel does not change cell formatting in this way.
     *
     * Excel Function:
     *        TIMEVALUE(timeValue)
     *
     * @access    public
     * @category Date/Time Functions
     * @param    string $timeValue A text string that represents a time in any one of the Microsoft
     *                                    Excel time formats; for example, "6:45 PM" and "18:45" text strings
     *                                    within quotation marks that represent time.
     *                                    Date information in time_text is ignored.
     * @return    mixed    Excel date/time serial value, PHP date/time serial value or PHP date/time object,
     *                        depending on the value of the ReturnDateType flag
     */
    public static function TIMEVALUE($timeValue)
    {
        $timeValue = trim(PHPExcel_Calculation_Functions::flattenSingleValue($timeValue), '"');
        $timeValue = str_replace(array('/', '.'), array('-', '-'), $timeValue);

        $PHPDateArray = date_parse($timeValue);
        if (($PHPDateArray !== False) && ($PHPDateArray['error_count'] == 0)) {
            if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) {
                $excelDateValue = PHPExcel_Shared_Date::FormattedPHPToExcel($PHPDateArray['year'], $PHPDateArray['month'], $PHPDateArray['day'], $PHPDateArray['hour'], $PHPDateArray['minute'], $PHPDateArray['second']);
            } else {
                $excelDateValue = PHPExcel_Shared_Date::FormattedPHPToExcel(1900, 1, 1, $PHPDateArray['hour'], $PHPDateArray['minute'], $PHPDateArray['second']) - 1;
            }

            switch (PHPExcel_Calculation_Functions::getReturnDateType()) {
                case PHPExcel_Calculation_Functions::RETURNDATE_EXCEL :
                    return (float)$excelDateValue;
                case PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC :
                    return (integer)$phpDateValue = PHPExcel_Shared_Date::ExcelToPHP($excelDateValue + 25569) - 3600;;
                case PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT :
                    return new DateTime('1900-01-01 ' . $PHPDateArray['hour'] . ':' . $PHPDateArray['minute'] . ':' . $PHPDateArray['second']);
            }
        }
        return PHPExcel_Calculation_Functions::VALUE();
    } //	function TIMEVALUE()

    /**
     * DATEDIF
     *
     * @param    mixed $startDate Excel date serial value, PHP date/time stamp, PHP DateTime object
     *                                    or a standard date string
     * @param    mixed $endDate Excel date serial value, PHP date/time stamp, PHP DateTime object
     *                                    or a standard date string
     * @param    string $unit
     * @return    integer    Interval between the dates
     */
    public static function DATEDIF($startDate = 0, $endDate = 0, $unit = 'D')
    {
        $startDate = PHPExcel_Calculation_Functions::flattenSingleValue($startDate);
        $endDate = PHPExcel_Calculation_Functions::flattenSingleValue($endDate);
        $unit = strtoupper(PHPExcel_Calculation_Functions::flattenSingleValue($unit));

        if (is_string($startDate = self::_getDateValue($startDate))) {
            return PHPExcel_Calculation_Functions::VALUE();
        }
        if (is_string($endDate = self::_getDateValue($endDate))) {
            return PHPExcel_Calculation_Functions::VALUE();
        }

        // Validate parameters
        if ($startDate >= $endDate) {
            return PHPExcel_Calculation_Functions::NaN();
        }

        // Execute function
        $difference = $endDate - $startDate;

        $PHPStartDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($startDate);
        $startDays = $PHPStartDateObject->format('j');
        $startMonths = $PHPStartDateObject->format('n');
        $startYears = $PHPStartDateObject->format('Y');

        $PHPEndDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($endDate);
        $endDays = $PHPEndDateObject->format('j');
        $endMonths = $PHPEndDateObject->format('n');
        $endYears = $PHPEndDateObject->format('Y');

        $retVal = PHPExcel_Calculation_Functions::NaN();
        switch ($unit) {
            case 'D':
                $retVal = intval($difference);
                break;
            case 'M':
                $retVal = intval($endMonths - $startMonths) + (intval($endYears - $startYears) * 12);
                //	We're only interested in full months
                if ($endDays < $startDays) {
                    --$retVal;
                }
                break;
            case 'Y':
                $retVal = intval($endYears - $startYears);
                //	We're only interested in full months
                if ($endMonths < $startMonths) {
                    --$retVal;
                } elseif (($endMonths == $startMonths) && ($endDays < $startDays)) {
                    --$retVal;
                }
                break;
            case 'MD':
                if ($endDays < $startDays) {
                    $retVal = $endDays;
                    $PHPEndDateObject->modify('-' . $endDays . ' days');
                    $adjustDays = $PHPEndDateObject->format('j');
                    if ($adjustDays > $startDays) {
                        $retVal += ($adjustDays - $startDays);
                    }
                } else {
                    $retVal = $endDays - $startDays;
                }
                break;
            case 'YM':
                $retVal = intval($endMonths - $startMonths);
                if ($retVal < 0) $retVal = 12 + $retVal;
                //	We're only interested in full months
                if ($endDays < $startDays) {
                    --$retVal;
                }
                break;
            case 'YD':
                $retVal = intval($difference);
                if ($endYears > $startYears) {
                    while ($endYears > $startYears) {
                        $PHPEndDateObject->modify('-1 year');
                        $endYears = $PHPEndDateObject->format('Y');
                    }
                    $retVal = $PHPEndDateObject->format('z') - $PHPStartDateObject->format('z');
                    if ($retVal < 0) {
                        $retVal += 365;
                    }
                }
                break;
            default:
                $retVal = PHPExcel_Calculation_Functions::NaN();
        }
        return $retVal;
    } //	function DATEDIF()

    /**
     * DAYS360
     *
     * Returns the number of days between two dates based on a 360-day year (twelve 30-day months),
     * which is used in some accounting calculations. Use this function to help compute payments if
     * your accounting system is based on twelve 30-day months.
     *
     * Excel Function:
     *        DAYS360(startDate,endDate[,method])
     *
     * @access    public
     * @category Date/Time Functions
     * @param    mixed $startDate Excel date serial value (float), PHP date timestamp (integer),
     *                                        PHP DateTime object, or a standard date string
     * @param    mixed $endDate Excel date serial value (float), PHP date timestamp (integer),
     *                                        PHP DateTime object, or a standard date string
     * @param    boolean $method US or European Method
     *                                        FALSE or omitted: U.S. (NASD) method. If the starting date is
     *                                        the last day of a month, it becomes equal to the 30th of the
     *                                        same month. If the ending date is the last day of a month and
     *                                        the starting date is earlier than the 30th of a month, the
     *                                        ending date becomes equal to the 1st of the next month;
     *                                        otherwise the ending date becomes equal to the 30th of the
     *                                        same month.
     *                                        TRUE: European method. Starting dates and ending dates that
     *                                        occur on the 31st of a month become equal to the 30th of the
     *                                        same month.
     * @return    integer        Number of days between start date and end date
     */
    public static function DAYS360($startDate = 0, $endDate = 0, $method = false)
    {
        $startDate = PHPExcel_Calculation_Functions::flattenSingleValue($startDate);
        $endDate = PHPExcel_Calculation_Functions::flattenSingleValue($endDate);

        if (is_string($startDate = self::_getDateValue($startDate))) {
            return PHPExcel_Calculation_Functions::VALUE();
        }
        if (is_string($endDate = self::_getDateValue($endDate))) {
            return PHPExcel_Calculation_Functions::VALUE();
        }

        if (!is_bool($method)) {
            return PHPExcel_Calculation_Functions::VALUE();
        }

        // Execute function
        $PHPStartDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($startDate);
        $startDay = $PHPStartDateObject->format('j');
        $startMonth = $PHPStartDateObject->format('n');
        $startYear = $PHPStartDateObject->format('Y');

        $PHPEndDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($endDate);
        $endDay = $PHPEndDateObject->format('j');
        $endMonth = $PHPEndDateObject->format('n');
        $endYear = $PHPEndDateObject->format('Y');

        return self::_dateDiff360($startDay, $startMonth, $startYear, $endDay, $endMonth, $endYear, !$method);
    } //	function DAYS360()

    /**
     * YEARFRAC
     *
     * Calculates the fraction of the year represented by the number of whole days between two dates
     * (the start_date and the end_date).
     * Use the YEARFRAC worksheet function to identify the proportion of a whole year's benefits or
     * obligations to assign to a specific term.
     *
     * Excel Function:
     *        YEARFRAC(startDate,endDate[,method])
     *
     * @access    public
     * @category Date/Time Functions
     * @param    mixed $startDate Excel date serial value (float), PHP date timestamp (integer),
     *                                    PHP DateTime object, or a standard date string
     * @param    mixed $endDate Excel date serial value (float), PHP date timestamp (integer),
     *                                    PHP DateTime object, or a standard date string
     * @param    integer $method Method used for the calculation
     *                                        0 or omitted    US (NASD) 30/360
     *                                        1                Actual/actual
     *                                        2                Actual/360
     *                                        3                Actual/365
     *                                        4                European 30/360
     * @return    float    fraction of the year
     */
    public static function YEARFRAC($startDate = 0, $endDate = 0, $method = 0)
    {
        $startDate = PHPExcel_Calculation_Functions::flattenSingleValue($startDate);
        $endDate = PHPExcel_Calculation_Functions::flattenSingleValue($endDate);
        $method = PHPExcel_Calculation_Functions::flattenSingleValue($method);

        if (is_string($startDate = self::_getDateValue($startDate))) {
            return PHPExcel_Calculation_Functions::VALUE();
        }
        if (is_string($endDate = self::_getDateValue($endDate))) {
            return PHPExcel_Calculation_Functions::VALUE();
        }

        if (((is_numeric($method)) && (!is_string($method))) || ($method == '')) {
            switch ($method) {
                case 0    :
                    return self::DAYS360($startDate, $endDate) / 360;
                case 1    :
                    $days = self::DATEDIF($startDate, $endDate);
                    $startYear = self::YEAR($startDate);
                    $endYear = self::YEAR($endDate);
                    $years = $endYear - $startYear + 1;
                    $leapDays = 0;
                    if ($years == 1) {
                        if (self::_isLeapYear($endYear)) {
                            $startMonth = self::MONTHOFYEAR($startDate);
                            $endMonth = self::MONTHOFYEAR($endDate);
                            $endDay = self::DAYOFMONTH($endDate);
                            if (($startMonth < 3) ||
                                (($endMonth * 100 + $endDay) >= (2 * 100 + 29))
                            ) {
                                $leapDays += 1;
                            }
                        }
                    } else {
                        for ($year = $startYear; $year <= $endYear; ++$year) {
                            if ($year == $startYear) {
                                $startMonth = self::MONTHOFYEAR($startDate);
                                $startDay = self::DAYOFMONTH($startDate);
                                if ($startMonth < 3) {
                                    $leapDays += (self::_isLeapYear($year)) ? 1 : 0;
                                }
                            } elseif ($year == $endYear) {
                                $endMonth = self::MONTHOFYEAR($endDate);
                                $endDay = self::DAYOFMONTH($endDate);
                                if (($endMonth * 100 + $endDay) >= (2 * 100 + 29)) {
                                    $leapDays += (self::_isLeapYear($year)) ? 1 : 0;
                                }
                            } else {
                                $leapDays += (self::_isLeapYear($year)) ? 1 : 0;
                            }
                        }
                        if ($years == 2) {
                            if (($leapDays == 0) && (self::_isLeapYear($startYear)) && ($days > 365)) {
                                $leapDays = 1;
                            } elseif ($days < 366) {
                                $years = 1;
                            }
                        }
                        $leapDays /= $years;
                    }
                    return $days / (365 + $leapDays);
                case 2    :
                    return self::DATEDIF($startDate, $endDate) / 360;
                case 3    :
                    return self::DATEDIF($startDate, $endDate) / 365;
                case 4    :
                    return self::DAYS360($startDate, $endDate, True) / 360;
            }
        }
        return PHPExcel_Calculation_Functions::VALUE();
    } //	function YEARFRAC()

    /**
     * NETWORKDAYS
     *
     * Returns the number of whole working days between start_date and end_date. Working days
     * exclude weekends and any dates identified in holidays.
     * Use NETWORKDAYS to calculate employee benefits that accrue based on the number of days
     * worked during a specific term.
     *
     * Excel Function:
     *        NETWORKDAYS(startDate,endDate[,holidays[,holiday[,...]]])
     *
     * @access    public
     * @category Date/Time Functions
     * @param    mixed $startDate Excel date serial value (float), PHP date timestamp (integer),
     *                                            PHP DateTime object, or a standard date string
     * @param    mixed $endDate Excel date serial value (float), PHP date timestamp (integer),
     *                                            PHP DateTime object, or a standard date string
     * @param    mixed $holidays,... Optional series of Excel date serial value (float), PHP date
     *                                            timestamp (integer), PHP DateTime object, or a standard date
     *                                            strings that will be excluded from the working calendar, such
     *                                            as state and federal holidays and floating holidays.
     * @return    integer            Interval between the dates
     */
    public static function NETWORKDAYS($startDate, $endDate)
    {
        //	Retrieve the mandatory start and end date that are referenced in the function definition
        $startDate = PHPExcel_Calculation_Functions::flattenSingleValue($startDate);
        $endDate = PHPExcel_Calculation_Functions::flattenSingleValue($endDate);
        //	Flush the mandatory start and end date that are referenced in the function definition, and get the optional days
        $dateArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args());
        array_shift($dateArgs);
        array_shift($dateArgs);

        //	Validate the start and end dates
        if (is_string($startDate = $sDate = self::_getDateValue($startDate))) {
            return PHPExcel_Calculation_Functions::VALUE();
        }
        $startDate = (float)floor($startDate);
        if (is_string($endDate = $eDate = self::_getDateValue($endDate))) {
            return PHPExcel_Calculation_Functions::VALUE();
        }
        $endDate = (float)floor($endDate);

        if ($sDate > $eDate) {
            $startDate = $eDate;
            $endDate = $sDate;
        }

        // Execute function
        $startDoW = 6 - self::DAYOFWEEK($startDate, 2);
        if ($startDoW < 0) {
            $startDoW = 0;
        }
        $endDoW = self::DAYOFWEEK($endDate, 2);
        if ($endDoW >= 6) {
            $endDoW = 0;
        }

        $wholeWeekDays = floor(($endDate - $startDate) / 7) * 5;
        $partWeekDays = $endDoW + $startDoW;
        if ($partWeekDays > 5) {
            $partWeekDays -= 5;
        }

        //	Test any extra holiday parameters
        $holidayCountedArray = array();
        foreach ($dateArgs as $holidayDate) {
            if (is_string($holidayDate = self::_getDateValue($holidayDate))) {
                return PHPExcel_Calculation_Functions::VALUE();
            }
            if (($holidayDate >= $startDate) && ($holidayDate <= $endDate)) {
                if ((self::DAYOFWEEK($holidayDate, 2) < 6) && (!in_array($holidayDate, $holidayCountedArray))) {
                    --$partWeekDays;
                    $holidayCountedArray[] = $holidayDate;
                }
            }
        }

        if ($sDate > $eDate) {
            return 0 - ($wholeWeekDays + $partWeekDays);
        }
        return $wholeWeekDays + $partWeekDays;
    } //	function NETWORKDAYS()

    /**
     * WORKDAY
     *
     * Returns the date that is the indicated number of working days before or after a date (the
     * starting date). Working days exclude weekends and any dates identified as holidays.
     * Use WORKDAY to exclude weekends or holidays when you calculate invoice due dates, expected
     * delivery times, or the number of days of work performed.
     *
     * Excel Function:
     *        WORKDAY(startDate,endDays[,holidays[,holiday[,...]]])
     *
     * @access    public
     * @category Date/Time Functions
     * @param    mixed $startDate Excel date serial value (float), PHP date timestamp (integer),
     *                                        PHP DateTime object, or a standard date string
     * @param    integer $endDays The number of nonweekend and nonholiday days before or after
     *                                        startDate. A positive value for days yields a future date; a
     *                                        negative value yields a past date.
     * @param    mixed $holidays,... Optional series of Excel date serial value (float), PHP date
     *                                        timestamp (integer), PHP DateTime object, or a standard date
     *                                        strings that will be excluded from the working calendar, such
     *                                        as state and federal holidays and floating holidays.
     * @return    mixed    Excel date/time serial value, PHP date/time serial value or PHP date/time object,
     *                        depending on the value of the ReturnDateType flag
     */
    public static function WORKDAY($startDate, $endDays)
    {
        //	Retrieve the mandatory start date and days that are referenced in the function definition
        $startDate = PHPExcel_Calculation_Functions::flattenSingleValue($startDate);
        $endDays = PHPExcel_Calculation_Functions::flattenSingleValue($endDays);
        //	Flush the mandatory start date and days that are referenced in the function definition, and get the optional days
        $dateArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args());
        array_shift($dateArgs);
        array_shift($dateArgs);

        if ((is_string($startDate = self::_getDateValue($startDate))) || (!is_numeric($endDays))) {
            return PHPExcel_Calculation_Functions::VALUE();
        }
        $startDate = (float)floor($startDate);
        $endDays = (int)floor($endDays);
        //	If endDays is 0, we always return startDate
        if ($endDays == 0) {
            return $startDate;
        }

        $decrementing = ($endDays < 0) ? True : False;

        //	Adjust the start date if it falls over a weekend

        $startDoW = self::DAYOFWEEK($startDate, 3);
        if (self::DAYOFWEEK($startDate, 3) >= 5) {
            $startDate += ($decrementing) ? -$startDoW + 4 : 7 - $startDoW;
            ($decrementing) ? $endDays++ : $endDays--;
        }

        //	Add endDays
        $endDate = (float)$startDate + (intval($endDays / 5) * 7) + ($endDays % 5);

        //	Adjust the calculated end date if it falls over a weekend
        $endDoW = self::DAYOFWEEK($endDate, 3);
        if ($endDoW >= 5) {
            $endDate += ($decrementing) ? -$endDoW + 4 : 7 - $endDoW;
        }

        //	Test any extra holiday parameters
        if (!empty($dateArgs)) {
            $holidayCountedArray = $holidayDates = array();
            foreach ($dateArgs as $holidayDate) {
                if (($holidayDate !== NULL) && (trim($holidayDate) > '')) {
                    if (is_string($holidayDate = self::_getDateValue($holidayDate))) {
                        return PHPExcel_Calculation_Functions::VALUE();
                    }
                    if (self::DAYOFWEEK($holidayDate, 3) < 5) {
                        $holidayDates[] = $holidayDate;
                    }
                }
            }
            if ($decrementing) {
                rsort($holidayDates, SORT_NUMERIC);
            } else {
                sort($holidayDates, SORT_NUMERIC);
            }
            foreach ($holidayDates as $holidayDate) {
                if ($decrementing) {
                    if (($holidayDate <= $startDate) && ($holidayDate >= $endDate)) {
                        if (!in_array($holidayDate, $holidayCountedArray)) {
                            --$endDate;
                            $holidayCountedArray[] = $holidayDate;
                        }
                    }
                } else {
                    if (($holidayDate >= $startDate) && ($holidayDate <= $endDate)) {
                        if (!in_array($holidayDate, $holidayCountedArray)) {
                            ++$endDate;
                            $holidayCountedArray[] = $holidayDate;
                        }
                    }
                }
                //	Adjust the calculated end date if it falls over a weekend
                $endDoW = self::DAYOFWEEK($endDate, 3);
                if ($endDoW >= 5) {
                    $endDate += ($decrementing) ? -$endDoW + 4 : 7 - $endDoW;
                }

            }
        }

        switch (PHPExcel_Calculation_Functions::getReturnDateType()) {
            case PHPExcel_Calculation_Functions::RETURNDATE_EXCEL :
                return (float)$endDate;
            case PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC :
                return (integer)PHPExcel_Shared_Date::ExcelToPHP($endDate);
            case PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT :
                return PHPExcel_Shared_Date::ExcelToPHPObject($endDate);
        }
    } //	function WORKDAY()

    /**
     * DAYOFMONTH
     *
     * Returns the day of the month, for a specified date. The day is given as an integer
     * ranging from 1 to 31.
     *
     * Excel Function:
     *        DAY(dateValue)
     *
     * @param    mixed $dateValue Excel date serial value (float), PHP date timestamp (integer),
     *                                    PHP DateTime object, or a standard date string
     * @return    int        Day of the month
     */
    public static function DAYOFMONTH($dateValue = 1)
    {
        $dateValue = PHPExcel_Calculation_Functions::flattenSingleValue($dateValue);

        if (is_string($dateValue = self::_getDateValue($dateValue))) {
            return PHPExcel_Calculation_Functions::VALUE();
        } elseif ($dateValue == 0.0) {
            return 0;
        } elseif ($dateValue < 0.0) {
            return PHPExcel_Calculation_Functions::NaN();
        }

        // Execute function
        $PHPDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($dateValue);

        return (int)$PHPDateObject->format('j');
    } //	function DAYOFMONTH()

    /**
     * DAYOFWEEK
     *
     * Returns the day of the week for a specified date. The day is given as an integer
     * ranging from 0 to 7 (dependent on the requested style).
     *
     * Excel Function:
     *        WEEKDAY(dateValue[,style])
     *
     * @param    mixed $dateValue Excel date serial value (float), PHP date timestamp (integer),
     *                                    PHP DateTime object, or a standard date string
     * @param    int $style A number that determines the type of return value
     *                                        1 or omitted    Numbers 1 (Sunday) through 7 (Saturday).
     *                                        2                Numbers 1 (Monday) through 7 (Sunday).
     *                                        3                Numbers 0 (Monday) through 6 (Sunday).
     * @return    int        Day of the week value
     */
    public static function DAYOFWEEK($dateValue = 1, $style = 1)
    {
        $dateValue = PHPExcel_Calculation_Functions::flattenSingleValue($dateValue);
        $style = PHPExcel_Calculation_Functions::flattenSingleValue($style);

        if (!is_numeric($style)) {
            return PHPExcel_Calculation_Functions::VALUE();
        } elseif (($style < 1) || ($style > 3)) {
            return PHPExcel_Calculation_Functions::NaN();
        }
        $style = floor($style);

        if (is_string($dateValue = self::_getDateValue($dateValue))) {
            return PHPExcel_Calculation_Functions::VALUE();
        } elseif ($dateValue < 0.0) {
            return PHPExcel_Calculation_Functions::NaN();
        }

        // Execute function
        $PHPDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($dateValue);
        $DoW = $PHPDateObject->format('w');

        $firstDay = 1;
        switch ($style) {
            case 1:
                ++$DoW;
                break;
            case 2:
                if ($DoW == 0) {
                    $DoW = 7;
                }
                break;
            case 3:
                if ($DoW == 0) {
                    $DoW = 7;
                }
                $firstDay = 0;
                --$DoW;
                break;
        }
        if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_EXCEL) {
            //	Test for Excel's 1900 leap year, and introduce the error as required
            if (($PHPDateObject->format('Y') == 1900) && ($PHPDateObject->format('n') <= 2)) {
                --$DoW;
                if ($DoW < $firstDay) {
                    $DoW += 7;
                }
            }
        }

        return (int)$DoW;
    } //	function DAYOFWEEK()

    /**
     * WEEKOFYEAR
     *
     * Returns the week of the year for a specified date.
     * The WEEKNUM function considers the week containing January 1 to be the first week of the year.
     * However, there is a European standard that defines the first week as the one with the majority
     * of days (four or more) falling in the new year. This means that for years in which there are
     * three days or less in the first week of January, the WEEKNUM function returns week numbers
     * that are incorrect according to the European standard.
     *
     * Excel Function:
     *        WEEKNUM(dateValue[,style])
     *
     * @param    mixed $dateValue Excel date serial value (float), PHP date timestamp (integer),
     *                                    PHP DateTime object, or a standard date string
     * @param    boolean $method Week begins on Sunday or Monday
     *                                        1 or omitted    Week begins on Sunday.
     *                                        2                Week begins on Monday.
     * @return    int        Week Number
     */
    public static function WEEKOFYEAR($dateValue = 1, $method = 1)
    {
        $dateValue = PHPExcel_Calculation_Functions::flattenSingleValue($dateValue);
        $method = PHPExcel_Calculation_Functions::flattenSingleValue($method);

        if (!is_numeric($method)) {
            return PHPExcel_Calculation_Functions::VALUE();
        } elseif (($method < 1) || ($method > 2)) {
            return PHPExcel_Calculation_Functions::NaN();
        }
        $method = floor($method);

        if (is_string($dateValue = self::_getDateValue($dateValue))) {
            return PHPExcel_Calculation_Functions::VALUE();
        } elseif ($dateValue < 0.0) {
            return PHPExcel_Calculation_Functions::NaN();
        }

        // Execute function
        $PHPDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($dateValue);
        $dayOfYear = $PHPDateObject->format('z');
        $dow = $PHPDateObject->format('w');
        $PHPDateObject->modify('-' . $dayOfYear . ' days');
        $dow = $PHPDateObject->format('w');
        $daysInFirstWeek = 7 - (($dow + (2 - $method)) % 7);
        $dayOfYear -= $daysInFirstWeek;
        $weekOfYear = ceil($dayOfYear / 7) + 1;

        return (int)$weekOfYear;
    } //	function WEEKOFYEAR()

    /**
     * MONTHOFYEAR
     *
     * Returns the month of a date represented by a serial number.
     * The month is given as an integer, ranging from 1 (January) to 12 (December).
     *
     * Excel Function:
     *        MONTH(dateValue)
     *
     * @param    mixed $dateValue Excel date serial value (float), PHP date timestamp (integer),
     *                                    PHP DateTime object, or a standard date string
     * @return    int        Month of the year
     */
    public static function MONTHOFYEAR($dateValue = 1)
    {
        $dateValue = PHPExcel_Calculation_Functions::flattenSingleValue($dateValue);

        if (is_string($dateValue = self::_getDateValue($dateValue))) {
            return PHPExcel_Calculation_Functions::VALUE();
        } elseif ($dateValue < 0.0) {
            return PHPExcel_Calculation_Functions::NaN();
        }

        // Execute function
        $PHPDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($dateValue);

        return (int)$PHPDateObject->format('n');
    } //	function MONTHOFYEAR()

    /**
     * YEAR
     *
     * Returns the year corresponding to a date.
     * The year is returned as an integer in the range 1900-9999.
     *
     * Excel Function:
     *        YEAR(dateValue)
     *
     * @param    mixed $dateValue Excel date serial value (float), PHP date timestamp (integer),
     *                                    PHP DateTime object, or a standard date string
     * @return    int        Year
     */
    public static function YEAR($dateValue = 1)
    {
        $dateValue = PHPExcel_Calculation_Functions::flattenSingleValue($dateValue);

        if (is_string($dateValue = self::_getDateValue($dateValue))) {
            return PHPExcel_Calculation_Functions::VALUE();
        } elseif ($dateValue < 0.0) {
            return PHPExcel_Calculation_Functions::NaN();
        }

        // Execute function
        $PHPDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($dateValue);

        return (int)$PHPDateObject->format('Y');
    } //	function YEAR()

    /**
     * HOUROFDAY
     *
     * Returns the hour of a time value.
     * The hour is given as an integer, ranging from 0 (12:00 A.M.) to 23 (11:00 P.M.).
     *
     * Excel Function:
     *        HOUR(timeValue)
     *
     * @param    mixed $timeValue Excel date serial value (float), PHP date timestamp (integer),
     *                                    PHP DateTime object, or a standard time string
     * @return    int        Hour
     */
    public static function HOUROFDAY($timeValue = 0)
    {
        $timeValue = PHPExcel_Calculation_Functions::flattenSingleValue($timeValue);

        if (!is_numeric($timeValue)) {
            if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC) {
                $testVal = strtok($timeValue, '/-: ');
                if (strlen($testVal) < strlen($timeValue)) {
                    return PHPExcel_Calculation_Functions::VALUE();
                }
            }
            $timeValue = self::_getTimeValue($timeValue);
            if (is_string($timeValue)) {
                return PHPExcel_Calculation_Functions::VALUE();
            }
        }
        // Execute function
        if ($timeValue >= 1) {
            $timeValue = fmod($timeValue, 1);
        } elseif ($timeValue < 0.0) {
            return PHPExcel_Calculation_Functions::NaN();
        }
        $timeValue = PHPExcel_Shared_Date::ExcelToPHP($timeValue);

        return (int)gmdate('G', $timeValue);
    } //	function HOUROFDAY()

    /**
     * MINUTEOFHOUR
     *
     * Returns the minutes of a time value.
     * The minute is given as an integer, ranging from 0 to 59.
     *
     * Excel Function:
     *        MINUTE(timeValue)
     *
     * @param    mixed $timeValue Excel date serial value (float), PHP date timestamp (integer),
     *                                    PHP DateTime object, or a standard time string
     * @return    int        Minute
     */
    public static function MINUTEOFHOUR($timeValue = 0)
    {
        $timeValue = $timeTester = PHPExcel_Calculation_Functions::flattenSingleValue($timeValue);

        if (!is_numeric($timeValue)) {
            if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC) {
                $testVal = strtok($timeValue, '/-: ');
                if (strlen($testVal) < strlen($timeValue)) {
                    return PHPExcel_Calculation_Functions::VALUE();
                }
            }
            $timeValue = self::_getTimeValue($timeValue);
            if (is_string($timeValue)) {
                return PHPExcel_Calculation_Functions::VALUE();
            }
        }
        // Execute function
        if ($timeValue >= 1) {
            $timeValue = fmod($timeValue, 1);
        } elseif ($timeValue < 0.0) {
            return PHPExcel_Calculation_Functions::NaN();
        }
        $timeValue = PHPExcel_Shared_Date::ExcelToPHP($timeValue);

        return (int)gmdate('i', $timeValue);
    } //	function MINUTEOFHOUR()

    /**
     * SECONDOFMINUTE
     *
     * Returns the seconds of a time value.
     * The second is given as an integer in the range 0 (zero) to 59.
     *
     * Excel Function:
     *        SECOND(timeValue)
     *
     * @param    mixed $timeValue Excel date serial value (float), PHP date timestamp (integer),
     *                                    PHP DateTime object, or a standard time string
     * @return    int        Second
     */
    public static function SECONDOFMINUTE($timeValue = 0)
    {
        $timeValue = PHPExcel_Calculation_Functions::flattenSingleValue($timeValue);

        if (!is_numeric($timeValue)) {
            if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC) {
                $testVal = strtok($timeValue, '/-: ');
                if (strlen($testVal) < strlen($timeValue)) {
                    return PHPExcel_Calculation_Functions::VALUE();
                }
            }
            $timeValue = self::_getTimeValue($timeValue);
            if (is_string($timeValue)) {
                return PHPExcel_Calculation_Functions::VALUE();
            }
        }
        // Execute function
        if ($timeValue >= 1) {
            $timeValue = fmod($timeValue, 1);
        } elseif ($timeValue < 0.0) {
            return PHPExcel_Calculation_Functions::NaN();
        }
        $timeValue = PHPExcel_Shared_Date::ExcelToPHP($timeValue);

        return (int)gmdate('s', $timeValue);
    } //	function SECONDOFMINUTE()

    /**
     * EDATE
     *
     * Returns the serial number that represents the date that is the indicated number of months
     * before or after a specified date (the start_date).
     * Use EDATE to calculate maturity dates or due dates that fall on the same day of the month
     * as the date of issue.
     *
     * Excel Function:
     *        EDATE(dateValue,adjustmentMonths)
     *
     * @param    mixed $dateValue Excel date serial value (float), PHP date timestamp (integer),
     *                                        PHP DateTime object, or a standard date string
     * @param    int $adjustmentMonths The number of months before or after start_date.
     *                                        A positive value for months yields a future date;
     *                                        a negative value yields a past date.
     * @return    mixed    Excel date/time serial value, PHP date/time serial value or PHP date/time object,
     *                        depending on the value of the ReturnDateType flag
     */
    public static function EDATE($dateValue = 1, $adjustmentMonths = 0)
    {
        $dateValue = PHPExcel_Calculation_Functions::flattenSingleValue($dateValue);
        $adjustmentMonths = PHPExcel_Calculation_Functions::flattenSingleValue($adjustmentMonths);

        if (!is_numeric($adjustmentMonths)) {
            return PHPExcel_Calculation_Functions::VALUE();
        }
        $adjustmentMonths = floor($adjustmentMonths);

        if (is_string($dateValue = self::_getDateValue($dateValue))) {
            return PHPExcel_Calculation_Functions::VALUE();
        }

        // Execute function
        $PHPDateObject = self::_adjustDateByMonths($dateValue, $adjustmentMonths);

        switch (PHPExcel_Calculation_Functions::getReturnDateType()) {
            case PHPExcel_Calculation_Functions::RETURNDATE_EXCEL :
                return (float)PHPExcel_Shared_Date::PHPToExcel($PHPDateObject);
            case PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC :
                return (integer)PHPExcel_Shared_Date::ExcelToPHP(PHPExcel_Shared_Date::PHPToExcel($PHPDateObject));
            case PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT :
                return $PHPDateObject;
        }
    } //	function EDATE()

    /**
     * EOMONTH
     *
     * Returns the date value for the last day of the month that is the indicated number of months
     * before or after start_date.
     * Use EOMONTH to calculate maturity dates or due dates that fall on the last day of the month.
     *
     * Excel Function:
     *        EOMONTH(dateValue,adjustmentMonths)
     *
     * @param    mixed $dateValue Excel date serial value (float), PHP date timestamp (integer),
     *                                        PHP DateTime object, or a standard date string
     * @param    int $adjustmentMonths The number of months before or after start_date.
     *                                        A positive value for months yields a future date;
     *                                        a negative value yields a past date.
     * @return    mixed    Excel date/time serial value, PHP date/time serial value or PHP date/time object,
     *                        depending on the value of the ReturnDateType flag
     */
    public static function EOMONTH($dateValue = 1, $adjustmentMonths = 0)
    {
        $dateValue = PHPExcel_Calculation_Functions::flattenSingleValue($dateValue);
        $adjustmentMonths = PHPExcel_Calculation_Functions::flattenSingleValue($adjustmentMonths);

        if (!is_numeric($adjustmentMonths)) {
            return PHPExcel_Calculation_Functions::VALUE();
        }
        $adjustmentMonths = floor($adjustmentMonths);

        if (is_string($dateValue = self::_getDateValue($dateValue))) {
            return PHPExcel_Calculation_Functions::VALUE();
        }

        // Execute function
        $PHPDateObject = self::_adjustDateByMonths($dateValue, $adjustmentMonths + 1);
        $adjustDays = (int)$PHPDateObject->format('d');
        $adjustDaysString = '-' . $adjustDays . ' days';
        $PHPDateObject->modify($adjustDaysString);

        switch (PHPExcel_Calculation_Functions::getReturnDateType()) {
            case PHPExcel_Calculation_Functions::RETURNDATE_EXCEL :
                return (float)PHPExcel_Shared_Date::PHPToExcel($PHPDateObject);
            case PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC :
                return (integer)PHPExcel_Shared_Date::ExcelToPHP(PHPExcel_Shared_Date::PHPToExcel($PHPDateObject));
            case PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT :
                return $PHPDateObject;
        }
    } //	function EOMONTH()

} //	class PHPExcel_Calculation_DateTime


text:
package ocr

//Licensed under the Apache License, Version 2.0 (the "License");
//you may not use this file except in compliance with the License.
//You may obtain a copy of the License at
//
//http://www.apache.org/licenses/LICENSE-2.0
//
//Unless required by applicable law or agreed to in writing, software
//distributed under the License is distributed on an "AS IS" BASIS,
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//See the License for the specific language governing permissions and
//limitations under the License.
//
// Code generated by Alibaba Cloud SDK Code Generator.
// Changes may cause incorrect behavior and will be lost if the code is regenerated.

// DataInRecognizeMalaysiaIdentityCard is a nested struct in ocr response
type DataInRecognizeMalaysiaIdentityCard struct {
	AddressFirstLine  AddressFirstLine  `json:"AddressFirstLine" xml:"AddressFirstLine"`
	AddressSecondLine AddressSecondLine `json:"AddressSecondLine" xml:"AddressSecondLine"`
	AddressThirdLine  AddressThirdLine  `json:"AddressThirdLine" xml:"AddressThirdLine"`
	AddressFourthLine AddressFourthLine `json:"AddressFourthLine" xml:"AddressFourthLine"`
	AddressFifthLine  AddressFifthLine  `json:"AddressFifthLine" xml:"AddressFifthLine"`
	CardBox           CardBox           `json:"CardBox" xml:"CardBox"`
	DriveClass        DriveClass        `json:"DriveClass" xml:"DriveClass"`
	ExpiryDate        ExpiryDate        `json:"ExpiryDate" xml:"ExpiryDate"`
	IdNumber          IdNumber          `json:"IdNumber" xml:"IdNumber"`
	IssueDate         IssueDate         `json:"IssueDate" xml:"IssueDate"`
	NameFirstLine     NameFirstLine     `json:"NameFirstLine" xml:"NameFirstLine"`
	NameSecondLine    NameSecondLine    `json:"NameSecondLine" xml:"NameSecondLine"`
	Nationality       Nationality       `json:"Nationality" xml:"Nationality"`
	PortraitBox       PortraitBox       `json:"PortraitBox" xml:"PortraitBox"`
	Sex               Sex               `json:"Sex" xml:"Sex"`
}

redpajama_set_name: RedPajamaGithub


text:
package adt.bson.scalacheck

import org.bson.types.{Binary, ObjectId}
import org.joda.time.DateTime
import org.scalacheck.ops.time.joda.ImplicitJodaTimeGenerators
import org.scalacheck.{Arbitrary, Shrink}

trait CommonGenerators extends ImplicitJodaTimeGenerators {

  protected def halves[T](n: T)(implicit integral: Integral[T]): Stream[T] = {
    import integral._
    if (n == zero) Stream.empty
    else n #:: halves(n / fromInt(2))
  }

  protected def shrinkSameSign[T](value: T)(implicit integral: Integral[T]): Stream[T] = {
    import integral._
    zero #:: halves(value).map(value - _)
  }

  implicit val shrinkDateTime: Shrink[DateTime] = Shrink { datetime =>
    val shrinkMillis = shrinkSameSign(datetime.getMillis)
    shrinkMillis map { new DateTime(_, datetime.getZone) }
  }

  implicit def arbBinary(implicit arbBytes: Arbitrary[Array[Byte]]): Arbitrary[Binary] = Arbitrary {
    arbBytes.arbitrary.map(new Binary(_))
  }

  implicit def arbObjectId(implicit arbDate: Arbitrary[java.util.Date]): Arbitrary[ObjectId] = Arbitrary {
    for {
      date <- arbDate.arbitrary
    } yield new ObjectId(date)
  }
}


text:
[kakao](../../index.md) / [com.agoda.kakao.pager2](../index.md) / [KViewPager2](index.md) / [view](./view.md)

# view

`val view: `[`ViewInteractionDelegate`](../../com.agoda.kakao.delegate/-view-interaction-delegate/index.md)

Overrides [BaseActions.view](../../com.agoda.kakao.common.actions/-base-actions/view.md)

Overrides [AdapterAssertions.view](../../com.agoda.kakao.common.assertions/-adapter-assertions/view.md)

Overrides [BaseAssertions.view](../../com.agoda.kakao.common.assertions/-base-assertions/view.md)


text:
package blacksmyth.swing;

import java.awt.Dimension;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.Window;
import java.util.List;
import javax.swing.JComponent;

public class JUtilities {

  public static void centerWindow(Window window) {
    final Point screenCentre = getScreenCenterPoint();
    final Dimension windowSize = window.getSize();
    window.setLocation(
        (int) screenCentre.getX() - (windowSize.width  / 2),
        (int) screenCentre.getY() - (windowSize.height / 2)
    );
  }

  private static Dimension getScreenSize() {
    return Toolkit.getDefaultToolkit().getScreenSize();
  }

  private static Point getScreenCenterPoint() {
    final Dimension screenSize = getScreenSize();
    return new Point(screenSize.width  / 2, screenSize.height / 2);
  }

  public static void equalizeComponentSizes(List<JComponent> components) {
    resizeAllComponentsToSize(
        components,
        findMaxComponentSize(components)
    );
  }

  private static void resizeAllComponentsToSize(List<JComponent> components, Dimension newSize) {
    components.stream().forEach(
        (component) -> resize(component, newSize)
    );
  }

  private static void resize(JComponent component, Dimension size) {
    component.setPreferredSize(size);
    component.setMaximumSize(size);
    component.setMinimumSize(size);
  }

  private static Dimension findMaxComponentSize(List<JComponent> components) {
    return new Dimension(
        getMaxComponentWidth(components),
        getMaxComponentHeight(components)
    );
  }

  private static int getMaxComponentWidth(List<JComponent> components) {
    return components.stream()
        .max( (c1, c2) -> Integer.compare(c1.getPreferredSize().width, c2.getPreferredSize().width) )
        .get().getPreferredSize().width;
  }

  private static int getMaxComponentHeight(List<JComponent> components) {
    return components.stream()
            .max( (c1, c2) -> Integer.compare(c1.getPreferredSize().height, c2.getPreferredSize().height) )
            .get().getPreferredSize().height;
  }
}


text:
Caramel
=======

A bootstrap project to create fully dynamic websites using jaggery


text:
package com.geekcattle.core.interceptor;

import com.geekcattle.util.IpUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author geekcattle
 */
@Component
public class ResourceInterceptor extends HandlerInterceptorAdapter {

    private static final String USER_AGENT = "user-agent";
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
            throws Exception {
        if(logger.isDebugEnabled()){
            String uri = request.getRequestURI();
            logger.info(uri);
            logger.info("UserAgent: {}", request.getHeader(USER_AGENT));
            logger.info("用户访问地址: {}, 来路地址: {}", uri, IpUtil.getIpAddr(request));
        }
        return true;
    }

}


text:
You can come back to this page and switch the version of the docs you're reading at any time.

## Stable versions

The most recent version is recommended in production.

{{"demo": "pages/versions/StableVersions.js", "hideHeader": true}}

## Latest versions

Here you can find the latest unreleased documentation and code. You can use it to see what changes are coming and provide better feedback to Material-UI contributors.

{{"demo": "pages/versions/LatestVersions.js", "hideHeader": true}}

## Versioning strategy

We recognize that you need **stability** from the Material-UI library. Stability ensures that reusable components and libraries, tutorials, tools, and learned practices don't become obsolete unexpectedly. Stability is essential for the ecosystem around Material-UI to thrive.

This document contains **the practices that we follow** to provide you with a leading-edge UI library, balanced with stability. We strive to ensure that future changes are always introduced in a predictable way. We want everyone who depends on Material-UI to know when and how new features are added, and to be well-prepared when obsolete ones are removed.

Material-UI strictly follows [Semantic Versioning 2.0.0](https://semver.org/). Material-UI version numbers have three parts: `major.minor.patch`. The version number is incremented based on the level of change included in the release.

- **Major releases** contain significant new features, some but minimal developer assistance is expected during the update. When updating to a new major release, you may need to run update scripts, refactor code, run additional tests, and learn new APIs.
- **Minor releases** contain important new features. Minor releases are fully backward-compatible; no developer assistance is expected during update, but you can optionally modify your apps and libraries to begin using new APIs, features, and capabilities that were added in the release.
- **Patch releases** are low risk, contain bug fixes and small new features. No developer assistance is expected during update.

## Release frequency

We work toward a regular schedule of releases, so that you can plan and coordinate your updates with the continuing evolution of Material-UI.

In general, you can expect the following release cycle:

- A **major** release every 6 months.
- 1-3 **minor** releases for each major release.
- A **patch** release every week (anytime for urgent bugfix).

## Release schedule

> Disclaimer: The dates are offered as general guidance and may be adjusted by us when necessary to ensure delivery of a high-quality code.

| Date          | Version                    |
|:------------- |:-------------------------- |
| May 2019      | `@material-ui/core` v4.0.0 |
| December 2019 | `@material-ui/core` v5.0.0 |

You can follow [our milestones](https://github.com/mui-org/material-ui/milestones) for a more detailed overview.

## Support policy

We only support the latest version of Material-UI. We don't yet have the resources to offer [LTS](https://en.wikipedia.org/wiki/Long-term_support) releases.

## Deprecation practices

Sometimes **"breaking changes"**, such as the removal of support for select APIs and features, are necessary.

To make these transitions as easy as possible, we make two commitments to you:

- We work hard to minimize the number of breaking changes and to provide migration tools when possible.
- We follow the deprecation policy described here, so you have time to update your apps to the latest APIs and best practices.

To help ensure that you have sufficient time and a clear path to update, this is our deprecation policy:

- We announce deprecated features in the changelog, and when possible, with warnings at runtime.
- When we announce a deprecation, we also announce a recommended update path.
- We support existing use of a stable API during the deprecation period, so your code will keep working during that period.
- We only make peer dependency updates (React) that require changes to your apps in a major release.


text:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.9.1"/>
<title>Helix: Helix::Glob::IOAdapterFactory Class Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>

<link href="navtree.css" rel="stylesheet" type="text/css"/>

<link href="search/search.css" rel="stylesheet" type="text/css"/>

<link href="doxygen.css" rel="stylesheet" type="text/css" />

Helix

Main Page

Namespaces

Classes

Files

          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)"
               onblur="searchBox.OnSearchFieldFocus(false)"
               onkeyup="searchBox.OnSearchFieldChange(event)"/>

Class List

Class Index

Class Hierarchy

Class Members

Static Public Member Functions |
Static Protected Member Functions |
List of all members

Helix::Glob::IOAdapterFactory Class Reference

#include <IOAdapter.h>

Inheritance diagram for Helix::Glob::IOAdapterFactory:

  <map id="Helix::Glob::IOAdapterFactory_map" name="Helix::Glob::IOAdapterFactory_map">
<area href="classHelix_1_1Glob_1_1IOAdapterRegister.html" alt="Helix::Glob::IOAdapterRegister< T >" shape="rect" coords="0,56,352,80"/>
<area href="classHelix_1_1Glob_1_1IOAdapterRegister.html" alt="Helix::Glob::IOAdapterRegister< Helix::Glob::HttpIOAdapter >" shape="rect" coords="362,56,714,80"/>
</map>

Static Public Member Functions

static IOAdapter * 	createInstance (const twine &className)

Static Protected Member Functions

static iomap_type * 	getMap ()

Member Function Documentation

          IOAdapter * IOAdapterFactory::createInstance
          (
          const twine &
          className	)

static

          iomap_type * IOAdapterFactory::getMap
          (
          	)

staticprotected

The documentation for this class was generated from the following files:

glob/IOAdapter.h

glob/IOAdapter.cpp

Helix

Glob

IOAdapterFactory

Generated on Wed Jan 14 2015 12:23:31 for Helix by

     1.8.9.1


text:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DLLInjection {
    [Serializable]
    public class DLLInjectionFailedException : Exception {
        public DLLInjectionFailedException(string message) : base(message) { }
    }
}


text:
from django import template

from ..helpers import get_mapped_url, check_mapped_url

register = template.Library()

@register.simple_tag(takes_context=True)
def mapped_url(context, key):
    return get_mapped_url(key, context.get('request'))

@register.filter
def is_mapped_url(key):
    return check_mapped_url(key)


text:
author: alba
layout: post
permalink: /2005/03/07/590/
categories:
  - asides
tags:
  - asides
  - del.icio.us
---
[Beaterator][1] – rockstar games' real-time music sequencer and sampler in your browser

 [1]: http://www.beaterator.com/ "BEATERATOR"


text:
#ifndef INCLUDED_AERON_CONCURRENT_LOGBUFFER_LOG_APPENDER__
#define INCLUDED_AERON_CONCURRENT_LOGBUFFER_LOG_APPENDER__

#include <util/Index.h>
#include <concurrent/AtomicBuffer.h>
#include "LogBufferDescriptor.h"
#include "LogBuffer.h"

namespace aeron { namespace common { namespace concurrent { namespace logbuffer {

class LogAppender : public LogBuffer
{
public:
    enum ActionStatus
    {
        SUCCESS,
        TRIPPED,
        FAILURE
    };

    LogAppender(AtomicBuffer& logBuffer, AtomicBuffer& stateBuffer,
        std::uint8_t *defaultHdr, util::index_t defaultHdrLength, util::index_t maxFrameLength)
    : LogBuffer(logBuffer, stateBuffer),
        m_defaultHdr(defaultHdr),
        m_defaultHdrLength(defaultHdrLength),
        m_maxMessageLength(FrameDescriptor::calculateMaxMessageLength(capacity())),
        m_maxFrameLength(maxFrameLength),
        m_maxPayloadLength(m_maxFrameLength - defaultHdrLength)
    {
        FrameDescriptor::checkHeaderLength(defaultHdrLength);
        FrameDescriptor::checkMaxFrameLength(maxFrameLength);
    }

    inline util::index_t maxMessageLength()
    {
        return m_maxMessageLength;
    }

    inline util::index_t maxPayloadLength()
    {
        return m_maxPayloadLength;
    }

    inline util::index_t maxFrameLength()
    {
        return m_maxFrameLength;
    }

    inline ActionStatus append(AtomicBuffer& srcBuffer, util::index_t offset, util::index_t length)
    {
        checkMessageLength(length);

        if (length <= m_maxPayloadLength)
        {
            return appendUnfragmentedMessage(srcBuffer, offset, length);
        }

        return appendFragmentedMessage(srcBuffer, offset, length);
    }

    // TODO: add claim() API

private:
    std::uint8_t *m_defaultHdr;
    util::index_t m_defaultHdrLength;
    const util::index_t m_maxMessageLength;
    const util::index_t m_maxFrameLength;
    const util::index_t m_maxPayloadLength;

    ActionStatus appendUnfragmentedMessage(AtomicBuffer& srcBuffer, util::index_t srcOffset, util::index_t length)
    {
        const util::index_t frameLength = length + m_defaultHdrLength;
        const util::index_t alignedLength = util::BitUtil::align(frameLength, FrameDescriptor::FRAME_ALIGNMENT);
        const util::index_t frameOffset = getTailAndAdd(alignedLength);

        if (isBeyondLogBufferCapacity(frameOffset, alignedLength, capacity()))
        {
            if (frameOffset < capacity())
            {
                appendPaddingFrame(logBuffer(), frameOffset);
                return ActionStatus::TRIPPED;
            }
            else if (frameOffset == capacity())
            {
                return ActionStatus::TRIPPED;
            }

            return ActionStatus::FAILURE;
        }

        logBuffer().putBytes(frameOffset, m_defaultHdr, m_defaultHdrLength);
        logBuffer().putBytes(frameOffset + m_defaultHdrLength, srcBuffer, srcOffset, length);

        FrameDescriptor::frameFlags(logBuffer(), frameOffset, FrameDescriptor::UNFRAGMENTED);
        FrameDescriptor::frameTermOffset(logBuffer(), frameOffset, frameOffset);
        FrameDescriptor::frameLengthOrdered(logBuffer(), frameOffset, frameLength);

        return ActionStatus::SUCCESS;
    }

    ActionStatus appendFragmentedMessage(AtomicBuffer& srcBuffer, util::index_t srcOffset, util::index_t length)
    {
        const int numMaxPayloads = length / m_maxMessageLength;
        const util::index_t remainingPayload = length % m_maxPayloadLength;
        const util::index_t requiredCapacity =
            util::BitUtil::align(remainingPayload + m_defaultHdrLength, FrameDescriptor::FRAME_ALIGNMENT) +
                (numMaxPayloads * m_maxFrameLength);
        util::index_t frameOffset = getTailAndAdd(requiredCapacity);

        if (isBeyondLogBufferCapacity(frameOffset, requiredCapacity, capacity()))
        {
            if (frameOffset < capacity())
            {
                appendPaddingFrame(logBuffer(), frameOffset);
                return ActionStatus::TRIPPED;
            }
            else if (frameOffset == capacity())
            {
                return ActionStatus::TRIPPED;
            }

            return ActionStatus::FAILURE;
        }

        std::uint8_t flags = FrameDescriptor::BEGIN_FRAG;
        util::index_t remaining = length;

        do
        {
            const util::index_t bytesToWrite = std::min(remaining, m_maxPayloadLength);
            const util::index_t frameLength = bytesToWrite + m_defaultHdrLength;
            const util::index_t alignedLength = util::BitUtil::align(frameLength, FrameDescriptor::FRAME_ALIGNMENT);

            logBuffer().putBytes(frameOffset, m_defaultHdr, m_defaultHdrLength);
            logBuffer().putBytes(frameOffset + m_defaultHdrLength, srcBuffer, srcOffset + (length - remaining), bytesToWrite);

            FrameDescriptor::frameFlags(logBuffer(), frameOffset, flags);
            FrameDescriptor::frameTermOffset(logBuffer(), frameOffset, frameOffset);
            FrameDescriptor::frameLengthOrdered(logBuffer(), frameOffset, frameLength);

            flags = 0;
            frameOffset += alignedLength;
            remaining -= bytesToWrite;
        }
        while (remaining > 0);

        return ActionStatus::SUCCESS;
    }

    inline bool isBeyondLogBufferCapacity(util::index_t frameOffset, util::index_t alignedFrameLength, util::index_t capacity)
    {
        return (frameOffset + alignedFrameLength + m_defaultHdrLength) > capacity;
    }

    inline void appendPaddingFrame(AtomicBuffer& logBuffer, util::index_t frameOffset)
    {
        logBuffer.putBytes(frameOffset, m_defaultHdr, m_defaultHdrLength);

        FrameDescriptor::frameType(logBuffer, frameOffset, FrameDescriptor::PADDING_FRAME_TYPE);
        FrameDescriptor::frameFlags(logBuffer, frameOffset, FrameDescriptor::UNFRAGMENTED);
        FrameDescriptor::frameTermOffset(logBuffer, frameOffset, frameOffset);
        FrameDescriptor::frameLengthOrdered(logBuffer, frameOffset, capacity() - frameOffset);
    }

    inline std::int32_t getTailAndAdd(std::int32_t delta)
    {
        return stateBuffer().getAndAddInt32(LogBufferDescriptor::TAIL_COUNTER_OFFSET, delta);
    }

    inline void checkMessageLength(util::index_t length)
    {
        if (length > m_maxMessageLength)
        {
            throw util::IllegalArgumentException(
                util::strPrintf("encoded message exceeds maxMessageLength of %d, length=%d", m_maxMessageLength, length), SOURCEINFO);
        }
    }
};

}}}}

#endif


text:
package org.sonarsource.plugins.go.languages;

import org.apache.commons.lang.StringUtils;
import org.sonar.api.config.Settings;
import org.sonar.api.resources.AbstractLanguage;

import java.util.ArrayList;
import java.util.List;

/**
 * This class defines the fictive Go language.
 */
public final class GoLanguage extends AbstractLanguage {
  public static final String KEY = "go";
  private static final String NAME = "Go";
  private static final String FILE_SUFFIXES_PROPERTY_KEY = "sonar.go.file.suffixes";
  private static final String DEFAULT_FILE_SUFFIXES = "go";

  private final Settings settings;

  public GoLanguage(Settings settings) {
    super(KEY, NAME);
    this.settings = settings;
  }

  @Override
  public String[] getFileSuffixes() {
    String[] suffixes = filterEmptyStrings(settings.getStringArray(FILE_SUFFIXES_PROPERTY_KEY));
    if (suffixes.length == 0) {
      suffixes = StringUtils.split(DEFAULT_FILE_SUFFIXES, ",");
    }
    return suffixes;
  }

  private String[] filterEmptyStrings(String[] stringArray) {
    List<String> nonEmptyStrings = new ArrayList<>();
    for (String string : stringArray) {
      if (StringUtils.isNotBlank(string.trim())) {
        nonEmptyStrings.add(string.trim());
      }
    }
    return nonEmptyStrings.toArray(new String[nonEmptyStrings.size()]);
  }

}


text:
capn
====

A little demo 3rd party app that's a trivial but secure chat


text:
from django.contrib import admin

from sorl.thumbnail.admin import AdminImageMixin

from events.models import Event

class EventAdmin(AdminImageMixin, admin.ModelAdmin):

    # use objects instead of the default manager
    def queryset(self, request):
        # use our manager, rather than the default one
        qs = self.model.objects.get_query_set()

        # we need this from the superclass method
        # provide an altenrative so we don't try to get *None
        ordering = self.ordering or ()
        if ordering:
            qs = qs.order_by(*ordering)
        return qs

    list_display = ('__unicode__', 'start_date', 'end_date',)
    list_filter = ('start_date', 'end_date',)
    prepopulated_fields = {'slug': ['name']}
    search_fields = ['name', 'start_date', 'end_date', 'description']

admin.site.register(Event, EventAdmin)


text:
define(['balls'], function(Balls) {

  TestCase("test balls", {

    setUp: function () {
      this.boundingRect = { left: 0, top: 0, right: 100, bottom: 100};
    },

    tearDown: function () {
    },

    "test Balls constructor": function () {

      var balls = new Balls(this.boundingRect);
      assertTrue(balls instanceof Balls);
    },

    "test number of balls created": function () {

      var balls = new Balls(this.boundingRect, { num: 10 });
      assertEquals(10, balls._balls.length);
    }

  });

});


text:
import os
import zipfile
from collections import defaultdict
from unittest.mock import patch

from torchtext.datasets.wikitext103 import WikiText103
from torchtext.datasets.wikitext2 import WikiText2

from ..common.case_utils import TempDirMixin, zip_equal, get_random_unicode
from ..common.parameterized_utils import nested_params
from ..common.torchtext_test_case import TorchtextTestCase

def _get_mock_dataset(root_dir, base_dir_name):
    """
    root_dir: directory to the mocked dataset
    base_dir_name: WikiText103 or WikiText2
    """
    base_dir = os.path.join(root_dir, base_dir_name)
    temp_dataset_dir = os.path.join(base_dir, "temp_dataset_dir")
    os.makedirs(temp_dataset_dir, exist_ok=True)

    seed = 1
    mocked_data = defaultdict(list)
    file_names = ("wiki.train.tokens", "wiki.valid.tokens", "wiki.test.tokens")
    for file_name in file_names:
        csv_file = os.path.join(temp_dataset_dir, file_name)
        mocked_lines = mocked_data[file_name.split(".")[1]]
        with open(csv_file, "w", encoding="utf-8") as f:
            for i in range(5):
                rand_string = get_random_unicode(seed)
                dataset_line = f"{rand_string}\n"
                f.write(dataset_line)

                # append line to correct dataset split
                mocked_lines.append(dataset_line)
                seed += 1

    if base_dir_name == WikiText103.__name__:
        compressed_file = "wikitext-103-v1"
        arcname_folder = "wikitext-103"
    else:
        compressed_file = "wikitext-2-v1"
        arcname_folder = "wikitext-2"

    compressed_dataset_path = os.path.join(base_dir, compressed_file + ".zip")
    # create zip file from dataset folder
    with zipfile.ZipFile(compressed_dataset_path, "w") as zip_file:
        for file_name in file_names:
            txt_file = os.path.join(temp_dataset_dir, file_name)
            zip_file.write(txt_file, arcname=os.path.join(arcname_folder, file_name))

    return mocked_data

class TestWikiTexts(TempDirMixin, TorchtextTestCase):
    root_dir = None
    samples = []

    @classmethod
    def setUpClass(cls):
        super().setUpClass()
        cls.root_dir = cls.get_base_temp_dir()
        cls.patcher = patch("torchdata.datapipes.iter.util.cacheholder._hash_check", return_value=True)
        cls.patcher.start()

    @classmethod
    def tearDownClass(cls):
        cls.patcher.stop()
        super().tearDownClass()

    @nested_params([WikiText103, WikiText2], ["train", "valid", "test"])
    def test_wikitexts(self, wikitext_dataset, split):
        expected_samples = _get_mock_dataset(
            os.path.join(self.root_dir, "datasets"), base_dir_name=wikitext_dataset.__name__
        )[split]

        dataset = wikitext_dataset(root=self.root_dir, split=split)
        samples = list(dataset)
        for sample, expected_sample in zip_equal(samples, expected_samples):
            self.assertEqual(sample, expected_sample)

    @nested_params([WikiText103, WikiText2], ["train", "valid", "test"])
    def test_wikitexts_split_argument(self, wikitext_dataset, split):
        # call `_get_mock_dataset` to create mock dataset files
        _ = _get_mock_dataset(self.root_dir, wikitext_dataset.__name__)

        dataset1 = wikitext_dataset(root=self.root_dir, split=split)
        (dataset2,) = wikitext_dataset(root=self.root_dir, split=(split,))

        for d1, d2 in zip_equal(dataset1, dataset2):
            self.assertEqual(d1, d2)


text:
@implementation NSPCloudinaryImageURLPatcher

+(NSRegularExpression*)cloudinaryURLRegExp
{
    static NSRegularExpression* cloudinaryURLRegExp = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        NSError* regExpParsingError = nil;
        cloudinaryURLRegExp = [NSRegularExpression regularExpressionWithPattern:@"^http://res.cloudinary.com/([^/]*)(/image/upload.*)(/v\\d*/)(.*)$"
                                                                        options:0
                                                                          error:&regExpParsingError];
        NSAssert(!regExpParsingError, @"Error parsing cloudinary regular expression: %@", regExpParsingError);
    });
    return cloudinaryURLRegExp;
}

+(NSURL*)cloudinaryFillCropResizedImageURL:(NSURL*)URL cropSize:(CGSize)cropSize
{
    NSString* URLString = [URL absoluteString];
    NSArray* matches = [[self cloudinaryURLRegExp] matchesInString:URLString options:0 range:NSMakeRange(0, [URLString length])];
    NSTextCheckingResult* matchResult = [matches firstObject];
    if (!matchResult || [matchResult numberOfRanges] != 5) {
        return nil;
    }
    NSRange accountRange = [matchResult rangeAtIndex:1];
    NSRange imagePathRange = [matchResult rangeAtIndex:2];
    NSRange versionRange = [matchResult rangeAtIndex:3];
    NSRange filenameRange = [matchResult rangeAtIndex:4];
    NSString* account = [URLString substringWithRange:accountRange];
    NSString* imagePath = [URLString substringWithRange:imagePathRange];
    NSString* version = versionRange.location != NSNotFound ? [URLString substringWithRange:versionRange] : [NSString string];
    version = [version stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"/"]];
    NSString* filename = [URLString substringWithRange:filenameRange];

    NSString *resizeString = [NSString stringWithFormat:@"w_%ld,h_%ld,c_limit", (long)cropSize.width, (long)cropSize.height];
    NSString *resizedVersion = (CGSizeEqualToSize(cropSize, CGSizeZero)) ? version : [NSString stringWithFormat:@"%@/%@", resizeString, version];
    NSString *resizedURLString = [NSString stringWithFormat:@"http://res.cloudinary.com/%@%@/%@/%@", account, imagePath, resizedVersion, filename];

    return [NSURL URLWithString:resizedURLString];
}

#pragma mark - NSPImageURLPatcher

-(NSURL *)patchedURLFromURL:(NSURL *)url
{
    return [NSPCloudinaryImageURLPatcher cloudinaryFillCropResizedImageURL:url cropSize:self.imageCropSize];
}

-(NSURL*)patchedURLFromURL:(NSURL*)url cropSize:(CGSize)cropSize
{
    return [NSPCloudinaryImageURLPatcher cloudinaryFillCropResizedImageURL:url cropSize:cropSize];
}

@end


text:
<?php

declare(strict_types=1);

namespace Sylius\Behat\Service\Setter;

use Behat\Mink\Driver\Selenium2Driver;
use Behat\Mink\Session;
use FriendsOfBehat\SymfonyExtension\Driver\SymfonyDriver;
use Symfony\Component\BrowserKit\Cookie;

final class CookieSetter implements CookieSetterInterface
{
    /** @var Session */
    private $minkSession;

    /** @var array */
    private $minkParameters;

    public function __construct(Session $minkSession, $minkParameters)
    {
        if (!is_array($minkParameters) && !$minkParameters instanceof \ArrayAccess) {
            throw new \InvalidArgumentException(sprintf(
                '"$minkParameters" passed to "%s" has to be an array or implement "%s".',
                self::class,
                \ArrayAccess::class
            ));
        }

        $this->minkSession = $minkSession;
        $this->minkParameters = $minkParameters;
    }

    /**
     * {@inheritdoc}
     */
    public function setCookie($name, $value)
    {
        $this->prepareMinkSessionIfNeeded($this->minkSession);

        $driver = $this->minkSession->getDriver();

        if ($driver instanceof SymfonyDriver) {
            $driver->getClient()->getCookieJar()->set(
                new Cookie($name, $value, null, null, parse_url($this->minkParameters['base_url'], \PHP_URL_HOST))
            );

            return;
        }

        $this->minkSession->setCookie($name, $value);
    }

    private function prepareMinkSessionIfNeeded(Session $session): void
    {
        if ($this->shouldMinkSessionBePrepared($session)) {
            $session->visit(rtrim($this->minkParameters['base_url'], '/') . '/');
        }
    }

    private function shouldMinkSessionBePrepared(Session $session): bool
    {
        $driver = $session->getDriver();

        if ($driver instanceof SymfonyDriver) {
            return false;
        }

        if ($driver instanceof Selenium2Driver && $driver->getWebDriverSession() === null) {
            return true;
        }

        if (false !== strpos($session->getCurrentUrl(), $this->minkParameters['base_url'])) {
            return false;
        }

        return true;
    }
}