IntlCalendar::clear
(PHP 5.5.0, PECL >= 3.0.0a1)
IntlCalendar::clear — Clear a field or all fields
Description
Object oriented style
$field
= NULL
] )Procedural style
Clears either all of the fields or a specific field. A cleared field is marked as unset, giving it the lowest priority against overlapping fields or even default values when calculating the time. Additionally, its value is set to 0, though given the fieldʼs low priority, its value may have been internally set to another value by the time the field has finished been queried.
Parameters
-
cal
-
The IntlCalendar resource.
-
field
-
One of the IntlCalendar date/time field constants. These are integer values between 0 and
IntlCalendar::FIELD_COUNT
.
Return Values
Returns TRUE
on success or FALSE
on failure. Failure can only occur is
invalid arguments are provided.
Examples
Example #1 IntlCalendar::clear() examples
<?php
ini_set('intl.default_locale', 'es_ES');
ini_set('date.timezone', 'UTC');
$fields = array(
'FIELD_ERA' => 0,
'FIELD_YEAR' => 1,
'FIELD_MONTH' => 2,
'FIELD_WEEK_OF_YEAR' => 3,
'FIELD_WEEK_OF_MONTH' => 4,
'FIELD_DATE' => 5,
'FIELD_DAY_OF_YEAR' => 6,
'FIELD_DAY_OF_WEEK' => 7,
'FIELD_DAY_OF_WEEK_IN_MONTH' => 8,
'FIELD_AM_PM' => 9,
'FIELD_HOUR' => 10,
'FIELD_HOUR_OF_DAY' => 11,
'FIELD_MINUTE' => 12,
'FIELD_SECOND' => 13,
'FIELD_MILLISECOND' => 14,
'FIELD_ZONE_OFFSET' => 15,
'FIELD_DST_OFFSET' => 16,
'FIELD_YEAR_WOY' => 17,
'FIELD_DOW_LOCAL' => 18,
'FIELD_EXTENDED_YEAR' => 19,
'FIELD_JULIAN_DAY' => 20,
'FIELD_MILLISECONDS_IN_DAY' => 21,
'FIELD_IS_LEAP_MONTH' => 22,
'FIELD_FIELD_COUNT' => 23,
);
function getSetFields(IntlCalendar $cal) {
global $fields;
$ret = array();
foreach ($fields as $name => $value) {
if ($cal->isSet($value)) {
$ret[] = $name;
}
}
return $ret;
}
$cal = new IntlGregorianCalendar(2013, 2 /* March */, 15);
echo "After GregorianCalendar creation\n";
print_r(getSetFields($cal));
echo "\n";
echo IntlDateFormatter::formatObject($cal), "\n";
echo "After the formatter requested the extended year\n";
print_r(getSetFields($cal));
echo "\n";
$cal->clear(IntlCalendar::FIELD_YEAR);
echo "After the year has been cleared, the date stays the same\n";
echo IntlDateFormatter::formatObject($cal), "\n";
echo "because FIELD_EXTENDED_YEAR is still set\n";
print_r(getSetFields($cal));
echo "\n";
var_dump($cal->clear(IntlCalendar::FIELD_EXTENDED_YEAR));
echo "After the extended year has been cleared\n";
print_r(getSetFields($cal));
echo IntlDateFormatter::formatObject($cal), "\n";
echo "\n";
echo "After the fields are recalculated,\n"
. " extended year is set again (to 1970)\n";
print_r(getSetFields($cal));
echo "\n";
$cal->clear();
echo "After calling variant with no arguments\n";
print_r(getSetFields($cal));
echo IntlDateFormatter::formatObject($cal), "\n";
The above example will output:
After GregorianCalendar creation Array ( [0] => FIELD_ERA [1] => FIELD_YEAR [2] => FIELD_MONTH [3] => FIELD_DATE ) 15/03/2013 00:00:00 After the formatter requested the extended year Array ( [0] => FIELD_ERA [1] => FIELD_YEAR [2] => FIELD_MONTH [3] => FIELD_DATE [4] => FIELD_EXTENDED_YEAR ) After the year has been cleared, the date stays the same 15/03/2013 00:00:00 because FIELD_EXTENDED_YEAR is still set Array ( [0] => FIELD_ERA [1] => FIELD_MONTH [2] => FIELD_DATE [3] => FIELD_EXTENDED_YEAR ) bool(true) After the extended year has been cleared Array ( [0] => FIELD_ERA [1] => FIELD_MONTH [2] => FIELD_DATE ) 15/03/1970 00:00:00 After the fields are recalculated, extended year is set again (to 1970) Array ( [0] => FIELD_ERA [1] => FIELD_MONTH [2] => FIELD_DATE [3] => FIELD_EXTENDED_YEAR ) After calling variant with no arguments Array ( ) 01/01/1970 00:00:00
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Поддержка языков и кодировок
- Internationalization Functions
- Функция IntlCalendar::add() - Add a (signed) amount of time to a field
- Функция IntlCalendar::after() - Whether this objectʼs time is after that of the passed object
- Функция IntlCalendar::before() - Whether this objectʼs time is before that of the passed object
- Функция IntlCalendar::clear() - Clear a field or all fields
- Функция IntlCalendar::__construct() - Private constructor for disallowing instantiation
- Функция IntlCalendar::createInstance() - Create a new IntlCalendar
- Функция IntlCalendar::equals() - Compare time of two IntlCalendar objects for equality
- Функция IntlCalendar::fieldDifference() - Calculate difference between given time and this objectʼs time
- Функция IntlCalendar::fromDateTime() - Create an IntlCalendar from a DateTime object or string
- Функция IntlCalendar::get() - Get the value for a field
- Функция IntlCalendar::getActualMaximum() - The maximum value for a field, considering the objectʼs current time
- Функция IntlCalendar::getActualMinimum() - The minimum value for a field, considering the objectʼs current time
- Функция IntlCalendar::getAvailableLocales() - Get array of locales for which there is data
- Функция IntlCalendar::getDayOfWeekType() - Tell whether a day is a weekday, weekend or a day that has a transition between the two
- Функция IntlCalendar::getErrorCode() - Get last error code on the object
- Функция IntlCalendar::getErrorMessage() - Get last error message on the object
- Функция IntlCalendar::getFirstDayOfWeek() - Get the first day of the week for the calendarʼs locale
- Функция IntlCalendar::getGreatestMinimum() - Get the largest local minimum value for a field
- Функция IntlCalendar::getKeywordValuesForLocale() - Get set of locale keyword values
- Функция IntlCalendar::getLeastMaximum() - Get the smallest local maximum for a field
- Функция IntlCalendar::getLocale() - Get the locale associated with the object
- Функция IntlCalendar::getMaximum() - Get the global maximum value for a field
- Функция IntlCalendar::getMinimalDaysInFirstWeek() - Get minimal number of days the first week in a year or month can have
- Функция IntlCalendar::getMinimum() - Get the global minimum value for a field
- Функция IntlCalendar::getNow() - Get number representing the current time
- Функция IntlCalendar::getRepeatedWallTimeOption() - Get behavior for handling repeating wall time
- Функция IntlCalendar::getSkippedWallTimeOption() - Get behavior for handling skipped wall time
- Функция IntlCalendar::getTime() - Get time currently represented by the object
- Функция IntlCalendar::getTimeZone() - Get the objectʼs timezone
- Функция IntlCalendar::getType() - Get the calendar type
- Функция IntlCalendar::getWeekendTransition() - Get time of the day at which weekend begins or ends
- Функция IntlCalendar::inDaylightTime() - Whether the objectʼs time is in Daylight Savings Time
- Функция IntlCalendar::isEquivalentTo() - Whether another calendar is equal but for a different time
- Функция IntlCalendar::isLenient() - Whether date/time interpretation is in lenient mode
- Функция IntlCalendar::isSet() - Whether a field is set
- Функция IntlCalendar::isWeekend() - Whether a certain date/time is in the weekend
- Функция IntlCalendar::roll() - Add value to field without carrying into more significant fields
- Функция IntlCalendar::set() - Set a time field or several common fields at once
- Функция IntlCalendar::setFirstDayOfWeek() - Set the day on which the week is deemed to start
- Функция IntlCalendar::setLenient() - Set whether date/time interpretation is to be lenient
- Функция IntlCalendar::setMinimalDaysInFirstWeek() - Set minimal number of days the first week in a year or month can have
- Функция IntlCalendar::setRepeatedWallTimeOption() - Set behavior for handling repeating wall times at negative timezone offset transitions
- Функция IntlCalendar::setSkippedWallTimeOption() - Set behavior for handling skipped wall times at positive timezone offset transitions
- Функция IntlCalendar::setTime() - Set the calendar time in milliseconds since the epoch
- Функция IntlCalendar::setTimeZone() - Set the timezone used by this calendar
- Функция IntlCalendar::toDateTime() - Convert an IntlCalendar into a DateTime object
Коментарии
404 Not Found