{"action":"created","issue":{"url":"https://api.github.com/repos/miwarin/netbsd-gnats-memo/issues/38","labels_url":"https://api.github.com/repos/miwarin/netbsd-gnats-memo/issues/38/labels{/name}","comments_url":"https://api.github.com/repos/miwarin/netbsd-gnats-memo/issues/38/comments","events_url":"https://api.github.com/repos/miwarin/netbsd-gnats-memo/issues/38/events","html_url":"https://github.com/miwarin/netbsd-gnats-memo/issues/38","id":54693129,"number":38,"title":"lib/36528","user":{"login":"miwarin","id":250465,"avatar_url":"https://avatars.githubusercontent.com/u/250465?v=3","gravatar_id":"","url":"https://api.github.com/users/miwarin","html_url":"https://github.com/miwarin","followers_url":"https://api.github.com/users/miwarin/followers","following_url":"https://api.github.com/users/miwarin/following{/other_user}","gists_url":"https://api.github.com/users/miwarin/gists{/gist_id}","starred_url":"https://api.github.com/users/miwarin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/miwarin/subscriptions","organizations_url":"https://api.github.com/users/miwarin/orgs","repos_url":"https://api.github.com/users/miwarin/repos","events_url":"https://api.github.com/users/miwarin/events{/privacy}","received_events_url":"https://api.github.com/users/miwarin/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/miwarin/netbsd-gnats-memo/labels/bug","name":"bug","color":"fc2929"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-01-18T11:01:45Z","updated_at":"2015-01-18T23:31:43Z","closed_at":null,"body":"http://gnats.netbsd.org/36528\r\n\r\ntm_mday, tm_mon and tm_wday がおかしい、という。\r\n\r\n再現する\r\n\r\n    % ./a.out\r\n    tm_mday = 0      /* 月内の日付 (1-31) */\r\n    tm_mon = 0       /* 月 (0-11) */\r\n    tm_year = 107    /* 年 - 1900 */\r\n    tm_yday = 99     /* 年内通算日 (0-365, 1 月 1 日 = 0) */\r\n    tm_wday = 0      /* 曜日 (0-6, 日曜 = 0) */\r\n\r\n参考\r\n\r\n[On-line Manual of &quot;strftime&quot;](http://www.jp.freebsd.org/cgi/mroff.cgi?sect=3&amp;cmd=&amp;lc=1&amp;subdir=man&amp;dir=jpman-11.0.2%2Fman&amp;subdir=man&amp;man=strftime \"On-line Manual of &quot;strftime&quot;\")\r\n\r\n    %j    1 年の日を示す 10 進数 (001-366) で置き換えられます。\r\n    %Y    百年紀付きの年を示す 10 進数で置き換えられます。\r\n\r\n\r\n2015年1月1日は木曜日。週の4番目。\r\n\r\n    retp = strptime(\"1-2015\", \"%j-%Y\", &tm);\r\n\r\n結果\r\n\r\n    % ./a.out\r\n    tm_mday = 0     NG 期待値=1\r\n    tm_mon = 0      OK 期待値=0\r\n    tm_year = 115   OK 期待値=115\r\n    tm_yday = 0     OK 期待値=0\r\n    tm_wday = 0     NG 期待値=4\r\n\r\n\r\n2015年2月2日は月曜日。週の1番目。\r\n\r\n    retp = strptime(\"33-2015\", \"%j-%Y\", &tm);\r\n\r\n結果\r\n\r\n    tm_mday = 0    NG 期待値=2\r\n    tm_mon = 0     NG 期待値=1\r\n    tm_year = 115  OK 期待値=115\r\n    tm_yday = 32   OK 期待値=32\r\n    tm_wday = 0    NG 期待値=1\r\n\r\n\r\nちなみに同じコードを cygwin gcc 4.8.3 でビルドして実行すると全部期待通り。\r\n\r\n2015年1月1日は木曜日。週の4番目。\r\n\r\n    $ ./a.exe\r\n    tm_mday = 1\r\n    tm_mon = 0\r\n    tm_year = 115\r\n    tm_yday = 0\r\n    tm_wday = 4\r\n\r\n2015年2月2日は月曜日。週の1番目。\r\n\r\n    $ ./a.exe\r\n    tm_mday = 2\r\n    tm_mon = 1\r\n    tm_year = 115\r\n    tm_yday = 32\r\n    tm_wday = 1\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/miwarin/netbsd-gnats-memo/issues/comments/70432133","html_url":"https://github.com/miwarin/netbsd-gnats-memo/issues/38#issuecomment-70432133","issue_url":"https://api.github.com/repos/miwarin/netbsd-gnats-memo/issues/38","id":70432133,"user":{"login":"miwarin","id":250465,"avatar_url":"https://avatars.githubusercontent.com/u/250465?v=3","gravatar_id":"","url":"https://api.github.com/users/miwarin","html_url":"https://github.com/miwarin","followers_url":"https://api.github.com/users/miwarin/followers","following_url":"https://api.github.com/users/miwarin/following{/other_user}","gists_url":"https://api.github.com/users/miwarin/gists{/gist_id}","starred_url":"https://api.github.com/users/miwarin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/miwarin/subscriptions","organizations_url":"https://api.github.com/users/miwarin/orgs","repos_url":"https://api.github.com/users/miwarin/repos","events_url":"https://api.github.com/users/miwarin/events{/privacy}","received_events_url":"https://api.github.com/users/miwarin/received_events","type":"User","site_admin":false},"created_at":"2015-01-18T23:31:43Z","updated_at":"2015-01-18T23:31:43Z","body":"参考\r\n\r\nRuby 実装。struct tm に格納するんではなくハッシュへ格納していく？\r\n\r\nruby-2.2.0\\ext\\date\\date_strptime.c\r\n\r\nテストパターン\r\n\r\nruby-2.2.0\\ext\\date\\date_core.c\r\n\r\n     *    Date._strptime('2001-02-03', '%Y-%m-%d')\r\n     *\t\t\t\t#=> {:year=>2001, :mon=>2, :mday=>3}\r\n     *    Date.strptime('2001-02-03', '%Y-%m-%d')\t#=> #<Date: 2001-02-03 ...>\r\n     *    Date.strptime('03-02-2001', '%d-%m-%Y')\t#=> #<Date: 2001-02-03 ...>\r\n     *    Date.strptime('2001-034', '%Y-%j')\t#=> #<Date: 2001-02-03 ...>\r\n     *    Date.strptime('2001-W05-6', '%G-W%V-%u')\t#=> #<Date: 2001-02-03 ...>\r\n     *    Date.strptime('2001 04 6', '%Y %U %w')\t#=> #<Date: 2001-02-03 ...>\r\n     *    Date.strptime('2001 05 6', '%Y %W %u')\t#=> #<Date: 2001-02-03 ...>\r\n     *    Date.strptime('sat3feb01', '%a%d%b%y')\t#=> #<Date: 2001-02-03 ...>\r\n     *    DateTime.strptime('2001-02-03T04:05:06+07:00', '%Y-%m-%dT%H:%M:%S%z')\r\n     *\t\t\t\t#=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>\r\n     *    DateTime.strptime('03-02-2001 04:05:06 PM', '%d-%m-%Y %I:%M:%S %p')\r\n     *\t\t\t\t#=> #<DateTime: 2001-02-03T16:05:06+00:00 ...>\r\n     *    DateTime.strptime('2001-W05-6T04:05:06+07:00', '%G-W%V-%uT%H:%M:%S%z')\r\n     *\t\t\t\t#=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>\r\n     *    DateTime.strptime('2001 04 6 04 05 06 +7', '%Y %U %w %H %M %S %z')\r\n     *\t\t\t\t#=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>\r\n     *    DateTime.strptime('2001 05 6 04 05 06 +7', '%Y %W %u %H %M %S %z')\r\n     *\t\t\t\t#=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>\r\n     *    DateTime.strptime('-1', '%s')\r\n     *\t\t\t\t#=> #<DateTime: 1969-12-31T23:59:59+00:00 ...>\r\n     *    DateTime.strptime('-1000', '%Q')\r\n     *\t\t\t\t#=> #<DateTime: 1969-12-31T23:59:59+00:00 ...>\r\n     *    DateTime.strptime('sat3feb014pm+7', '%a%d%b%y%H%p%z')\r\n     *\t\t\t\t#=> #<DateTime: 2001-02-03T16:00:00+07:00 ...>\r\n     *    DateTime._strptime(string[, format='%FT%T%z'])  ->  hash\r\n\r\nruby-2.2.0\\test\\test_time.rb\r\n\r\n      def test_strptime\r\n        assert_equal(Time.utc(2005, 8, 28, 06, 54, 20), Time.strptime(\"28/Aug/2005:06:54:20 +0000\", \"%d/%b/%Y:%T %z\"))\r\n        assert_equal(Time.at(1).localtime, Time.strptime(\"1\", \"%s\"))\r\n        assert_equal(false, Time.strptime('0', '%s').utc?)\r\n      end\r\n    \r\n      def test_strptime_empty\r\n        assert_raise(ArgumentError) { Time.strptime('', '') }\r\n        assert_raise(ArgumentError) { Time.strptime('+09:00', '%z') } # [ruby-core:62351] by matz.\r\n      end\r\n    \r\n      def test_strptime_s_z\r\n        t = Time.strptime('0 +0100', '%s %z')\r\n        assert_equal(0, t.to_r)\r\n        assert_equal(3600, t.utc_offset)\r\n        t = Time.strptime('0 UTC', '%s %z')\r\n        assert_equal(0, t.to_r)\r\n        assert_equal(0, t.utc_offset)\r\n        assert_equal(true, t.utc?)\r\n      end\r\n    \r\n      def test_strptime_Ymd_z\r\n        t = Time.strptime('20010203 -0200', '%Y%m%d %z')\r\n        assert_equal(2001, t.year)\r\n        assert_equal(2, t.mon)\r\n        assert_equal(3, t.day)\r\n        assert_equal(0, t.hour)\r\n        assert_equal(0, t.min)\r\n        assert_equal(0, t.sec)\r\n        assert_equal(-7200, t.utc_offset)\r\n        t = Time.strptime('20010203 UTC', '%Y%m%d %z')\r\n        assert_equal(2001, t.year)\r\n        assert_equal(2, t.mon)\r\n        assert_equal(3, t.day)\r\n        assert_equal(0, t.hour)\r\n        assert_equal(0, t.min)\r\n        assert_equal(0, t.sec)\r\n        assert_equal(0, t.utc_offset)\r\n        assert_equal(true, t.utc?)\r\n      end\r\n"}}