function ut_main()
{
    $locale_arr = array('en_US_CA');
    $datetype_arr = array(IntlDateFormatter::FULL, IntlDateFormatter::LONG, IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT, IntlDateFormatter::NONE);
    $res_str = '';
    $text_arr = array("Sunday, September 18, 3039 4:06:40 PM PT", "Thursday, December 18, 1969 8:49:59 AM PST", "12/18/69 8:49 AM", "20111218 08:49 AM", "19691218 08:49 AM");
    foreach ($text_arr as $text_entry) {
        $res_str .= "\n------------\n";
        $res_str .= "\nInput text is : {$text_entry}";
        $res_str .= "\n------------";
        foreach ($locale_arr as $locale_entry) {
            $res_str .= "\nLocale is : {$locale_entry}";
            $res_str .= "\n------------";
            foreach ($datetype_arr as $datetype_entry) {
                $res_str .= "\ndatetype = {$datetype_entry} ,timetype ={$datetype_entry}";
                $fmt = ut_datefmt_create($locale_entry, $datetype_entry, $datetype_entry);
                $pos = 0;
                $parsed = ut_datefmt_parse($fmt, $text_entry, $pos);
                if (intl_get_error_code() == U_ZERO_ERROR) {
                    $res_str .= "\nParsed text is : {$parsed}; Position = {$pos}";
                } else {
                    $res_str .= "\nError while parsing as: '" . intl_get_error_message() . "'; Position = {$pos}";
                }
            }
        }
    }
    $res_str .= "\n";
    return $res_str;
}
Exemple #2
0
function ut_main()
{
    $locale_arr = array('en_US_CA');
    $datetype_arr = array(IntlDateFormatter::FULL, IntlDateFormatter::LONG, IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT, IntlDateFormatter::NONE);
    $res_str = '';
    $text_arr = array(array("Sunday, September 18, 2039 4:06:40 PM PT", IntlDateFormatter::FULL, IntlDateFormatter::FULL), array("Wednesday, December 17, 1969 6:40:00 PM PT", IntlDateFormatter::FULL, IntlDateFormatter::FULL), array("Thursday, December 18, 1969 8:49:59 PM PST", IntlDateFormatter::FULL, IntlDateFormatter::FULL), array("December 18, 1969 8:49:59 AM PST", IntlDateFormatter::LONG, IntlDateFormatter::FULL), array("12/18/69 8:49 AM", IntlDateFormatter::SHORT, IntlDateFormatter::SHORT), array("19691218 08:49 AM", IntlDateFormatter::SHORT, IntlDateFormatter::SHORT), array("Sunday, September 18, 2039 4:06:40 PM PT", IntlDateFormatter::FULL, IntlDateFormatter::NONE), array("Sunday, September 18, 2039 4:06:40 PM PT", IntlDateFormatter::FULL, IntlDateFormatter::SHORT), array("December 18, 1969 8:49:59 AM PST", IntlDateFormatter::LONG, IntlDateFormatter::NONE), array("December 18, 1969 8:49:59 AM PST", IntlDateFormatter::LONG, IntlDateFormatter::SHORT), array("12/18/69 8:49 AM", IntlDateFormatter::SHORT, IntlDateFormatter::LONG), array("19691218 08:49 AM", IntlDateFormatter::SHORT, IntlDateFormatter::LONG));
    foreach ($text_arr as $text_entry) {
        $fmt = ut_datefmt_create('en_US_CA', $text_entry[1], $text_entry[2]);
        $parse_pos = 0;
        $parsed = ut_datefmt_parse($fmt, $text_entry[0], $parse_pos);
        $res_str .= "\nInput text : {$text_entry[0]} ; DF = {$text_entry[1]}; TF = {$text_entry[2]}";
        if (intl_get_error_code() != U_ZERO_ERROR) {
            $res_str .= "\nError : " . intl_get_error_message();
        }
        $res_str .= "\nParsed: {$parsed}; parse_pos : {$parse_pos}\n";
    }
    return $res_str;
}
function ut_main()
{
    $timezone = 'GMT+05:00';
    $locale_arr = array('en_US');
    $datetype_arr = array(IntlDateFormatter::FULL, IntlDateFormatter::LONG, IntlDateFormatter::MEDIUM);
    $res_str = '';
    $time_arr = array(0, -1200000, 1200000, 2200000000, -2200000000, 90099999, 3600, -3600);
    $localtime_arr1 = array('tm_sec' => 24, 'tm_min' => 3, 'tm_hour' => 19, 'tm_mday' => 3, 'tm_mon' => 3, 'tm_year' => 105);
    $localtime_arr2 = array('tm_sec' => 21, 'tm_min' => 5, 'tm_hour' => 7, 'tm_mday' => 13, 'tm_mon' => 7, 'tm_year' => 205);
    $localtime_arr3 = array('tm_sec' => 11, 'tm_min' => 13, 'tm_hour' => 0, 'tm_mday' => 17, 'tm_mon' => 11, 'tm_year' => -5);
    $localtime_arr = array($localtime_arr1, $localtime_arr2, $localtime_arr3);
    //Test format and parse with a timestamp : long
    foreach ($time_arr as $timestamp_entry) {
        $res_str .= "\n------------\n";
        $res_str .= "\nInput timestamp is : {$timestamp_entry}";
        $res_str .= "\n------------\n";
        foreach ($locale_arr as $locale_entry) {
            foreach ($datetype_arr as $datetype_entry) {
                $res_str .= "\nIntlDateFormatter locale= {$locale_entry} ,datetype = {$datetype_entry} ,timetype ={$datetype_entry} ";
                $fmt = ut_datefmt_create($locale_entry, $datetype_entry, $datetype_entry, $timezone);
                $formatted = ut_datefmt_format($fmt, $timestamp_entry);
                $res_str .= "\nFormatted timestamp is : {$formatted}";
                $parsed = ut_datefmt_parse($fmt, $formatted);
                if (intl_get_error_code() == U_ZERO_ERROR) {
                    $res_str .= "\nParsed timestamp is : {$parsed}";
                } else {
                    $res_str .= "\nError while parsing as: '" . intl_get_error_message() . "'";
                }
            }
        }
    }
    //Test format and parse with a localtime :array
    foreach ($localtime_arr as $localtime_entry) {
        $res_str .= "\n------------\n";
        $res_str .= "\nInput localtime is : ";
        foreach ($localtime_entry as $key => $value) {
            $res_str .= "{$key} : '{$value}' , ";
        }
        $res_str .= "\n------------\n";
        foreach ($locale_arr as $locale_entry) {
            foreach ($datetype_arr as $datetype_entry) {
                $res_str .= "\nIntlDateFormatter locale= {$locale_entry} ,datetype = {$datetype_entry} ,timetype ={$datetype_entry} ";
                $fmt = ut_datefmt_create($locale_entry, $datetype_entry, $datetype_entry, $timezone);
                $formatted1 = ut_datefmt_format($fmt, $localtime_entry);
                if (intl_get_error_code() == U_ZERO_ERROR) {
                    $res_str .= "\nFormatted localtime_array is : {$formatted1}";
                } else {
                    $res_str .= "\nError while formatting as: '" . intl_get_error_message() . "'";
                }
                //Parsing
                $parsed_arr = ut_datefmt_localtime($fmt, $formatted1);
                if ($parsed_arr) {
                    $res_str .= "\nParsed array is: ";
                    foreach ($parsed_arr as $key => $value) {
                        $res_str .= "{$key} : '{$value}' , ";
                    }
                }
                /*
                				else{
                				    //$res_str .= "No values found from LocaleTime parsing.";
                				    $res_str .= "\tError : '".intl_get_error_message()."'";
                				}
                */
            }
        }
    }
    return $res_str;
}