Главная
translate
Войти
Регистрация
Форум
Блоги
Пользователи
Ресурсы
Список джемов
Поиск
Loading...
Login form
Ruby On Rails in UA
/
Code Review, Вопросы по теории программирования
/
Работа с датами date_cheat_sheet
/
Вычисденя с датами
назад
новый
ответить
2008-06-06 11:38:45
Ответить
Ruslan Voloshin
Адрес:
odessa
Сообщений: 978
Регистр: 2007-03-13
его блог
28 сообщ.
Вычисденя с датами
require 'date' (Date.new(1776, 7, 2)..Date.new(1776, 7, 4)).each { |x| puts x } # 1776-07-02 # 1776-07-03 # 1776-07-04 span = DateTime.new(1776, 7, 2, 1, 30, 15)..DateTime.new(1776, 7, 4, 7, 0, 0) span.each { |x| puts x } # 1776-07-02T01:30:15Z # 1776-07-03T01:30:15Z # 1776-07-04T01:30:15Z (Time.at(100)..Time.at(102)).each { |x| puts x } # Wed Dec 31 19:01:40 EST 1969 # Wed Dec 31 19:01:41 EST 1969 # Wed Dec 31 19:01:42 EST 1969 #--- the_first = Date.new(2004, 1, 1) the_fifth = Date.new(2004, 1, 5) the_first.upto(the_fifth) { |x| puts x } # 2004-01-01 # 2004-01-02 # 2004-01-03 # 2004-01-04 # 2004-01-05 #--- class Time def step(other_time, increment) raise ArgumentError, "step can't be 0" if increment == 0 increasing = self < other_time if (increasing && increment < 0) || (!increasing && increment > 0) yield self return end d = self begin yield d d += increment end while (increasing ? d <= other_time : d >= other_time) end def upto(other_time) step(other_time, 1) { |x| yield x } end end the_first = Time.local(2004, 1, 1) the_second = Time.local(2004, 1, 2) the_first.step(the_second, 60 * 60 * 6) { |x| puts x } # Thu Jan 01 00:00:00 EST 2004 # Thu Jan 01 06:00:00 EST 2004 # Thu Jan 01 12:00:00 EST 2004 # Thu Jan 01 18:00:00 EST 2004 # Fri Jan 02 00:00:00 EST 2004 the_first.upto(the_first) { |x| puts x } # Thu Jan 01 00:00:00 EST 2004 #---
date
,
DateTime.new
,
interactiong over dates
,
Time.local
назад
новый
ответить
Ключевые слова:
globalize [2]
Mongrel 1.0.1 [1]
tempfile [1]
$_ [1]
auto_complete [1]
Zend [1]
NetBeanse vendor [1]
svn propset [1]
XAMPP [1]
rxml [3]
array [2]
cron rails [1]
cache mod_headers [1]
разработка сайтов [1]
svn ci -m [1]
grep mysql.sock [1]
rake save db data to fixtures [1]
rails centos [1]
rake db [1]
Comparing Floating-Point Numbers [1]
Гости: 118 Онлайн: 0
О проекте
по всем вопросам обращайтесь на
support
Rubyclub.com.ua
Copyright © 2007 - 2008