Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3345384
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:10:46+00:00 2026-05-18T01:10:46+00:00

Ruby’s date/time helpers are useful but I found a discrepancy. It seems that 12.months

  • 0

Ruby’s date/time helpers are useful but I found a discrepancy. It seems that 12.months does not equal 1.year. Check 1.month and you’ll find it’s equal to 30.days and, of course, 12 * 30.days = 360.days, 5.25 days short of an actual year’s length.

I came across this when I set access to certain components of our web site based on the number of months granted, as specified by the client. I discovered that a 36.month term expired a couple of weeks early when running my tests. The solution was something like this:

def months_to_seconds(number_of_months)
  ( (number_of_months.to_f / 12) * 1.year).to_i.seconds
end

This returns the number of seconds in whatever fraction of a year is represented by the number_of_months.

Since 1.year is equal in seconds to 365.25 days, why do you suppose they didn’t have 1.month return the seconds for 1/12 of a year instead of 30 days?

Has anyone run across this before? Does anyone have a better solution?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T01:10:47+00:00Added an answer on May 18, 2026 at 1:10 am

    The calendar, and time in general, is such an arbitrary thing and is riddled with inconsistencies like this. There is no standard length of “month”, as the variation is anywhere between 28 and 31 days, just as there is no standard length of “day”, which can be anywhere from 23 to 25 hours, and even minute can have anywhere from 59 to 62 seconds when “leap seconds” are taken into account. Likewise a year can be 365 or 366 days, or even 351 as was the case in 1582.

    Unless you’re doing calculations specific to a particular interval, like the number of seconds between January 3, 2010 and October 19, 2011, you will not be able to know how long the interval is using abstract months, days, or years. These things are dependent on a huge number of factors.

    Your solution is suitable for your application, but in Rails terms a “month” is simply 30 days for simplicity’s sake, just as a “day” is 24 hours.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ruby has conditional initialization. Apparently, Java does not or does it? I try to
ruby -n is the closest thing I found, but it repeats the whole script.
Ruby's standard popen3 module does not work on Windows. Is there a maintained replacement
Ruby on Rails does not do multithreaded request-responses very well, or at least, ActiveRecord
ruby 1.8.7 does not compile well under Lion and Xcode 4.2. I'd like to
ruby newbie alert! (hey that rhymes :)) I have read the official definition but
Ruby has a select method that takes an array and returns a subarray consisting
ruby-mode from svn, looks equal to 1.1 version here is emacs indentation of hash
Ruby Enterprise Edition fails to compile from sources with GCC 4.5, but sucessfully compiles
Ruby's Time.parse() works for dates from Dec 14 1901 up Jan 18 2038 (this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.