問題が 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\n", (long)now);
printf("Formatted (%lu): %s\n", (unsigned long)f_len, buffer1);
printf("End: 0x%08lX (Buffer: 0x%08lX)\n", (unsigned long)end, (unsigned long)buffer1);
printf("Then: year = %d, month = %d, day = %d, hour = %d, minute = %d\n",
then.tm_year + 1900, then.tm_mon + 1, then.tm_mday, then.tm_hour, then.tm_min);
printf("Reformatted (%lu): %s\n", (unsigned long)p_len, buffer2);
return(0);
}
私が見たところ、私が使用しているバージョンでは strptime() にバグはありません。存在しないエラー チェックのメリット、および印刷におけるキャストと C99<inttypes.h>
表記のメリットについて議論することはできますが、コードは十分に正確だと思います。;gmtime()
の代わりに使用しました。localtime()
それが問題を再現しない要因であったかどうかは疑問です。
たぶん、PHP テスト スイートを確認する必要がありますか? PHP でエラーが発生した場所を検出するために、かなり複雑な式を分割する必要があるのではないでしょうか?