Days in a year

Discussion in 'Ruby' started by Pål Bergström, Oct 27, 2008.

  1. How do I get number of days in a year?
    Pål Bergström, Oct 27, 2008
    1. Advertisements

  2. Enter "number of days in a year" into Google and you'll get some useful

    The very first hit gives you

    Google is your friend.
    Brian Candler, Oct 27, 2008
    1. Advertisements

  3. Pål Bergström

    Hélio Rocha Guest

    Just check if the year is leap. In google u'll find something like:

    int __isleap <javascript:searchRef('__isleap')>(int
    /* every fourth year is a leap year except for century years that are
    * not divisible by 400. */
    /* return (year % 4 =3D=3D 0 && (year % 100 !=3D 0 || year % 400 =3D=3D 0)=
    ); */
    return (!(year <javascript:searchRef('year')>%4) &&
    || !(year <javascript:searchRef('year')>%400)));
    Hélio Rocha, Oct 27, 2008
  4. Pål Bergström

    Todd Benson Guest

    You can use the date library...

    require 'date'; puts -
    =3D> 366

    Todd Benson, Oct 27, 2008
  5. So there's nothing like this (Rails)

    Pål Bergström, Oct 27, 2008
  6. A stupid question in the first place. I've done like this; I check if
    Feb in a particular year has 29 days or not, so it gives 365 or 366
    days. Simple. :)
    Pål Bergström, Oct 28, 2008
  7. And notice how days_in_month is implemented in activesupport:

    def days_in_month(month, year = now.year)
    return 29 if month == 2 && ::Date.gregorian_leap?(year)

    So all you need is:

    irb(main):001:0> require 'date'
    => true
    irb(main):002:0> Date.gregorian_leap?(2008) ? 366 : 365
    => 366
    irb(main):003:0> Date.gregorian_leap?(2009) ? 366 : 365
    => 365
    Brian Candler, Oct 28, 2008
  8. Or ask the day of year of December 31st:

    require 'date', 12, 31).yday # => 366, 12, 31).yday # => 366

    Best regards,
    Jan Friedrich
    Jan Friedrich, Oct 28, 2008
  9. Or ask the day of year of December 31st:

    require 'date', 12, 31).yday # => 366, 12, 31).yday # => 365

    Best regards,
    Jan Friedrich
    Jan Friedrich, Oct 28, 2008
  10. That was smart. Thanks!
    Pål Bergström, Oct 28, 2008
  11. Pål Bergström


    Sep 26, 2013
    Likes Received:
    I created a new calendar, which i call ("1253"). This calendar has 12 months. labeled the same as the one used now. the seasons fall, on the 22nd day opf every third month. The number of days are the only alteration for this calendar. they are shuffled minutely to allow the placement of leap day on december 31St, and there is no december 31st in the non leap years.

    the mont3/day quantities are as follows. (FOR LEAP YEAR BEGINNING 2000). 30-31-30-31-30-91-30-31-30-31-30-31. This is leap year and the string =366 days, in equal proportions of 30/31 days per month. there are 6 30 day months, and 6 31 day months. In 2001 the order is (30-31-30-31-30-31-30-31-30-31-30-30) this latter pattern is the same for the years 2002 and 2003, nd the leap year 2004 revertts to the first pattern (which is for each leap year). The pattern then reverts to the second pattern for 2005-2006-2007, and then back to the original pattern for 2008,(leap year pattern), and then back to the secondary pattern, for non leap years for the years 2009-2010-2011, and then to the leap year pattern for 2002, and then back the secondary pattwern for 2003. This is a 14 year history,and it is cionsistent.

    My das's birthday was on jan 31,and is now on feb 1. My birthday was on feb 29. it now falls on feb 30 every year. My brother was born march 1 and his birthday is now on feb 31. My mother was born on march 31, and her birthday is now apri 1. My sister was born on may 1 and her birthday is now on april 30. My cousin was born on july1 and his birthday is now on june 31. My other cousin was born on july 31, and her birthday is now aug 1. My neighbor was born on august 31, and his birthday is still aug 31. My neighbor's wife was born on september 1 and her birthday is still, sept 1. My neighbor's son was born on september 30 and his birthday is still sept 30. his daughter was born on oct 1 and is still on oct 1, My mechanic was born on oct 31 and is still having his birthday on oct 31. My mechanic's wife was orn on november 1 and still celebrates on november 1. My mechanic's son was born on november 30 and his birthday on november 30. My mechanic's daughter was born on december 1 and still celebrates on dec 1. My girlfriend was born on december 31 and only has a birthday every fourth year. She likes this, as she only ages one year for every four years. (LOL).

    This calendar fits as an overlay over conventional calendars, and therefore does not need to be in any conflict , ever, with conventional calendars. As you can see, the only changes are the beginning and ending dates of the month, to achieve consistency, and only the persons born on the first day or last day of the month, are affected. Why is february not affected in a quantity greater than one when there are three more days in non leap years, and 2 more days in leap year? Because one of the days comes from the last day of january, and the other comes from the first day of march, and the third is from the leap day feb 29, which now occurs every year. Therefore the difference si still only (one) regardless which way you go.

    This constance in the number sequences, (6//6 or 6/5) has the effect of making the seasons fall on the same day every year, and the same day of the month every quarter. Always the 22nd day of the 3rd month in the quarter. This was always true anyway, and was never more than one day off, and it was always the same day. So this constance is s till only one day off, and there is no difference in the dates to calculate. the number of the days in each quarter for the change of seanos is always the 83rd day of the quarter, whether the quarter has 91/92 days. TTHEREBY THE LEAP DAY ALWAYS FALLS ON DECEMBER 31ST WHICH IS THE 92ND DAY OF THE FOURTH QUARTER, (THE LAST SDAY OF THE 53RD WEEK, W HICH ALWAYS HAS 2 DAYS IN LEAP YEAR, AND ONE DAY THE REST OF THE YEARS.

    (every year has always had 53 weeks, no one ever tells you tjhis. The 365th day of every is a new month a new week, and always happens. however in leap year this 53rd week has always had , 2 days, and still does. these 2 days have always fell on the 30th and the 31st day of december every year, anyway. And they still do in my calendar.

    it is simply an omission ofht 31st day of december for non leap years and the replacement of it, for leap year. This consistency, is so simple, to learn and caslculate, it could easily replace the old calendar. But then no one would know how to calculate the old methods, so i suggest it never be used as a stand alone calendar. it should always be used as an overlay for other calendars which have a seven day week.

    Thias may not work for other time systems, as it is designed for calendars based on a seven day week. ("52X7=364 and decembner 30 is 365 and december 31 is 366) and this has alwatys eben true anyway.


    Will everyone help me find a good free calendar maker, to create an overlay onto a regular calendar? Thanx for reading.
    chicogringo, Sep 26, 2013
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.