ruby 中有 ISO 8601 的综合库/模块吗?
是否已经实施了 ISO 8601 标准的所有日期、时间、持续时间和间隔用法在红宝石中?我的意思是类似一个类,您可以在其中设置和获取详细信息,例如年、月、日、周、小时、分钟、is_duration?、has_recurrence?等等哪些也可以通过字符串设置并导出到字符串?
Is there already an implementation of all the date, time, duration and interval usage of the ISO 8601 standard in ruby? I mean something like a Class where you can set and get the details like, year, month, day, day_of_the_week, week, hour, minutes, is_duration?, has_recurrence? and so on which also can be set by and exported to a string?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看时间。它里面有很多东西。
不幸的是,Ruby 的内置日期时间函数似乎没有经过深思熟虑(例如与 .NET 相比),因此对于其他功能,您将需要使用一些 gem。
好的一点是,使用这些 gem 确实感觉像是内置的 Ruby 实现。
最有用的可能是来自 ActiveSupport (Rails 3) 的时间计算。
您不需要 Rails,只需要这个小库:
gem install activesupport
。那么你可以做:
确实有很多事情可以做你可以做,我相信你会找到非常适合你的需求的。
因此,我不在这里为您提供抽象示例,而是鼓励您尝试使用需要
active_support
的irb
。将时间计算放在手边。
Have a look at the Time. It has a lot of stuff in it.
Unfortunately Ruby's built-in Date-Time functions do not seem to be well thought through (comparing to .NET for example), so for other functionality you will need to use some gems.
Good thing is that using those gems does feel like it's a built-into Ruby implementation.
Most useful probably is Time Calculations from ActiveSupport (Rails 3).
You don't need to require the rails but only this small library:
gem install activesupport
.Then you can do:
There are really a lot of things that you can do and I believe you will find what suites your needs very well.
So instead of giving you abstract examples here I encourage you to experiment with
irb
requiringactive_support
from it.Keep the Time Calculations at hand.
Ruby Time 库向 Time 类添加了 iso8601 方法。请参阅此处。
我不知道导出其他 ISO 8601 格式的 gem。您可以自己扩展 Time 类来添加它们。
通常,您会使用 strftime 方法来打印特定格式。 示例。
Ruby Time library adds an iso8601 method to the Time class. See here.
I don't know of a gem that exports the other ISO 8601 formats. You could extend the Time class yourself to add them.
Often you'll use the strftime method to print out specific formats. Example.