[#49270] [Ruby trunk - Feature #11558] Time related C APIs — akr@...
Issue #11558 has been updated by Akira Tanaka.
7 messages
2015/09/30
[#49275] Re: [Ruby trunk - Feature #11558] Time related C APIs
— KOSAKI Motohiro <kosaki.motohiro@...>
2015/09/30
>> 既存の非公開APIを公開してください。
[#49278] Re: [Ruby trunk - Feature #11558] Time related C APIs
— Tanaka Akira <akr@...>
2015/10/01
2015年10月1日 7:03 KOSAKI Motohiro <kosaki.motohiro@gmail.com>:
[ruby-dev:49270] [Ruby trunk - Feature #11558] Time related C APIs
From:
akr@...
Date:
2015-09-30 08:55:18 UTC
List:
ruby-dev #49270
Issue #11558 has been updated by Akira Tanaka. Yui NARUSE wrote: > Time関連のC APIを追加して欲しいです。 要望は理解できます。 > struct timespecとoffsetを取って、Timeを返してください。 > VALUE rb_time_timespec_new(const struct timespec *ts, int offset); > 趣旨としては、[秒, ナノ秒, offset]からTimeを作って欲しいと言うことです。 > (rb_time_num_new(Rational, offset)とかだと手間かかる上に遅い) いいんじゃないでしょうか。 > 現在時刻をstruct timespecで欲しいです。 > void timespec_now(struct timespec *ts); Ruby の定義であることがわかる prefix が名前に必要だと思います。 > 既存の非公開APIを公開してください。 > struct tm * localtime_with_gmtoff_zone(const time_t *t, struct tm *result, long *gmtoff, const char **zone); time_t を使うと 2038年問題を考慮しないといけないので、よくないと思います。 struct tm を使うと (tm_year が int なので) 2**31年問題を考慮しないといけないので、よくないと思います。 zone を char * で返すのはメモリ管理に責任を持てなくなるので、よくないと思います。 > time_t timegm_noleapsecond(struct tm *tm); time_t と struct tm は上記のようによくないと思います。 > void tm_add_offset(struct tm *tm, long diff); struct tm は上記のようによくないと思います。 tm_year が overflow したらどうするんでしょうか。 まぁ、time_t と struct tm が癌なので、Ruby の公開API用の構造体を定義すれば解決できるとは思います。 (あと zone は Ruby 内部で VALUE で扱うことに変えないといけないと思う。) ---------------------------------------- Feature #11558: Time related C APIs https://bugs.ruby-lang.org/issues/11558#change-54325 * Author: Yui NARUSE * Status: Open * Priority: Normal * Assignee: ---------------------------------------- Time関連のC APIを追加して欲しいです。 具体的には以下のようなものが欲しいです。 struct timespecとoffsetを取って、Timeを返してください。 VALUE rb_time_timespec_new(const struct timespec *ts, int offset); 趣旨としては、[秒, ナノ秒, offset]からTimeを作って欲しいと言うことです。 (rb_time_num_new(Rational, offset)とかだと手間かかる上に遅い) 現在時刻をstruct timespecで欲しいです。 void timespec_now(struct timespec *ts); 既存の非公開APIを公開してください。 struct tm * localtime_with_gmtoff_zone(const time_t *t, struct tm *result, long *gmtoff, const char **zone); time_t timegm_noleapsecond(struct tm *tm); void tm_add_offset(struct tm *tm, long diff); https://github.com/nurse/strptime/blob/v0.1.1/ext/strptime/ruby_time.c -- https://bugs.ruby-lang.org/