Days in a year

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

  1. Pål Bergström, Oct 27, 2008
    #1
    1. Advertising

  2. Brian Candler, Oct 27, 2008
    #2
    1. Advertising

  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
    year<javascript:searchRef('year')>)
    {
    /* 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')>%100)
    || !(year <javascript:searchRef('year')>%400)));
    }

    On Mon, Oct 27, 2008 at 2:12 PM, P=E5l Bergstr=F6m <> w=
    rote:

    > How do I get number of days in a year?
    > --
    > Posted via http://www.ruby-forum.com/.
    >
    >
     
    Hélio Rocha, Oct 27, 2008
    #3
  4. Pål Bergström

    Todd Benson Guest

    On Mon, Oct 27, 2008 at 9:12 AM, P=E5l Bergstr=F6m <> w=
    rote:
    > How do I get number of days in a year?


    You can use the date library...

    require 'date'; puts Date.new(2005) - Date.new(2004)
    =3D> 366

    Todd
     
    Todd Benson, Oct 27, 2008
    #4
  5. Todd Benson wrote:
    > On Mon, Oct 27, 2008 at 9:12 AM, P�l Bergstr�m <> wrote:
    >> How do I get number of days in a year?

    >
    > You can use the date library...
    >
    > require 'date'; puts Date.new(2005) - Date.new(2004)
    > => 366
    >
    > Todd


    So there's nothing like this (Rails)

    Time.days_in_month()
    --
    Posted via http://www.ruby-forum.com/.
     
    Pål Bergström, Oct 27, 2008
    #5
  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. :)
    --
    Posted via http://www.ruby-forum.com/.
     
    Pål Bergström, Oct 28, 2008
    #6
  7. Pål Bergström wrote:
    > 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. :)


    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)
    COMMON_YEAR_DAYS_IN_MONTH[month]
    end

    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
    --
    Posted via http://www.ruby-forum.com/.
     
    Brian Candler, Oct 28, 2008
    #7
  8. Brian Candler <> wrote:
    > 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


    Or ask the day of year of December 31st:

    require 'date'
    DateTime.new(2008, 12, 31).yday # => 366
    DateTime.new(2009, 12, 31).yday # => 366

    Best regards,
    Jan Friedrich
     
    Jan Friedrich, Oct 28, 2008
    #8
  9. Brian Candler <> wrote:
    > 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


    Or ask the day of year of December 31st:

    require 'date'

    DateTime.new(2008, 12, 31).yday # => 366

    DateTime.new(2009, 12, 31).yday # => 365

    Best regards,
    Jan Friedrich
     
    Jan Friedrich, Oct 28, 2008
    #9
  10. Jan Friedrich wrote:
    > Brian Candler <> wrote:


    > Or ask the day of year of December 31st:
    >
    > require 'date'
    >
    > DateTime.new(2008, 12, 31).yday # => 366
    >
    > DateTime.new(2009, 12, 31).yday # => 365
    >
    > Best regards,
    > Jan Friedrich


    That was smart. Thanks!
    --
    Posted via http://www.ruby-forum.com/.
     
    Pål Bergström, Oct 28, 2008
    #10
  11. Pål Bergström

    chicogringo

    Joined:
    Sep 26, 2013
    Messages:
    1
    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.

    THERFORE THIS CALENDAR I HAVE LABELED TO BE ("1253").

    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
    #11
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Stockwell
    Replies:
    2
    Views:
    730
    Anna Martelli Ravenscroft
    Sep 20, 2004
  2. Gerrit
    Replies:
    0
    Views:
    412
    Gerrit
    Sep 20, 2004
  3. Terry Reedy
    Replies:
    0
    Views:
    447
    Terry Reedy
    Sep 20, 2004
  4. Replies:
    5
    Views:
    502
    Bo Yang
    Nov 2, 2006
  5. kirke

    list of days between two days

    kirke, Oct 19, 2006, in forum: Javascript
    Replies:
    7
    Views:
    153
    Julian Turner
    Oct 20, 2006
Loading...

Share This Page