Time-Piece-1.20 > 1.08 との差分

Time::Piece 1.08 と 1.20 の差分

11
22=encoding euc-jp
33
4=head1 名前
4=head1 NAME
55
6=begin original
7
8Time::Piece - Object Oriented time objects
9
10=end original
11
612Time::Piece - オブジェクト指向な時間オブジェクト
713
8=head1 概要
14=head1 SYNOPSIS
915
1016 use Time::Piece;
1117
1218 my $t = localtime;
1319 print "Time is $t\n";
1420 print "Year is ", $t->year, "\n";
1521
16=head1 説明
22=head1 DESCRIPTION
1723
24=begin original
25
1826This module replaces the standard localtime and gmtime functions with
1927implementations that return objects. It does so in a backwards
2028compatible manner, so that using localtime/gmtime in the way documented
2129in perlfunc will still return what you expect.
2230
23このモジュールは、標準の localtime と gmtime 関数を、オブジェクトを返す実装のものに置き換えます。
31=end original
24後方互換性があるので、perlfunc に書かれているように、localtime/gmtime を使っても、期待通りのものを返します。
2532
33このモジュールは、標準の localtime と gmtime 関数を、オブジェクトを返す
34実装のものに置き換えます。
35これを後方互換性がある形で行うので、perlfunc に書かれているように
36localtime/gmtime を使っても、期待通りのものを返します。
37
38=begin original
39
2640The module actually implements most of an interface described by
2741Larry Wall on the perl5-porters mailing list here:
2842http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2000-01/msg00241.html
2943
30このモジュールは、実際に、Larry Wall が、perl5-portersメーリングリストに書いた、
44=end original
31ほとんどのインターフェースを実装します:
46このモジュールは、Larry Wall が perl5-porters メーリングリストに書いた、
47インターフェースのほとんどを実際に実装します:
3248http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2000-01/msg00241.html
3349
34=head1 使い方
50=head1 USAGE
3551
52(使い方)
53
54=begin original
55
3656After importing this module, when you use localtime or gmtime in a scalar
3757context, rather than getting an ordinary scalar string representing the
3858date and time, you get a Time::Piece object, whose stringification happens
3959to produce the same effect as the localtime and gmtime functions. There is
4060also a new() constructor provided, which is the same as localtime(), except
4161when passed a Time::Piece object, in which case it's a copy constructor. The
4262following methods are available on the object:
4363
44このモジュールをインポートした後は、スカラコンテキストで、localtime か、gmtime を使うと、
64=end original
45日付と時間を表現する普通のスカラ文字列ではなくて、Time::Pieceオブジェクトを得ます。
46Time::Pieceオブェクの stringification は、localtime と gmtime たまたま関数と同じ効果があります。
66このモュールをインポーした後は、スカラコンテキストで localtime
47new() コンストラクタもありますが、Time::Pieceオブジェクトが渡されない限りlocaltime()同じで
67gmtime を使う、日付と時間を表現る普通のスカラ文字列ではなく、
48Time::Pieceオブジェクトが渡されると、コピーするコンストラクタになります。
68Time::Piece オブジェクトを得ます。
69Time::Piece オブジェクトの文字列化は、偶然にも localtime と gmtime 関数と
70同じ効果があります。
71new() コンストラクタもありますが、Time::Piece オブジェクトが渡されない限り
72localtime() と同じです。
73Time::Piece オブジェクトが渡されると、コピーコンストラクタになります。
4974下記のメソッドがオブジェクトで利用できます:
5075
76=begin original
77
78 $t->sec # also available as $t->second
79 $t->min # also available as $t->minute
80 $t->hour # 24 hour
81 $t->mday # also available as $t->day_of_month
82 $t->mon # 1 = January
83 $t->_mon # 0 = January
84 $t->monname # Feb
85 $t->month # same as $t->monname
86 $t->fullmonth # February
87 $t->year # based at 0 (year 0 AD is, of course 1 BC)
88 $t->_year # year minus 1900
89 $t->yy # 2 digit year
90 $t->wday # 1 = Sunday
91 $t->_wday # 0 = Sunday
92 $t->day_of_week # 0 = Sunday
93 $t->wdayname # Tue
94 $t->day # same as wdayname
95 $t->fullday # Tuesday
96 $t->yday # also available as $t->day_of_year, 0 = Jan 01
97 $t->isdst # also available as $t->daylight_savings
98
99 $t->hms # 12:34:56
100 $t->hms(".") # 12.34.56
101 $t->time # same as $t->hms
102
103 $t->ymd # 2000-02-29
104 $t->date # same as $t->ymd
105 $t->mdy # 02-29-2000
106 $t->mdy("/") # 02/29/2000
107 $t->dmy # 29-02-2000
108 $t->dmy(".") # 29.02.2000
109 $t->datetime # 2000-02-29T12:34:56 (ISO 8601)
110 $t->cdate # Tue Feb 29 12:34:56 2000
111 "$t" # same as $t->cdate
112
113 $t->epoch # seconds since the epoch
114 $t->tzoffset # timezone offset in a Time::Seconds object
115
116 $t->julian_day # number of days since Julian period began
117 $t->mjd # modified Julian date (JD-2400000.5 days)
118
119 $t->week # week number (ISO 8601)
120
121 $t->is_leap_year # true if it its
122 $t->month_last_day # 28-31
123
124 $t->time_separator($s) # set the default separator (default ":")
125 $t->date_separator($s) # set the default separator (default "-")
126 $t->day_list(@days) # set the default weekdays
127 $t->mon_list(@days) # set the default months
128
129 $t->strftime(FORMAT) # same as POSIX::strftime (without the overhead
130 # of the full POSIX extension)
131 $t->strftime() # "Tue, 29 Feb 2000 12:34:56 GMT"
132
133 Time::Piece->strptime(STRING, FORMAT)
134 # see strptime man page. Creates a new
135 # Time::Piece object
136
137=end original
138
51139 $t->sec # $t->second も可
52140 $t->min # $t->minute も可
53 $t->hour # 24時制
141 $t->hour # 24 時制
54142 $t->mday # $t->day_of_month も可
55143 $t->mon # 1 = 一月
56144 $t->_mon # 0 = 一月
57145 $t->monname # Feb
58146 $t->month # $t->monname と同じ
59147 $t->fullmonth # February
60 $t->year # 0始まり(AD0年は、もちろん、BC1年)
148 $t->year # 0 始まり(AD 0 年は、もちろん、BC 1 年)
61 $t->_year # 年から1900引いたもの
149 $t->_year # 年から 1900引いたもの
62 $t->yy # 2桁の年
150 $t->yy # 2 桁の年
63151 $t->wday # 1 = 日曜
64152 $t->_wday # 0 = 日曜
65153 $t->day_of_week # 0 = 日曜
66154 $t->wdayname # Tue
67155 $t->day # wdayname と同じ
68156 $t->fullday # Tuesday
69 $t->yday # $t->day_of_year も可, 0 = Jan 01
157 $t->yday # $t->day_of_year も可, 0 = 1 1
70158 $t->isdst # $t->daylight_savings も可。
71159
72160 $t->hms # 12:34:56
73161 $t->hms(".") # 12.34.56
74162 $t->time # $t->hms と同じ
75163
76164 $t->ymd # 2000-02-29
77165 $t->date # $t->ymd と同じ
78166 $t->mdy # 02-29-2000
79167 $t->mdy("/") # 02/29/2000
80168 $t->dmy # 29-02-2000
81169 $t->dmy(".") # 29.02.2000
82170 $t->datetime # 2000-02-29T12:34:56 (ISO 8601)
83171 $t->cdate # Tue Feb 29 12:34:56 2000
84172 "$t" # $t->cdate と同じ
85173
86174 $t->epoch # epochからの秒
87 $t->tzoffset # timezone offset in a Time::Seconds object
175 $t->tzoffset # Time::Seconds オブジェクトによるタイムゾーンオフセット
88176
89177 $t->julian_day # ユリウス歴が始まってからの日の数
90 $t->mjd # modified Julian date (JD-2400000.5 days)
178 $t->mjd # 修正ユリウス日 (JD-2400000.5 )
91179
92180 $t->week # 週番号 (ISO 8601)
93181
94182 $t->is_leap_year # 閏年なら真を返す
95183 $t->month_last_day # 28-31
96184
97 $t->time_separator($s) # デフォルトのセパレータをセットします (default ":")
185 $t->time_separator($s) # デフォルトのセパレータを設定 (デフォルト ":")
98 $t->date_separator($s) # デフォルトのセパレータをセットします (default "-")
186 $t->date_separator($s) # デフォルトのセパレータを設定 (デフォルト "-")
99 $t->day_list(@days) # デフォルトの曜日をセットします
187 $t->day_list(@days) # デフォルトの曜日を設定
100 $t->mon_list(@days) # デフォルトの月名をセットします
188 $t->mon_list(@days) # デフォルトの月名を設定
101189
102 $t->strftime(FORMAT) # POSIX::strftime と同じ(without the overhead
190 $t->strftime(FORMAT) # POSIX::strftime と同じ(しかし完全な
103 # of the full POSIX extension)
191 # POSIX 拡張のためのオーバーヘッドはありません)
104192 $t->strftime() # "Tue, 29 Feb 2000 12:34:56 GMT"
105193
106194 Time::Piece->strptime(STRING, FORMAT)
107 # strptime man ページを見て下さい
195 # strptime man ページを見て下さい。新しく
108 # 新しく、Time::Piece object を作ります
196 # Time::Piece オブジェクトを作ります
109197
110198=head2 Local Locales
111199
200(ローカルロケール)
201
202=begin original
203
112204Both wdayname (day) and monname (month) allow passing in a list to use
113205to index the name of the days against. This can be useful if you need
114206to implement some form of localisation without actually installing or
115207using locales.
116208
117曜日(day)と月名(month)の両方ともに、曜日のインデックスに使うリストに渡すことを
209=end original
118許しています。実際にインストールしたり、ロケールを使わずに、
119なんらかのローカライゼーションを実装する必要があれば、有益でしょう。
120210
211wdayname (day) と monname (month) の両方ともに、曜日のインデックスに使う
212リストを渡すことができます。
213実際にロケールをインストールしたり使ったりせずに、ある種の地域化を実装する
214必要があるなら、有益でしょう。
215
121216 my @days = qw( Dimanche Lundi Merdi Mercredi Jeudi Vendredi Samedi );
122217
123218 my $french_day = localtime->day(@days);
124219
220=begin original
221
125222These settings can be overriden globally too:
126223
224=end original
225
127226これらの設定はグローバルにもオーバーライドできます:
128227
129228 Time::Piece::day_list(@days);
130229
230=begin original
231
131232Or for months:
132233
234=end original
235
133236また、月なら:
134237
135238 Time::Piece::mon_list(@months);
136239
240=begin original
241
137242And locally for months:
138243
139ローカルにするなら:
244=end original
140245
246月に関してローカルに行うなら:
247
141248 print localtime->month(@months);
142249
143=head2 日付の演算
250=head2 Date Calculations
144251
252(日付の演算)
253
254=begin original
255
145256It's possible to use simple addition and subtraction of objects:
146257
258=end original
259
147260単純なオブジェクトの足し算、引き算ができます:
148261
149262 use Time::Seconds;
150263
151264 my $seconds = $t1 - $t2;
152265 $t1 += ONE_DAY; # add 1 day (constant from Time::Seconds)
153266
267=begin original
268
154269The following are valid ($t1 and $t2 are Time::Piece objects):
155270
156下記のようにx使えます($t と $t2 はTime::Piece オブジェクト):
271=end original
157272
273下記のものは有効です($t1 と $t2 は Time::Piece オブジェクト):
274
158275 $t1 - $t2; # returns Time::Seconds object
159276 $t1 - 42; # returns Time::Piece object
160277 $t1 + 533; # returns Time::Piece object
161278
279=begin original
280
162281However adding a Time::Piece object to another Time::Piece object
163282will cause a runtime error.
164283
165ですが、Time::Piece オブジェクトに、別のTime::Piece オブジェクトを
284=end original
285
286ですが、Time::Piece オブジェクトに別の Time::Piece オブジェクトを
166287足すのは、実行時エラーを引き起こします。
167288
289=begin original
290
168291Note that the first of the above returns a Time::Seconds object, so
169292while examining the object will print the number of seconds (because
170293of the overloading), you can also get the number of minutes, hours,
171294days, weeks and years in that delta, using the Time::Seconds API.
172295
173上の例の最初のものは、Time::Seconds オブジェクトを返すことに注意して下さい。
296=end original
174オブジェクトを試験することで秒数を出力(オーバーロードによって)する一方で、
175Time::Seconds のAPIを使って、その差異から、分数、時間数、日数、週の数、年数を、
176得ることが出来ます。
177297
178=head2 日付の比較
298上の例の最初のものは、Time::Seconds オブジェクトを返すことに注意して下さい;
299オブジェクトを試験することで(オーバーロードによって)秒数を出力する一方で、
300Time::Seconds の API を使って、その差異から、分数、時間数、日数、週の数、
301年数を得ることが出来ます。
179302
303=begin original
304
305In addition to adding seconds, there are two APIs for adding months and
306years:
307
308=end original
309
310秒の加算に加えて、月と年を加算するための二つの API があります:
311
312 $t->add_months(6);
313 $t->add_years(5);
314
315=begin original
316
317The months and years can be negative for subtractions. Note that there
318is some "strange" behaviour when adding and subtracting months at the
319ends of months. Generally when the resulting month is shorter than the
320starting month then the number of overlap days is added. For example
321subtracting a month from 2008-03-31 will not result in 2008-02-31 as this
322is an impossible date. Instead you will get 2008-03-02. This appears to
323be consistent with other date manipulation tools.
324
325=end original
326
327月と年は減算のために負数にもなり得ます。
328月末で月を加減算すると「おかしな」振る舞いになることに注意してください。
329一般的に結果となる月が開始月より短い場合、重なった日の分が追加されます。
330例えば、2008-03-31 から 1 ヶ月引くと、あり得ない日付である 2008-02-31 には
331なりません。
332代わりに 2008-03-02 になります。
333これは他の日付操作ツールと一貫性があるように思われます。
334
335=head2 Date Comparisons
336
337(日付の比較)
338
339=begin original
340
180341Date comparisons are also possible, using the full suite of "<", ">",
181342"<=", ">=", "<=>", "==" and "!=".
182343
183日付の比較もまた可能です。 "<"、 ">"、"<="、 ">="、 "<=>"、 "=="、 "!="
344=end original
184の全てが使えます。
185345
186=head2 日付の解析
346日付の比較も可能です;
347"<"、 ">"、"<="、 ">="、 "<=>"、 "=="、 "!=" の全てが使えます。
187348
188Time::Piece links to your C library's strptime() function, allowing
349=head2 Date Parsing
350
351(日付の解析)
352
353=begin original
354
355Time::Piece has a built-in strptime() function (from FreeBSD), allowing
189356you incredibly flexible date parsing routines. For example:
190357
191Time::Piece は、C ライブラリの strptime()関数にリンクしているので、
358=end original
192信じられない程柔軟に日付を解析するルーチンを使えます。たとえば:
193359
194 my $t = Time::Piece->strptime("Sun 3rd Nov, 1943",
360Time::Piece は、驚くほど柔軟に日付を解析する組み込みの (FreeBSD 由来の)
361strptime() 関数を使えます。
362たとえば:
363
364 my $t = Time::Piece->strptime("Sunday 3rd Nov, 1943",
195365 "%A %drd %b, %Y");
196366
197367 print $t->strftime("%a, %d %b %Y");
198368
369=begin original
370
371Outputs:
372
373=end original
374
199375次のように出力します:
200376
201377 Wed, 03 Nov 1943
202378
379=begin original
380
203381(see, it's even smart enough to fix my obvious date bug)
204382
205(見て下さい、一目瞭然な日付のバグを直すのに十分賢い)
383=end original
206384
385(ほら、私の一目瞭然な日付のバグを直すのに十分なくらい賢いです)
386
387=begin original
388
207389For more information see "man strptime", which should be on all unix
208390systems.
209391
210もっと知りたければ、"man strptime"を見て下さい。これは、
392=end original
211すべての unix システムで使えます。
212393
394もっと知りたければ、"man strptime" を見て下さい;
395これは、すべての unix システムで使えるはずです。
396
397=begin original
398
399Alternatively look here: http://www.unix.com/man-page/FreeBSD/3/strftime/
400
401=end original
402
403あるいは、次のリンクを見てください:
404http://www.unix.com/man-page/FreeBSD/3/strftime/
405
213406=head2 YYYY-MM-DDThh:mm:ss
214407
408=begin original
409
215410The ISO 8601 standard defines the date format to be YYYY-MM-DD, and
216411the time format to be hh:mm:ss (24 hour clock), and if combined, they
217412should be concatenated with date first and with a capital 'T' in front
218413of the time.
219414
220ISO 8601 標準は、日付のフォーマットを YYYY-MM-DDとして、定めています。
415=end original
221時間は、hh:mm:ss(24時)です。組み合わせる場合、
222日付を最初にして、時間の前に大文字の'T'で結び付ける必要があります。
223416
224=head2 週番号
417ISO 8601 標準は、日付のフォーマットを YYYY-MM-DD として、
418時刻は hh:mm:ss(24 時制) として定めています。
419組み合わせる場合、日付を最初にして、時刻の前に大文字の 'T' で結び付ける
420必要があります。
225421
422=head2 Week Number
423
424(週番号)
425
426=begin original
427
226428The I<week number> may be an unknown concept to some readers. The ISO
2274298601 standard defines that weeks begin on a Monday and week 1 of the
228430year is the week that includes both January 4th and the first Thursday
229431of the year. In other words, if the first Monday of January is the
2304322nd, 3rd, or 4th, the preceding days of the January are part of the
231433last week of the preceding year. Week numbers range from 1 to 53.
232434
233I<週番号>は、読者によっては、その概念を知らないかもしれません。
435=end original
234ISO 8601 標準は、週は、月曜で始まり、一年のweek 1は、1月4日と、
235一年の最初の木曜日の両方を含む週です。
236言い換えると、1月の最初の月曜日が2日か、3日か、4日であれば、
237その前の日は、昨年の最後の週の一部になります。週番号は、1から53の範囲です。
238436
239=head2 グローバルオーバーライド
437I<週番号> は、概念を知らい読者もいるかもしれません。
438ISO 8601 標準は、週は月曜で始まり、その年の第 1 週は 1 月 4 日と
439一年の最初の木曜日の両方を含む週であると定義しています。
440言い換えると、1 月の最初の月曜日が 2 日か、3 日か、4 日であれば、
441それより前の日は、昨年の最後の週の一部になります。
442週番号は、1 から 53 の範囲です。
240443
444=head2 Global Overriding
445
446(グローバルなオーバーライド)
447
448=begin original
449
241450Finally, it's possible to override localtime and gmtime everywhere, by
242451including the ':override' tag in the import list:
243452
244localtime gmtime をどこにでもオーバーライドするのを可能にします。
453=end original
245インポートリストに、':override'を含めて下さい:
246454
455最後に、localtime と gmtime をどこにでもオーバーライドすることが可能です;
456インポートリストに、':override' タグを含めて下さい:
457
247458 use Time::Piece ':override';
248459
249=head1 著者
460=head1 CAVEATS
250461
462=head2 Setting $ENV{TZ} in Threads on Win32
463
464(Win32 でスレッドで $ENV{TZ} を設定する)
465
466=begin original
467
468Note that when using perl in the default build configuration on Win32
469(specifically, when perl is built with PERL_IMPLICIT_SYS), each perl
470interpreter maintains its own copy of the environment and only the main
471interpreter will update the process environment seen by strftime.
472
473=end original
474
475Win32 で perl をデフォルトビルド設定で使う場合
476(特に perl が PERL_IMPLICIT_SYS でビルドされている場合)、
477それぞれの perl インタプリタは独自の環境変数のコピーを保守していて、
478メインインタプリタのみが strftime で見られるプロセス環境変数を
479更新できることに注意してください。
480
481=begin original
482
483Therefore, if you make changes to $ENV{TZ} from inside a thread other than
484the main thread then those changes will not be seen by strftime if you
485subsequently call that with the %Z formatting code. You must change $ENV{TZ}
486in the main thread to have the desired effect in this case (and you must
487also call _tzset() in the main thread to register the environment change).
488
489=end original
490
491従って、メインスレッド以外のスレッド内から $ENV{TZ} を変更すると、
492後で strftime の %Z フォーマッティングコードを使っても変更は見えません。
493この場合、望み通りの効果を得るためにはメインスレッドで
494$ENV{TZ} を変更しなければなりません (そして環境変数の変更を登録するために
495メインスレッドで _tzset() を呼び出さなければなりません)。
496
497=begin original
498
499Furthermore, remember that this caveat also applies to fork(), which is
500emulated by threads on Win32.
501
502=end original
503
504さらに、この問題は fork() にも適用されることを忘れないでください; これは
505Win32 ではスレッドでエミュレートされています。
506
507=head2 Use of epoch seconds
508
509(紀元秒を使う)
510
511=begin original
512
513This module internally uses the epoch seconds system that is provided via
514the perl C<time()> function and supported by C<gmtime()> and C<localtime()>.
515
516=end original
517
518このモジュールは、perl の C<time()> 経由で提供され、C<gmtime()> と
519C<localtime()> が対応している紀元秒システムを内部で使用しています。
520
521=begin original
522
523If your perl does not support times larger than C<2^31> seconds then this
524module is likely to fail at processing dates beyond the year 2038. There are
525moves afoot to fix that in perl. Alternatively use 64 bit perl. Or if none
526of those are options, use the L<DateTime> module which has support for years
527well into the future and past.
528
529=end original
530
531C<2^31> 秒以上の時間に対応していない perl を使っている場合、このモジュールは
5322038 年以降の日付を扱おうとするとおそらく失敗するでしょう。
533これは perl 内で修正する動きがみられます。
534あるいは、64 ビット perl を使ってください。
535またはこれらの選択肢を取れない場合は、過去と未来の年に対応している
536L<DateTime> モジュールを使ってください。
537
538=head1 AUTHOR
539
251540Matt Sergeant, matt@sergeant.org
252541Jarkko Hietaniemi, jhi@iki.fi (while creating Time::Piece for core perl)
253542
254=head1 ライセンス
543=head1 License
255544
256545This module is free software, you may distribute it under the same terms
257546as Perl.
258547
259548=head1 SEE ALSO
260549
550=begin original
551
261552The excellent Calendar FAQ at http://www.tondering.dk/claus/calendar.html
262553
263=head1 バグ
554=end original
264555
556http://www.tondering.dk/claus/calendar.html にある素晴らしいカレンダー FAQ。
557
558=head1 BUGS
559
560=begin original
561
265562The test harness leaves much to be desired. Patches welcome.
266563
267=head1 翻訳について
564=end original
268565
269翻訳者:加藤敦 (ktat.is@gmail.com)
566テストハーネスは望ましい状態にはほど遠いです。
567パッチを歓迎します。
270568
271Perlドキュメント日本語訳 Project にて、
569=begin meta
272Perlモジュール、ドキュメントの翻訳を行っております。
273570
274 http://perldocjp.sourceforge.jp/
571Translate: 加藤敦 <ktat.is@gmail.com> (1.08)
275 http://sourceforge.jp/projects/perldocjp/
572Update: SHIRAKATA Kentaro <argrath@ub32.org> (1.20)
276 http://www.freeml.com/ctrl/html/MLInfoForm/perldocjp@freeml.com
277 http://www.perldoc.jp
574=end meta
575
576=cut