草庐IT

date-difference

全部标签

ruby-on-rails - Rails 2.3.5 - ".find"函数不适用于 ( :condition = >"date") option

我想做的是查找过去60天内使用过的特定记录。我正在使用Oracle(9i),railsv:2.3.5,rubyv:1.8.7我定义日期间隔的代码是:date=(((Time.now-60.days).strftime("%d-%b-%y"))...(Time.now.strftime("%d-%b-%y")))下面是我如何使用它:conditions={}conditions[:start_date]=dateconditions[:account_no]=account_numberresults=MyModel.find(:all,:conditions=>conditions)要

ruby - gem date_validator 不工作 Ruby 1.9.3 Rails 3.2.1

我刚刚安装了这个gem:geminstall'date_validation'我可以看到它已正确安装,因为它在我使用时出现在列表中:gemlist但是当我尝试将字段表单的内容验证为日期时,出现此错误:ArgumentErrorinProductesController#newUnknownvalidator:'DateValidator'我使用这段代码来验证:validates:data_caducitat,:date=>{:after=>Proc.new{Time.now}}知道可能是什么问题吗?提前致谢。 最佳答案 Rails3

ruby-on-rails - Rails routing with date 并且有很多

我有以下设置:map.resources:articlesmap.resources:users,:has_many=>[:articles]这很好,因为我可以执行/users/2/articles来获取给定用户的文章列表。我还有一个路线设置要做:map.connect'articles/month/:month/:year',:controller=>'articles',:action=>'index'这适用于查找给定月份和给定年份的所有文章。我现在想做的是显示给定用户在给定月份和年份的文章。也许是这样的url:/users/2/articles/month/4/2009有没有一种

ruby-on-rails - Rails Date#strptime 在 200 年之前错误地解析日期

为什么Rails的Date#strptime将“13/08”解析为200年之前的8月15日或8月14日?Date.strptime('13/08/99','%d/%m/%Y')#=>Thu,15Aug0099Date.strptime('13/08/100','%d/%m/%Y')#=>Fri,14Aug0100Date.strptime('13/08/199','%d/%m/%Y')#=>Tue,14Aug0199Date.strptime('13/08/200','%d/%m/%Y')#=>Wed,13Aug0200 最佳答案

ruby-on-rails - rails : Difference between timezones in hours

我想说user1比user2早4小时,这是根据用户在其帐户中指定的时区计算的。使用以下代码:time1=Time.zone.now.in_time_zone(user1.time_zone)time2=Time.zone.now.in_time_zone(user2.time_zone)distance_of_time_in_wordstime1,time2...相差不到一分钟-同样减去两次得到0。Rails显然仍然认为这两次相同。知道如何计算两个时区之间的差异吗? 最佳答案 如果您使用time1实例并对其调用utc_offset,

ruby-on-rails - 参数转换的禅宗方式[:date] to Date?

将params[:date]字段转换为Date对象的最优雅的方法是什么?"date"=>{"day"=>"13","year"=>"2012","month"=>"4"}目前,我在controller中有如下代码:@date=Date.currentifparams[:date]yy=mm=dd=0yy=params[:date][:year].to_iifparams[:date][:year]mm=params[:date][:month].to_iifparams[:date][:month]dd=params[:date][:day].to_iifparams[:date][:

ruby-on-rails - 为什么 Date.tomorrow > Time.now 在 Ruby on Rails 中返回 false?

查看RoRpry控制台结果:[1]pry(main)>Date.tomorrow>Time.now=>false[2]pry(main)>Date.tomorrow.to_time>Time.now=>true[3]pry(main)>Date.tomorrow=>Tue,07Oct2014[4]pry(main)>Time.now=>2014-10-0622:52:40-0400添加了时间戳结果,让您知道粗略的值。 最佳答案 因为Date.tomorrow是明天而Time.nowUTC也是明天。您会注意到您在10:52pm执行此操

ruby-on-rails - 如何使用 'assert_difference' 为两个不同的对象断言两个不同的值?

我有以下测试:it'createaction:auserrepliestoapostforthefirsttime'dologin_asuser#ActionMailergoesupbytwobecauseauserwhocreatedatopichasanaccompanyingpost.#Oneemailforpostcreation,anotherforpostreplies.assert_difference(['Post.count','ActionMailer::Base.deliveries.size'],2)dopost:create,topic_id:topic.id

java - 从非 Java Ruby 迁移到 Groovy : Language Differences

使用我并不出色的Google技能,我未能找到适合Ruby程序员的Groovy教程。有很多政治文章(Ruby很棒!Groovy很棒!)和微小的对比,但我真的不在乎哪个更好。我比较了解Ruby(和Java),我想学习Groovy。有人会关心(提供一个惊人的链接或)标记两种语言在如何做事(句法、类声明、循环、block等)方面的一些差异吗?出于我的目的,您可以假设具备完整的Java能力来进行解释。同样,我对知道哪个更好不感兴趣。只需要知道如何做事.... 最佳答案 如果您了解Java,那么您能读到的最好的东西就是如何在Groovy中使用元

引用 Date 时出现 Ruby NameError

我使用以下代码得到“未初始化的常量日期(NameError)”:classTestattr_accessor:reqsdefinitialize()@reqs=[]endendclassTestBuilderdeftest(&block)@current=Test.newblock.call@currentenddefolder_than_days(age)@current.reqs"Mon,5Apr201003:17:46-0400"})阅读这个问题的答案后添加了双冒号:Uninitializedconstant...NameError因为ruby​​试图在TestBuilder中查