如果您认为问题出在MacOS X和C库上,那么您可以制作一个测试用例来证明它。例如,我在MacOS X 10.4.11 (PPC,G4,32位)上运行了下面的代码,并得到了输出:
Now: 1225573977
Formatted (12): 011120082112
End: 0xBFFFF553 (Buffer: 0xBFFFF547)
Then: year = 2008, month = 11, day = 1, hour = 21, minute = 12
Reformatted (12): 011120082112
我使用的代码是:
#include <time.h>
#include <stdio.h>
int main(void)
{
time_t now = time(0);
struct tm *tm = gmtime(&now);
char format[] = "%d%m%Y%H%M";
char buffer1[64];
char buffer2[64];
size_t f_len = strftime(buffer1, sizeof(buffer1), format, tm);
struct tm then;
char *end = strptime(buffer1, format, &then);
size_t p_len = strftime(buffer2, sizeof(buffer2), format, &then);
printf("Now: %ld
", (long)now);
printf("Formatted (%lu): %s
", (unsigned long)f_len, buffer1);
printf("End: 0x%08lX (Buffer: 0x%08lX)
", (unsigned long)end, (unsigned long)buffer1);
printf("Then: year = %d, month = %d, day = %d, hour = %d, minute = %d
",
then.tm_year + 1900, then.tm_mon + 1, then.tm_mday, then.tm_hour, then.tm_min);
printf("Reformatted (%lu): %s
", (unsigned long)p_len, buffer2);
return(0);
}
根据我所看到的,我使用的版本中的strptime()没有任何错误。我们可以辩论不存在的错误检查和强制转换与打印中的C99 <inttypes.h>
符号的优点,但我认为代码足够准确。我使用了gmtime()
而不是localtime()
;我怀疑这没有成为不重现问题的因素。
Maybe you should look at the PHP test suite?
Maybe you should split your rather complex expression into pieces to detect where the error occurs in PHP?