News:

Download Pelles C here: http://www.smorgasbordet.com/pellesc/

Main Menu

Week2Date

Started by TimoVJL, May 28, 2008, 09:07:25 PM

Previous topic - Next topic

TimoVJL

Is this reliable way to find date from week?
May the source be with you

JohnF

You need to increase the size of szBuf to at least 11 as the string is 10 chars in length.


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


John

MT

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.

Robert

Quote from: timovjl on May 28, 2008, 09:07:25 PM
Is this reliable way to find date from week?


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

Robert Wishlaw


Grincheux

For manipulating dates I use the sofa library : http://www.iausofa.org/

Here is an example for julian date to windows date :


  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

Quote from: MT on May 29, 2008, 08:55:07 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.

Bitbeisser

Quote from: czerny on October 09, 2014, 08:15:18 AM
Quote from: MT on May 29, 2008, 08:55:07 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

Quote from: Bitbeisser on October 09, 2014, 11:51:00 PM
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.

Bitbeisser

Quote from: czerny on October 10, 2014, 09:39:38 AM
Quote from: Bitbeisser on October 09, 2014, 11:51:00 PM
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