first weekday? Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
MoonKid
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 543
Joined: Wed Apr 05, 2006 9:39 am
Contact:

first weekday?

Post by MoonKid » Sun Sep 06, 2009 3:51 pm

I looked in wxDateTime but found no solution.

How do I know if the first weekday is a Sunday or a Monday?

User avatar
tierra
Site Admin
Site Admin
Posts: 1343
Joined: Sun Aug 29, 2004 7:14 pm
Location: Salt Lake City, Utah, USA
Contact:

Post by tierra » Tue Sep 08, 2009 4:20 pm

This is typically a locale setting, but wxWidgets' locale support is very limited, and doesn't actually provide any cross-platform approach for finding it.

This needs to be done with platform-specific code. You would need to look up how to do this yourself.

Muetdhiver
Super wx Problem Solver
Super wx Problem Solver
Posts: 323
Joined: Sun Jun 08, 2008 11:59 am
Location: Bordeaux, France

Post by Muetdhiver » Tue Sep 08, 2009 4:36 pm

Hello, hope it helps, i found this in cplusplus.com, but it is not related to wxWidgets. It is a plateforme undependent solution to get the day from the day (in number), the month and the year. C++ standard implies that the first day of the week is always Sunday....

Code: Select all

/* mktime example: weekday calculator */
#include <stdio.h>
#include <time.h>

int main ()
{
  time_t rawtime;
  struct tm * timeinfo;
  int year, month ,day;
  char * weekday[] = { "Sunday", "Monday",
                       "Tuesday", "Wednesday",
                       "Thursday", "Friday", "Saturday"};

  /* prompt user for date */
  printf ("Enter year: "); scanf ("%d",&year);
  printf ("Enter month: "); scanf ("%d",&month);
  printf ("Enter day: "); scanf ("%d",&day);

  /* get current timeinfo and modify it to the user's choice */
  time ( &rawtime );
  timeinfo = localtime ( &rawtime );
  timeinfo->tm_year = year - 1900;
  timeinfo->tm_mon = month - 1;
  timeinfo->tm_mday = day;

  /* call mktime: timeinfo->tm_wday will be set */
  mktime ( timeinfo );

  printf ("That day is a %s.\n", weekday[timeinfo->tm_wday]);
  
  return 0;
}
Output:
Enter year: 2000
Enter month: 5
Enter day: 20
That day is a Saturday.
OS: Ubuntu 11.10
Compiler: g++ 4.6.1 (Eclipse CDT Indigo)
wxWidgets: 2.9.3

User avatar
tierra
Site Admin
Site Admin
Posts: 1343
Joined: Sun Aug 29, 2004 7:14 pm
Location: Salt Lake City, Utah, USA
Contact:

Post by tierra » Wed Sep 09, 2009 4:10 pm

That's not what he's asking...

Muetdhiver
Super wx Problem Solver
Super wx Problem Solver
Posts: 323
Joined: Sun Jun 08, 2008 11:59 am
Location: Bordeaux, France

Post by Muetdhiver » Thu Sep 10, 2009 8:20 am

Sorry.
Trying to help (even to give a hint or an approach of the problem), is always a bad idea...
The next time I will close my mouth and will never try to answer questions....

Sorry for existing...
Hope "wx World domination" has what he wants....

Good bye.
OS: Ubuntu 11.10
Compiler: g++ 4.6.1 (Eclipse CDT Indigo)
wxWidgets: 2.9.3

Post Reply