NO

Author Topic: Week2Date  (Read 4645 times)

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 1828
Week2Date
« on: May 28, 2008, 09:07:25 pm »
Is this reliable way to find date from week?
May the source be with you

JohnF

  • Guest
Re: Week2Date
« Reply #1 on: May 29, 2008, 10:44:18 am »
You need to increase the size of szBuf to at least 11 as the string is 10 chars in length.

Code: [Select]
int main(int argc, char **argv)
{
char szBuf[11];

John

MT

  • Guest
Re: Week2Date
« Reply #2 on: May 29, 2008, 08:55:07 pm »
Tim,

This relies on the windows API. I like to use my own code where at all possible to make porting to other OS easier.

For data and time functions I use a library I have built over the years. The central functions for date work use Julian date. I have developed a very fast algo for converting gregorian date as a string, to julian date as a Long.

Once in julian format, calculating days is easy. the result is then converted back to gregorian format.

To do what you want, I would convert 1/1/08 to julian then loop with a step of 7 days. Converting the julian sum back would give you the gregorian date.

I could try to convert my code if that would help.

Offline Robert

  • Member
  • *
  • Posts: 187
Re: Week2Date
« Reply #3 on: May 30, 2008, 08:16:59 am »
Is this reliable way to find date from week?


Valid values for wYear are limited to the years 1601 through 30827.

Robert Wishlaw


Grincheux

  • Guest
Re: Week2Date
« Reply #4 on: October 08, 2014, 10:41:21 pm »
For manipulating dates I use the sofa library : http://www.iausofa.org/
 
Here is an example for julian date to windows date :
 
Code: [Select]

  if(Work_Header.Perihelion.dJulien)
 {
  if(iauJd2cal(Work_Header.Perihelion.dJulien,0.00,(int *)&Work_Header.Perihelion.Date.wYear,(int*)&_iMonth,(int*)&Work_Header.Perihelion.Date.wDay,&_dFraction) == 0)
  {
   iauD2tf(9,_dFraction,_szSign,_ihmsf) ;
   Work_Header.Perihelion.Date.wMonth = (WORD) _iMonth ;
   Work_Header.Perihelion.Date.wHour = (WORD) _ihmsf[0] ;
   Work_Header.Perihelion.Date.wMinute = (WORD) _ihmsf[1] ;
   Work_Header.Perihelion.Date.wSecond = (WORD) _ihmsf[2] ;
//   ***************************************************************************
   SystemTimeToFileTime(&Work_Header.Perihelion.Date,&_ft) ;
   FileTimeToSystemTime(&_ft,&Work_Header.Perihelion.Date) ;
//   ***************************************************************************
  }
 }


czerny

  • Guest
Re: Week2Date
« Reply #5 on: October 09, 2014, 08:15:18 am »
This relies on the windows API. I like to use my own code where at all possible to make porting to other OS easier.

For data and time functions I use a library I have built over the years. The central functions for date work use Julian date. I have developed a very fast algo for converting gregorian date as a string, to julian date as a Long.
I too would use the way over Julian date.

But a further commen: There are different definitions in different countrys when the week counting ist starting in a year.

Offline Bitbeisser

  • Global Moderator
  • Member
  • *****
  • Posts: 760
Re: Week2Date
« Reply #6 on: October 09, 2014, 11:51:00 pm »
This relies on the windows API. I like to use my own code where at all possible to make porting to other OS easier.

For data and time functions I use a library I have built over the years. The central functions for date work use Julian date. I have developed a very fast algo for converting gregorian date as a string, to julian date as a Long.
I too would use the way over Julian date.

But a further commen: There are different definitions in different countrys when the week counting ist starting in a year.
Not to mention that there are differences as to on which day a week is actually starting...  ;)

Ralf

czerny

  • Guest
Re: Week2Date
« Reply #7 on: October 10, 2014, 09:39:38 am »
Not to mention that there are differences as to on which day a week is actually starting...  ;)
Historically this is the sonday, but ISO seems the see the monday as the first day. Don't know if there are other variants.

Offline Bitbeisser

  • Global Moderator
  • Member
  • *****
  • Posts: 760
Re: Week2Date
« Reply #8 on: October 11, 2014, 12:45:20 am »
Not to mention that there are differences as to on which day a week is actually starting...  ;)
Historically this is the sonday, but ISO seems the see the monday as the first day. Don't know if there are other variants.
Yes, ISO 8601 defines Monday as the first day of the week, just the way as I was used to it back in Germany. Here in the USA it is commonly the Sunday that is regarded the first day of the week. Don't know how this is handled for example in Israel or in Islam oriented countries, which have the Friday (night) as the "resting and worship" day/time and likely the end of their week.

A safe bet would be to stick with ISO8601, but that certainly throws off a lot of folks here in the USofA...

Ralf