[Bug #437] test_strftime(TestTime) fails on Solaris

Bug #437: test_strftime(TestTime) fails on Solaris
http://redmine.ruby-lang.org/issues/show/437

e$B5/I<<Te(B: Shugo M.
e$B%9%F!<%?%9e(B: Open, e$BM%@hEYe(B: Normal

test_strftime(TestTime) fails on Solaris.

$ ./ruby-trunk test/ruby/test_time.rb
Loaded suite test/ruby/test_time
Started
…F…
Finished in 0.017662724 seconds.

1) Failure:

test_strftime(TestTime) [test/ruby/test_time.rb:374]:
is not true.

strftime(“%Z”) seems always to return the local time zone.

$ ./ruby-trunk -e ‘p Time.now.gmtime’
2008-08-13 14:27:31 UTC
$ ./ruby-trunk -e ‘p Time.now.gmtime.strftime(“%Z”)’
“JST”

前田です。

Redmineのレポート先を間違えてruby-devにしてしまったので日本語で。

2008/08/13 23:27 Shugo M. [email protected]:

strftime(“%Z”) seems always to return the local time zone.

$ ./ruby-trunk -e ‘p Time.now.gmtime’
2008-08-13 14:27:31 UTC
$ ./ruby-trunk -e ‘p Time.now.gmtime.strftime(“%Z”)’
“JST”

どうもSolarisだとstrftime(3)è‡ªä½“ãŒå¸¸ã«ãƒ­ãƒ¼ã‚«ãƒ«ã®ã‚¿ã‚¤ãƒ ã‚¾ãƒ¼ãƒ³æƒ…å ±ã‚’
返すようです。
簡単な解決としては、添付のパッチのような方法しか思い付きませんでし
たが、もっと上手い解決方法があれば教えてください。

ほんとは全部自前で実装するのがよいのでしょうが…。

e$B$5$H$&$U$_$d$9e(B @ OSS e$B%F%/%N%m%8$G$9!#e(B

At Fri, 15 Aug 2008 16:59:30 +0900,
Shugo M. wrote:

e$B$I$&$be(BSolarise$B$@$He(Bstrftime(3)e$B<+BN$,>o$K%m!<%+%k$N%?%$%`%>!<%s>pJs$re(B
e$BJV$9$h$&$G$9!#e(B

e$B$U$D$&e(B(?) e$B$Ne(B struct tm e$B$K$O%?%$%%>!<%s$N>pJs$,e(B e$B4^$^$l$J$$$N$G!"%7%9%F%@_Dj$+e(B TZ e$B4D6-JQ?t$K=>$&$7$+$J$$e(B
e$B$N$@$H;W$$$^$9!#e(B

e$B<j85$Ne(B Debian GNU/Linux unstable e$B$Ne(B ctime(3) e$B$h$je(B:

   The glibc version of struct tm has additional fields

          long tm_gmtoff;           /* Seconds east of UTC */
          const char *tm_zone;      /* Timezone abbreviation */

e$B$H$$$&$3$H$G!"e(B

+#ifdef BROKEN_STRFTIME_Z

e$B!Ve(BBROKENe$B!W$G$O$J$/;EMM$G$9$M!#e(B

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:35856] Re: [Bug #437] test_strftime(TestTime)
fails on Solaris”
on Fri, 15 Aug 2008 17:21:34 +0900, SATOH Fumiyasu
[email protected] writes:

|At Fri, 15 Aug 2008 16:59:30 +0900,
|Shugo M. wrote:
|> e$B$I$&$be(BSolarise$B$@$He(Bstrftime(3)e$B<+BN$,>o$K%m!<%+%k$N%?%$%%>!<%s>pJs$re(B |> e$BJV$9$h$&$G$9!#e(B | |e$B$U$D$&e(B(?) e$B$Ne(B struct tm e$B$K$O%?%$%%>!<%s$N>pJs$,e(B
|e$B4^$^$l$J$$$N$G!"%7%9%F%`@_Dj$+e(B TZ e$B4D6-JQ?t$K=>$&$7$+$J$$e(B
|e$B$N$@$H;W$$$^$9!#e(B

e$B$J$s$H!";DG0$J!#e(B

|e$B$H$$$&$3$H$G!"e(B
|
|> +#ifdef BROKEN_STRFTIME_Z
|
|e$B!Ve(BBROKENe$B!W$G$O$J$/;EMM$G$9$M!#e(B

e$B$G$O!"e(BBROKENe$B$G$J$$C18l$r;H$C$Fe(B(NOGMTOFFe$B$H$+e(B)e$B%3%_%C%H$7$F$$$?e(B
e$B$@$1$^$;$s$+e(B e$B!de(B e$BA0ED$5$se(B

e$B1sF#$G$9!#e(B

2008/08/15 17:21 SATOH Fumiyasu [email protected]:

+#ifdef BROKEN_STRFTIME_Z

e$B!Ve(BBROKENe$B!W$G$O$J$/;EMM$G$9$M!#e(B

e$B13$N=PNO$rJV$9$N$O!"$d$O$je(B BROKEN e$B$J5$$,$7$^$9!#e(B
Solaris 10 e$B$Ne(B strftime(3C) e$B$K$h$k$He(B

 %Z       Time zone name or abbreviation, or no bytes  if  no
          time zone information exists.

e$B$i$7$$$N$G!"e(Bno bytes e$B$J$iG<F@$G$-$k$s$G$9$1$I!#e(B

e$B$5$H$&$U$_$d$9e(B @ OSS e$B%F%/%N%m%8$G$9!#e(B

At Fri, 15 Aug 2008 21:57:02 +0900,
Yusuke ENDOH wrote:

e$B$i$7$$$N$G!"e(Bno bytes e$B$J$iG<F@$G$-$k$s$G$9$1$I!#e(B
Solaris e$B$O!"e(Bstruct tm e$B$K$b!“e(Bstrftime(3C) e$B$K:$C$F$$$ke(B
cftime(3C) e$B$,<u$1$H$ke(B time_t e$B$K$b%?%$%`%>!<%s>pJs$Oe(B
e$B4^$^$l$F$$$J$$$N$G$9$+$i!”!Ve(Bif e$B!A!W$r$=$N$h$&$K2r<a$9$k$N$Oe(B
e$BIT<+A3$G$9!#e(B

e$B1Q8l$N$[$&$,%*%j%8%J%k$J$s$G$7$g$&$,!"F|K\8l$Ne(B
strftime(3C) e$B$K$h$k$He(B:

 %Z    e$B%?%$%`%>!<%sL>$^$?$O>JN,7Ae(B 

(e$B%?%$%`%>!<%s$,$J$$>l9g$K$Oe(B
e$BJ8;z$J$7e(B)

e$B$J$N$G!“3:Ev$9$k%?%$%`%>!<%s>pJse(B (/usr/share/lib/zoneinfo?)
e$B$,e(B
e$BB8:_$7$J$$>l9g!”$N$h$&$KFI$a$^$9!#e(B(e$B;d$K$Oe(B)

In article
[email protected],
“Shugo M.” [email protected] writes:

e$B4JC1$J2r7h$H$7$F$O!“E:IU$N%Q%C%A$N$h$&$JJ}K!$7$+;W$$IU$-$^$;$s$G$7e(B
e$B$?$,!”$b$C$H>e<j$$2r7hJ}K!$,$"$l$P65$($F$/$@$5$$!#e(B

e$B$[$s$H$OA4It<+A0$G<BAu$9$k$N$,$h$$$N$G$7$g$&$,!D!#e(B

missing/strftime.c e$B$r>o$K;H$&$H$$$&OC$G$9$+$M!#e(B

e$B$^$!!“e(B%Z e$B$@$1$G$J$/e(B %N e$B$d%m%1!<%k$NOC$b$”$j$^$9$7!#e(B

e$B1sF#$G$9!#e(B

2008/08/16 2:43 SATOH Fumiyasu [email protected]:

e$BIT<+A3$G$9!#e(B

e$B1Q8l$N$[$&$,%*%j%8%J%k$J$s$G$7$g$&$,!"F|K\8l$Ne(B
strftime(3C) e$B$K$h$k$He(B:

%Z    e$B%?%$%`%>!<%sL>$^$?$O>JN,7Ae(B (e$B%?%$%`%>!<%s$,$J$$>l9g$K$Oe(B
      e$BJ8;z$J$7e(B)

e$B$J$N$G!“3:Ev$9$k%?%$%`%>!<%s>pJse(B (/usr/share/lib/zoneinfo?) e$B$,e(B
e$BB8:_$7$J$$>l9g!”$N$h$&$KFI$a$^$9!#e(B(e$B;d$K$Oe(B)

e$B=q$+$l$?0U?^$O$=$s$J46$8$@$m$&$J$"$H;W$$$^$7$?$,!“87L)$K2r<a$9$k$He(B
e$B$3$3$Oe(B no bytes e$B$G$”$k$Y$-$@$H9M$($^$7$?!#e(B

e$B$,!"$3$N7o$Oe(B SUSv3 e$B$KL@5-$5$l$F$^$7$?!#e(B

If a struct tm broken-down time structure is created by localtime() or
localtime_r(), or modified by mktime(), and the value of TZ is
subsequently modified, the results of the %Z and %z strftime()
conversion specifiers are undefined, when strftime() is called with
such a broken-down time structure.

If a struct tm broken-down time structure is created or modified by
gmtime() or gmtime_r(), it is unspecified whether the result of the %Z
and %z conversion specifiers shall refer to UTC or the current local
timezone, when strftime() is called with such a broken-down time
structure.

e$B$H$$$&$o$1$G40`z$K$5$$$H$&$5$s$,$$C$7$c$k$H$$j$N;EMM$N$h$&$G$9!#e(B
e$B$9$_$^$;$s!#e(B

e$B1sF#$G$9!#e(B

2008/08/16 3:27 Yusuke ENDOH [email protected]:

e$B$H$$$&$o$1$G40`z$K$5$$$H$&$5$s$,$$C$7$c$k$H$$j$N;EMM$N$h$&$G$9!#e(B

e$B$5$H$&$5$s$G$7$?!#=E$M=E$M<:Ni$7$^$7$?!#e(B

e$BA0ED$G$9!#e(B

2008/08/15 21:08 Yukihiro M. [email protected]:

|e$B$H$$$&$3$H$G!"e(B
|
|> +#ifdef BROKEN_STRFTIME_Z
|
|e$B!Ve(BBROKENe$B!W$G$O$J$/;EMM$G$9$M!#e(B

e$B$G$O!"e(BBROKENe$B$G$J$$C18l$r;H$C$Fe(B(NOGMTOFFe$B$H$+e(B)e$B%3%_%C%H$7$F$$$?e(B
e$B$@$1$^$;$s$+e(B e$B!de(B e$BA0ED$5$se(B

NOGMTOFFe$B$O2?$+0c$&$h$&$J5$$,$7$^$9!#e(B
e$B$H$$$C$F!"e(BSTRFTIME_Z_DOESNT_RETURN_GMTe$B$/$i$$$7$+;W$$IU$+$J$+$C$?$N$G$9$,!"e(B
e$BB>$K$h$$L>A0$O$J$$$G$7$g$&$+!#e(B

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:35870] Re: [Bug #437] test_strftime(TestTime)
fails on Solaris”
on Mon, 18 Aug 2008 14:19:16 +0900, “Shugo M.”
[email protected] writes:

|> e$B$G$O!"e(BBROKENe$B$G$J$$C18l$r;H$C$Fe(B(NOGMTOFFe$B$H$+e(B)e$B%3%_%C%H$7$F$$$?e(B
|> e$B$@$1$^$;$s$+e(B e$B!de(B e$BA0ED$5$se(B
|
|NOGMTOFFe$B$O2?$+0c$&$h$&$J5$$,$7$^$9!#e(B

e$B$=$&$G$9$+!#e(B

|e$B$H$$$C$F!"e(BSTRFTIME_Z_DOESNT_RETURN_GMTe$B$/$i$$$7$+;W$$IU$+$J$+$C$?$N$G$9$,!"e(B
|e$BB>$K$h$$L>A0$O$J$$$G$7$g$&$+!#e(B

e$B$$$C$=!"A4It<+A0$Ne(Bmissing/strftime.ce$B$r;H$&$H$$$&$N$G$I$&$G$7$ge(B
e$B$&!#>-Mh$N$3$H$r9M$($k$H7k6I$O$3$C$A$,F;$+$b!#e(B

e$BA0ED$G$9!#e(B

2008/08/15 21:29 Tanaka A. [email protected]:

e$B4JC1$J2r7h$H$7$F$O!“E:IU$N%Q%C%A$N$h$&$JJ}K!$7$+;W$$IU$-$^$;$s$G$7e(B
e$B$?$,!”$b$C$H>e<j$$2r7hJ}K!$,$"$l$P65$($F$/$@$5$$!#e(B

e$B$[$s$H$OA4It<+A0$G<BAu$9$k$N$,$h$$$N$G$7$g$&$,!D!#e(B

missing/strftime.c e$B$r>o$K;H$&$H$$$&OC$G$9$+$M!#e(B

e$B$^$!!“e(B%Z e$B$@$1$G$J$/e(B %N e$B$d%m%1!<%k$NOC$b$”$j$^$9$7!#e(B

e$B$=$&$G$9$M!#$=$NJ}$,0B?4$7$F;H$($k$H;W$$$^$9!#e(B

missing/strftime.ce$B$K$O2?$+B-$j$J$$$N$G$7$?$C$1!#e(B
e$B$"$H!"e(B%Ze$B$N$?$a$K!"e(Btme$B9=B$BN$G$O$J$/e(Btime_objecte$B9=B$BN$r<u$1<h$ke(B
e$B$h$&$Je(BAPIe$B$K$7$?J}$,$$$$5$$,$7$^$9$M!#e(B

前田です。

2008/08/18 14:34 Shugo M. [email protected]:

いっそ、全部自前のmissing/strftime.cを使うというのでどうでしょ
う。将来のことを考えると結局はこっちが道かも。

方向性としては賛成なのですが、1.9.1までにやります?

とりあえず、作業してみました。パッチを添付します。

i686-linux/i386-solaris2.10で確認したかぎりではtest_time.rbも
通るようになりました。
ただ、他のプラットフォーム(Windowsとか)でちゃんと動くかどうかは
かなり怪しいと思います。

あと、%L(millisecond)/%N(nanosecond)もついでに実装しました。

e$BA0ED$G$9!#e(B

2008/08/18 14:25 Yukihiro M. [email protected]:

|> e$B$G$O!"e(BBROKENe$B$G$J$$C18l$r;H$C$Fe(B(NOGMTOFFe$B$H$+e(B)e$B%3%_%C%H$7$F$$$?e(B
|> e$B$@$1$^$;$s$+e(B e$B!de(B e$BA0ED$5$se(B
|
|NOGMTOFFe$B$O2?$+0c$&$h$&$J5$$,$7$^$9!#e(B

e$B$=$&$G$9$+!#e(B

tm_gmtoffe$B$,$"$k$+$I$&$+$H!"e(Bstrftimee$B$,e(Btest_time.rbe$B$,4|BT$9$k5sF0$r<($9$+$I$&$+$,!"e(B
e$BF1$8>r7o$J$N$+$I$&$+$K3N?.$,;}$F$J$+$C$?$N$G$7$?!#e(B

|e$B$H$$$C$F!"e(BSTRFTIME_Z_DOESNT_RETURN_GMTe$B$/$i$$$7$+;W$$IU$+$J$+$C$?$N$G$9$,!"e(B
|e$BB>$K$h$$L>A0$O$J$$$G$7$g$&$+!#e(B

e$B$$$C$=!"A4It<+A0$Ne(Bmissing/strftime.ce$B$r;H$&$H$$$&$N$G$I$&$G$7$ge(B
e$B$&!#>-Mh$N$3$H$r9M$($k$H7k6I$O$3$C$A$,F;$+$b!#e(B

e$BJ}8~@-$H$7$F$O;?@.$J$N$G$9$,!"e(B1.9.1e$B$^$G$K$d$j$^$9e(B?

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:35884] Re: [Bug #437] test_strftime(TestTime)
fails on Solaris”
on Wed, 20 Aug 2008 23:24:47 +0900, “Shugo M.”
[email protected] writes:

|2008/08/18 14:34 Shugo M. [email protected]:
|>> e$B$$$C$=!“A4It<+A0$Ne(Bmissing/strftime.ce$B$r;H$&$H$$$&$N$G$I$&$G$7$ge(B
|>> e$B$&!#>-Mh$N$3$H$r9M$($k$H7k6I$O$3$C$A$,F;$+$b!#e(B
|>
|> e$BJ}8~@-$H$7$F$O;?@.$J$N$G$9$,!“e(B1.9.1e$B$^$G$K$d$j$^$9e(B?
|
|e$B$H$j$”$($:!”:n6H$7$F$_$^$7$?!#%Q%C%A$rE:IU$7$^$9!#e(B

e$B%3%_%C%H$7$F$/$@$5$$!#e(B

|i686-linux/i386-solaris2.10e$B$G3NG’$7$?$+$.$j$G$Oe(Btest_time.rbe$B$be(B
|e$BDL$k$h$&$K$J$j$^$7$?!#e(B
|e$B$?$@!"B>$N%W%i%C%H%U%)!<%`e(B(Windowse$B$H$+e(B)e$B$G$A$c$s$HF0$/$+$I$&$+$Oe(B
|e$B$+$J$j2x$7$$$H;W$$$^$9!#e(B

e$B%3%_%C%H$7$?$iC/$+$,D>$9$G$7$g$&!"$-$C$H!#e(B

|e$B$"$H!"e(B%L(millisecond)/%N(nanosecond)e$B$b$D$$$G$K<BAu$7$^$7$?!#e(B

e$B$$!#e(B

e$B$3$s$K$A$O!"$J$+$`$ie(B(e$B$&e(B)e$B$G$9!#e(B

In message “[ruby-dev:35886] Re: [Bug #437] test_strftime(TestTime)
fails on Solaris”
on Aug.21,2008 00:32:53, [email protected] wrote:

|i686-linux/i386-solaris2.10e$B$G3NG’$7$?$+$.$j$G$Oe(Btest_time.rbe$B$be(B
|e$BDL$k$h$&$K$J$j$^$7$?!#e(B
|e$B$?$@!"B>$N%W%i%C%H%U%)!<%`e(B(Windowse$B$H$+e(B)e$B$G$A$c$s$HF0$/$+$I$&$+$Oe(B
|e$B$+$J$j2x$7$$$H;W$$$^$9!#e(B

e$B%3%_%C%H$7$?$iC/$+$,D>$9$G$7$g$&!"$-$C$H!#e(B

e$B$&$5$5$s!"$4$a$s$J$5$$!#e(B

e$B$;!$7$NDL$j$J$N$G!"E,Ev$K%3%s%Q%$%k$,DL$k$h$&$KD>$7$^$7$?!#e(B
e$B$$$A$
$&!“e(Bi386-netbsdelfe$B$G$b!”;d$NJQ99A08e$Ge(Btest_time.rbe$B$N7ke(B
e$B2L$,JQ$o$i$J$$e(B(0F0E)e$B$3$H$r3NG’$O$7$^$7$?$,!“B>$N%W%i%C%H%U%)e(B
e$B!<%`$G2?$+LdBj$,$”$C$?$iC/$+D>$7$F$/$@$5$$e(B :slight_smile:

e$B$=$l$G$O!#e(B

e$BA0ED$G$9!#e(B

2008/08/20 23:46 Yukihiro M. [email protected]:

|e$B$H$j$“$($:!”:n6H$7$F$_$^$7$?!#%Q%C%A$rE:IU$7$^$9!#e(B

e$B%3%_%C%H$7$F$/$@$5$$!#e(B

e$B@h$[$I%3%_%C%H$7$^$7$?!#e(B

|i686-linux/i386-solaris2.10e$B$G3NG’$7$?$+$.$j$G$Oe(Btest_time.rbe$B$be(B
|e$BDL$k$h$&$K$J$j$^$7$?!#e(B
|e$B$?$@!"B>$N%W%i%C%H%U%)!<%`e(B(Windowse$B$H$+e(B)e$B$G$A$c$s$HF0$/$+$I$&$+$Oe(B
|e$B$+$J$j2x$7$$$H;W$$$^$9!#e(B

e$B%3%_%C%H$7$?$iC/$+$,D>$9$G$7$g$&!"$-$C$H!#e(B

e$B$&$5$5$s!"$4$a$s$J$5$$!#e(B

In article
[email protected],
“Shugo M.” [email protected] writes:

e$B$"$H!"e(B%L(millisecond)/%N(nanosecond)e$B$b$D$$$G$K<BAu$7$^$7$?!#e(B

(e$BNc$NH/I=Cf$K65$($F$b$i$C$?OC$G$9$,e(B) Perl e$B$Ne(B DateTime
e$B%b%8%e!<e(B
e$B%k$G$Oe(B %N e$B$G7e?t$r;XDj$G$-$k$=$&$G$9!#e(B

|
| %N
|
| The fractional seconds digits. Default is 9 digits (nanoseconds).
|
| %3N milliseconds (3 digits)
| %6N microseconds (6 digits)
| %9N nanoseconds (9 digits)

%L e$B$,$$$1$J$$$H$$$&$[$I$G$O$"$j$^$;$s$,!"7e?t$4$H$K5-9f$r>Ce(B
e$BHq$9$k$h$j$O!"e(BPerl e$B$N$h$&$K7e?t;XDj$r5v$7$?$[$&$,NI$$$N$G$Oe(B
e$B$J$$$G$7$g$&$+!#e(B

e$BA0ED$G$9!#e(B

2008/08/21 0:49 U.Nakamura [email protected]:

e$B$&$5$5$s!"$4$a$s$J$5$$!#e(B

e$B$*;!$7$NDL$j$J$N$G!"E,Ev$K%3%s%Q%$%k$,DL$k$h$&$KD>$7$^$7$?!#e(B

e$B$“$j$,$H$&$4$6$$$^$7$?!#e(B
e$B$”$H$O!"!VEl5~I8=`;~!WLdBj$r!D!#e(B

Time#{to_s,zone}e$B$G$be(Bstrftime(3)e$B$r;HMQ$7$J$$$h$&$K$7$F!"e(Bmissing/strftime.c
e$B$O:o=|$7$^$7$?!#e(B

Time.now.utc.strftime(“%Z”)e$B$O:#$Oe(B"GMT"e$B$rJV$9$h$&$K$7$F$"$k$s$G$9$1$I!"e(B
"UTC"e$B$rJV$9$h$&$K$7$?J}$,$$$$$s$G$9$+$M$(!#e(B

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:35888] Re: [Bug #437] test_strftime(TestTime)
fails on Solaris”
on Thu, 21 Aug 2008 01:13:43 +0900, “Shugo M.”
[email protected] writes:

|Time.now.utc.strftime(“%Z”)e$B$O:#$Oe(B"GMT"e$B$rJV$9$h$&$K$7$F$"$k$s$G$9$1$I!"e(B
|"UTC"e$B$rJV$9$h$&$K$7$?J}$,$$$$$s$G$9$+$M$(!#e(B

e$B$=$&$G$9$M!#$$$^$5$ie(BGMTe$B$b$J$$$G$7$g$&$+$i!#e(B