Skip to content

Commit 1dffb31

Browse files
committedDec 4, 2021
Add calendar tests, available since 5.5.0
1 parent 3dbcc68 commit 1dffb31

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed
 

‎bench.php

+1
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ function print_pre($msg) {
422422
'29_datetime' => 500000,
423423
'30_intl_number_format' => 20000,
424424
'31_intl_message_format' => 200000,
425+
'32_intl_calendar' => 300000,
425426
);
426427
$totalOps = 0;
427428

‎php5.inc

+45
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,9 @@ function test_29_DateTime()
262262

263263
// ------------------------- INTL tests -----------------------
264264

265+
/**
266+
* @since 5.3.0
267+
*/
265268
function test_30_Intl_Number_Format()
266269
{
267270
global $testsLoopLimits, $totalOps, $emptyResult;
@@ -300,6 +303,9 @@ function test_30_Intl_Number_Format()
300303
return format_result_test(get_microtime() - $time_start, $count, mymemory_usage());
301304
}
302305

306+
/**
307+
* @since 5.3.0
308+
*/
303309
function test_31_Intl_Message_Format()
304310
{
305311
global $testsLoopLimits, $totalOps, $emptyResult;
@@ -325,3 +331,42 @@ function test_31_Intl_Message_Format()
325331
$totalOps += $count;
326332
return format_result_test(get_microtime() - $time_start, $count, mymemory_usage());
327333
}
334+
335+
/**
336+
* @since: 5.5.0
337+
*/
338+
function test_32_Intl_Calendar()
339+
{
340+
global $testsLoopLimits, $totalOps, $emptyResult;
341+
342+
if (!class_exists('IntlCalendar', false)) {
343+
return $emptyResult;
344+
}
345+
if (!class_exists('IntlTimeZone', false)) {
346+
return $emptyResult;
347+
}
348+
349+
$count = $testsLoopLimits['32_intl_calendar'];
350+
$time_start = get_microtime();
351+
352+
$cal = IntlCalendar::createInstance(IntlTimeZone::getGMT());
353+
354+
$a = 0;
355+
for ($i = 0; $i < $count; $i++) {
356+
$num = $i / 100.;
357+
$cal->clear();
358+
$cal->setTime($num);
359+
360+
if ($cal->inDaylightTime()) $a++;
361+
if ($cal->isWeekend()) $a--;
362+
if ($cal->getMinimalDaysInFirstWeek()) $a++;
363+
364+
$cal->add(IntlCalendar::FIELD_MONTH, 1);
365+
$cal->add(IntlCalendar::FIELD_DAY_OF_MONTH, 1);
366+
if ($cal->inDaylightTime()) $a--;
367+
if ($cal->isWeekend()) $a++;
368+
if ($cal->getMinimalDaysInFirstWeek()) $a--;
369+
}
370+
$totalOps += $count;
371+
return format_result_test(get_microtime() - $time_start, $count, mymemory_usage());
372+
}

0 commit comments

Comments
 (0)
Failed to load comments.