Results 1 to 8 of 8

Thread: Date algoritm

  1. #1

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    Date algoritm

    maybe this isn't the right forum for this, but it's my favourite forum so i decided to post here

    I need an algoritm to express a date format stored as a 32bit integer. In fact i need to express a date according to any planet with or without at least one moon. If there's no moons, month is omited and year and day is expressed. The time for the 32 bit integer is absolute. Currently i only know how to get year:

    year= Time/Sunrot;Time%=Sunrot;

    day=Time/Planetrot;

    here's where i get stuck, the Planet rotates absolute to Time, but since the first day has to start with the first whole day I don't know where the day changes as original Time is erased. That would be nothing compared to the next problem, how do i put in the days on leapyears and how should i put in or remove extra leapyears?

    Another qwestion, is there a reason to why each month is different length (on earth)?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  2. #2
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    It's because the gregorian calender is screwed big time.
    Actually, it wouldnt fit with only 30 day months and only 31 day months so they decided on a mixture of the two (that and 28 day months, 29 if leap year)

    A year is 365.25 (approx.) days.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  3. #3

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    thanks, i was expecting something like that, but i still need a screwed up model of counting months, based on days, shouldn't be a problem except very annoying.

    Anyway i worked out the leapyear problem by drawing some diagrams and banging my head against the wall a couple of times.
    Code:
    Year=Time/Sun;
    X=Time%Planet; 					//Time Since Midnight
    Day=((Time%=Sun)+Planet-X)/Planet;		//Time gets relative to NewYear, Convert to day after adding the rest of the day.
    if (!Day){					//Day belongs to last year
    	Day=Sun/Planet+((X-Time)<(Sun%Planet));	//Last day of last year + possible leapyear, which happens when the gap between
    	Year--;					//Last day and current year is smaller than the gap between first year's last day
    }						//and Second year.
    the whole thing got clear when i realized the first gap on a year shouldn't be smaller than the gap for the absolute year and last day. I'm still wondering if i should have Years starting at 0 or 1 since Day starts on 1.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  4. #4

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    BTW
    How many times (exactly) does the moon rotate around earth per year? that is how long does it take for moon to make a revolution around earth. If it's not 1/12 a year then what?

    In case moons don't have a tendency to make integer amount of revolutions per year (pardon my ignorance in astronomy) i'm running into another problem, should i include an option for having month relative to year as day is and then have day relative to month? (i want to be a bit realistic extrapolating alien intelligence)
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  5. #5

  6. #6

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Thanks, hmm 13.36 months i didn't know that
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  7. #7
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Hum, the way I'd do it would be to simply get the total number of days, and then divide it by 12 to get the number of days in each month... the number of months would be always 12 to keep it simple (dunno any other way to get another number of months ). You could also just make it like 30 or 31 days in a random pattern so you have 365 days at the end
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  8. #8

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Not too hard to simulate a screwed up calendar, but i'm also planning on serious ones
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width