Autor
Nachricht
Erhard Henkes
Mitglied
Benutzerprofil
Anmeldungsdatum: 25.04.2000
Beiträge: 11924
Erhard Henkes Mitglied
22:34:22 01.11.2011 Titel:
Funktion zur Berechnung des Wochentages
Zitieren
Bin gerade über diese Funktion gestolpert:
C/C++ Code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
static uint8_t calculateWeekday(uint16_t year, uint8_t month, int32_t day)
{
day += 6; // 1.1.2000 was a saturday
day += (year-2000)*365.25;
if (month > 11)
day+=334;
else if (month > 10)
day+=304;
else if (month > 9)
day+=273;
else if (month > 8)
day+=243;
else if (month > 7)
day+=212;
else if (month > 6)
day+=181;
else if (month > 5)
day+=151;
else if (month > 4)
day+=120;
else if (month > 3)
day+=90;
else if (month > 2)
day+=59;
else if (month > 1)
day+=31;
if (year%4 == 0 && (month < 2 || (month == 2 && day <= 28)))
{
day--;
}
return (day%7+1);
}
C/C++ Code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
static uint8_t calculateWeekday(uint16_t year, uint8_t month, int32_t day)
{
day += 6; // 1.1.2000 was a saturday
day += (year-2000)*365.25;
if (month > 11)
day+=334;
else if (month > 10)
day+=304;
else if (month > 9)
day+=273;
else if (month > 8)
day+=243;
else if (month > 7)
day+=212;
else if (month > 6)
day+=181;
else if (month > 5)
day+=151;
else if (month > 4)
day+=120;
else if (month > 3)
day+=90;
else if (month > 2)
day+=59;
else if (month > 1)
day+=31;
if (year%4 == 0 && (month < 2 || (month == 2 && day <= 28)))
{
day--;
}
return (day%7+1);
}
C/C++ Code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
static uint8_t calculateWeekday(uint16_t year, uint8_t month, int32_t day)
{
day += 6; // 1.1.2000 was a saturday
day += (year-2000)*365.25;
if (month > 11)
day+=334;
else if (month > 10)
day+=304;
else if (month > 9)
day+=273;
else if (month > 8)
day+=243;
else if (month > 7)
day+=212;
else if (month > 6)
day+=181;
else if (month > 5)
day+=151;
else if (month > 4)
day+=120;
else if (month > 3)
day+=90;
else if (month > 2)
day+=59;
else if (month > 1)
day+=31;
if (year%4 == 0 && (month < 2 || (month == 2 && day <= 28)))
{
day--;
}
return (day%7+1);
}
So richtig elegant sieht das noch nicht aus. Vielleicht hat jemand eine bessere Idee, wie man das kompakt lösen kann.
_________________ OS-Development-, C++, Win32-API-, MFC-, Chemie-, Robotik- und Flugsimulator-Tutorials
http://www.henkessoft.de/index.htm
dot
Mitglied
Benutzerprofil
Anmeldungsdatum: 20.05.2004
Beiträge: 3858
dot Mitglied
22:38:58 01.11.2011 Titel:
Zitieren
Erhard Henkes
Mitglied
Benutzerprofil
Anmeldungsdatum: 25.04.2000
Beiträge: 11924
Erhard Henkes Mitglied
22:45:25 01.11.2011 Titel:
Zitieren
Das sieht ja noch schrecklicher aus.
_________________ OS-Development-, C++, Win32-API-, MFC-, Chemie-, Robotik- und Flugsimulator-Tutorials
http://www.henkessoft.de/index.htm
dot
Mitglied
Benutzerprofil
Anmeldungsdatum: 20.05.2004
Beiträge: 3858
dot Mitglied
22:49:31 01.11.2011 Titel:
Zitieren
Ist aber korrekt (im Gegensatz zu obiger Funktion)
_________________ one point of view will never reveal the entire scene.
Erhard Henkes
Mitglied
Benutzerprofil
Anmeldungsdatum: 25.04.2000
Beiträge: 11924
Erhard Henkes Mitglied
22:56:39 01.11.2011 Titel:
Zitieren
Kannst du das nach C übersetzen mit obigen Parametern?
Hier im Forum gefunden:
C/C++ Code: 1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
dayofweek(int y, int m, int d) /* 0 = Sonntag */
/* 1 <= m <= 12, y > 1752 oder so */
{
static int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
y -= m < 3;
return (y + y/4 - y/100 + y/400 + t[m-1] + d) % 7;
}
C/C++ Code: 1 2 3 4 5 6 7 8 9
dayofweek(int y, int m, int d) /* 0 = Sonntag */
/* 1 <= m <= 12, y > 1752 oder so */
{
static int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
y -= m < 3;
return (y + y/4 - y/100 + y/400 + t[m-1] + d) % 7;
}
C/C++ Code: 1 2 3 4 5 6 7 8 9
dayofweek(int y, int m, int d) /* 0 = Sonntag */
/* 1 <= m <= 12, y > 1752 oder so */
{
static int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
y -= m < 3;
return (y + y/4 - y/100 + y/400 + t[m-1] + d) % 7;
}
Zitat: im Gegensatz zu obiger Funktion
Bisher wurde der Wochentag korrekt berechnet, aber ich traue der sache auch nicht.
_________________ OS-Development-, C++, Win32-API-, MFC-, Chemie-, Robotik- und Flugsimulator-Tutorials
http://www.henkessoft.de/index.htm
Zuletzt bearbeitet von Erhard Henkes am 23:02:54 01.11.2011, insgesamt 2-mal bearbeitet
dot
Mitglied
Benutzerprofil
Anmeldungsdatum: 20.05.2004
Beiträge: 3858
dot Mitglied
23:01:36 01.11.2011 Titel:
Zitieren
Erhard Henkes schrieb: Bisher wurde der Wochentag korrekt berechnet, aber ich traue der sache auch nicht.
Im Jahr 2100 stimmts nimmer, soweit ich das sehen kann, das ist nämlich kein Schaltjahr
_________________ one point of view will never reveal the entire scene.
Zuletzt bearbeitet von dot am 23:02:24 01.11.2011, insgesamt 2-mal bearbeitet
neuer_user
Mitglied
Benutzerprofil
Anmeldungsdatum: 28.12.2010
Beiträge: 210
neuer_user Mitglied
23:22:48 01.11.2011 Titel:
Zitieren
ich hab mal so angefangen:
EDIT: (angefangen heißt nicht fertig )
EDIT2: ist auch irgendwie falsch
Code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
static uint8_t calculateWeekday(uint16_t year, uint8_t month, int32_t day)
{
//1.1.2000 was Saturday
size_t day_ = 0;
int32_t diff_day = 1-day;
int32_t diff_year = 2000-year;
uint8_t schaltjahr[diff_year+1];
for(int i = 0;i < diff_year+1;i++)
{
if((2000+i)%4 == 0 && ((2000+i)%100 != 0 || (2000+i)%400 == 0))
schaltjahr[i] = 1;
else
schaltjahr[i] = 0;
}
if(diff_year > 0)
{
for(int i = 0;i < diff_year;i++)
{
day_ += 365+schaltjahr[i];
}
}
}
Code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
static uint8_t calculateWeekday(uint16_t year, uint8_t month, int32_t day)
{
//1.1.2000 was Saturday
size_t day_ = 0;
int32_t diff_day = 1-day;
int32_t diff_year = 2000-year;
uint8_t schaltjahr[diff_year+1];
for(int i = 0;i < diff_year+1;i++)
{
if((2000+i)%4 == 0 && ((2000+i)%100 != 0 || (2000+i)%400 == 0))
schaltjahr[i] = 1;
else
schaltjahr[i] = 0;
}
if(diff_year > 0)
{
for(int i = 0;i < diff_year;i++)
{
day_ += 365+schaltjahr[i];
}
}
}
Code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
static uint8_t calculateWeekday(uint16_t year, uint8_t month, int32_t day)
{
//1.1.2000 was Saturday
size_t day_ = 0;
int32_t diff_day = 1-day;
int32_t diff_year = 2000-year;
uint8_t schaltjahr[diff_year+1];
for(int i = 0;i < diff_year+1;i++)
{
if((2000+i)%4 == 0 && ((2000+i)%100 != 0 || (2000+i)%400 == 0))
schaltjahr[i] = 1;
else
schaltjahr[i] = 0;
}
if(diff_year > 0)
{
for(int i = 0;i < diff_year;i++)
{
day_ += 365+schaltjahr[i];
}
}
}
Zuletzt bearbeitet von neuer_user am 23:33:51 01.11.2011, insgesamt 2-mal bearbeitet
Erhard Henkes
Mitglied
Benutzerprofil
Anmeldungsdatum: 25.04.2000
Beiträge: 11924
Erhard Henkes Mitglied
23:30:30 01.11.2011 Titel:
Zitieren
da kommt noch kein Wochentag zurück ^^
_________________ OS-Development-, C++, Win32-API-, MFC-, Chemie-, Robotik- und Flugsimulator-Tutorials
http://www.henkessoft.de/index.htm
Erhard Henkes
Mitglied
Benutzerprofil
Anmeldungsdatum: 25.04.2000
Beiträge: 11924
Erhard Henkes Mitglied
23:36:55 01.11.2011 Titel:
Zitieren
Es ist interessant, wenn man höhere Jahreszahlen mit Emulatoren oder Windows testen will:
- qemu bricht sofort beim Start zusammen (ganz erbärmlich)
- Datum/Zeit von Win XP endet im Jahr 2099 (Unverschämtheit!)
- der GNU-Compiler gerät aus dem Takt, wenn man 2099 einstellt (merkwürdig)
_________________ OS-Development-, C++, Win32-API-, MFC-, Chemie-, Robotik- und Flugsimulator-Tutorials
http://www.henkessoft.de/index.htm
Zuletzt bearbeitet von Erhard Henkes am 23:56:45 01.11.2011, insgesamt 1-mal bearbeitet
neuer_user
Mitglied
Benutzerprofil
Anmeldungsdatum: 28.12.2010
Beiträge: 210
neuer_user Mitglied
23:47:31 01.11.2011 Titel:
Zitieren
Code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
static uint8_t calculateWeekday(uint16_t year, uint8_t month, int32_t day)
{
//1.1.2000 was Saturday
size_t day_ = 5;
int32_t diff_year = year-2000;
uint8_t schaltjahr[diff_year+1];
//calculate Schaltjahre
for(int i = 0;i < diff_year+1;i++)
{
if((2000+i)%4 == 0 && ((2000+i)%100 != 0 || (2000+i)%400 == 0))
schaltjahr[i] = 1;
else
schaltjahr[i] = 0;
}
//add days of diff. of years
if(diff_year > 0)
{
for(int i = 0;i < diff_year;i++)
{
day_ += 365+schaltjahr[i];
}
}
//Month
if(month > 1)
{
for(int i = 0;i < month-1;i++)
{
if(month-1+i == 2)
{
if(schaltjahr[year])
day_ += 29;
else
day_ += 28;
}
else
{
if((month-1+i)%2 == 1)
day_ += 31;
else
day_ += 30;
}
}
}
//add diff.day
day_ += day-1;
return day_%7;
}
Code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
static uint8_t calculateWeekday(uint16_t year, uint8_t month, int32_t day)
{
//1.1.2000 was Saturday
size_t day_ = 5;
int32_t diff_year = year-2000;
uint8_t schaltjahr[diff_year+1];
//calculate Schaltjahre
for(int i = 0;i < diff_year+1;i++)
{
if((2000+i)%4 == 0 && ((2000+i)%100 != 0 || (2000+i)%400 == 0))
schaltjahr[i] = 1;
else
schaltjahr[i] = 0;
}
//add days of diff. of years
if(diff_year > 0)
{
for(int i = 0;i < diff_year;i++)
{
day_ += 365+schaltjahr[i];
}
}
//Month
if(month > 1)
{
for(int i = 0;i < month-1;i++)
{
if(month-1+i == 2)
{
if(schaltjahr[year])
day_ += 29;
else
day_ += 28;
}
else
{
if((month-1+i)%2 == 1)
day_ += 31;
else
day_ += 30;
}
}
}
//add diff.day
day_ += day-1;
return day_%7;
}
Code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
static uint8_t calculateWeekday(uint16_t year, uint8_t month, int32_t day)
{
//1.1.2000 was Saturday
size_t day_ = 5;
int32_t diff_year = year-2000;
uint8_t schaltjahr[diff_year+1];
//calculate Schaltjahre
for(int i = 0;i < diff_year+1;i++)
{
if((2000+i)%4 == 0 && ((2000+i)%100 != 0 || (2000+i)%400 == 0))
schaltjahr[i] = 1;
else
schaltjahr[i] = 0;
}
//add days of diff. of years
if(diff_year > 0)
{
for(int i = 0;i < diff_year;i++)
{
day_ += 365+schaltjahr[i];
}
}
//Month
if(month > 1)
{
for(int i = 0;i < month-1;i++)
{
if(month-1+i == 2)
{
if(schaltjahr[year])
day_ += 29;
else
day_ += 28;
}
else
{
if((month-1+i)%2 == 1)
day_ += 31;
else
day_ += 30;
}
}
}
//add diff.day
day_ += day-1;
return day_%7;
}
Ich hab das noch nicht überprüft aber bei Montag sollte 0 rauskommen
Zuletzt bearbeitet von neuer_user am 23:49:29 01.11.2011, insgesamt 1-mal bearbeitet
Erhard Henkes
Mitglied
Benutzerprofil
Anmeldungsdatum: 25.04.2000
Beiträge: 11924
Erhard Henkes Mitglied
23:51:31 01.11.2011 Titel:
Zitieren
Zitat: Im Jahr 2100 stimmts nimmer, soweit ich das sehen kann, das ist nämlich kein Schaltjahr
Das lässt sich leicht ausbügeln:
C/C++ Code: if ((year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0)) && (month < 2 || (month == 2 && day <= 28)))
{
day--;
}
C/C++ Code: if ((year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0)) && (month < 2 || (month == 2 && day <= 28)))
{
day--;
}
C/C++ Code: if ((year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0)) && (month < 2 || (month == 2 && day <= 28)))
{
day--;
}
_________________ OS-Development-, C++, Win32-API-, MFC-, Chemie-, Robotik- und Flugsimulator-Tutorials
http://www.henkessoft.de/index.htm
dot
Mitglied
Benutzerprofil
Anmeldungsdatum: 20.05.2004
Beiträge: 3858
dot Mitglied
23:54:51 01.11.2011 Titel:
Zitieren
Ja, aber du hast doch sowieso schon eine fertige Implementierung der Wochentagsformel gefunden!? Ich würd die benutzen^^
_________________ one point of view will never reveal the entire scene.
neuer_user
Mitglied
Benutzerprofil
Anmeldungsdatum: 28.12.2010
Beiträge: 210
neuer_user Mitglied
23:59:49 01.11.2011 Titel:
Zitieren
jetzt hab ich mir mühe gemacht
Erhard Henkes
Mitglied
Benutzerprofil
Anmeldungsdatum: 25.04.2000
Beiträge: 11924
Erhard Henkes Mitglied
00:03:09 02.11.2011 Titel:
Zitieren
Wenn man unsere Formel optisch etwas pusht, die korrekte isLeapyear(...) einsetzt und die korrekte Zahl der Tage pro Jahr verwendet, dann hat das auch etwas Eingängliches.
C/C++ Code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
uint8_t calculateWeekday(uint16_t year, uint8_t month, int32_t day)
{
day += 6; // 1.1.2000 was a saturday
day += (year-2000) * 365.24219;
if (month > 11) day+=334;
else if (month > 10) day+=304;
else if (month > 9) day+=273;
else if (month > 8) day+=243;
else if (month > 7) day+=212;
else if (month > 6) day+=181;
else if (month > 5) day+=151;
else if (month > 4) day+=120;
else if (month > 3) day+=90;
else if (month > 2) day+=59;
else if (month > 1) day+=31;
if ((year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0)) && (month < 2 || (month == 2 && day <= 28)))
{
day--;
}
return ( day % 7 + 1 );
}
C/C++ Code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
uint8_t calculateWeekday(uint16_t year, uint8_t month, int32_t day)
{
day += 6; // 1.1.2000 was a saturday
day += (year-2000) * 365.24219;
if (month > 11) day+=334;
else if (month > 10) day+=304;
else if (month > 9) day+=273;
else if (month > 8) day+=243;
else if (month > 7) day+=212;
else if (month > 6) day+=181;
else if (month > 5) day+=151;
else if (month > 4) day+=120;
else if (month > 3) day+=90;
else if (month > 2) day+=59;
else if (month > 1) day+=31;
if ((year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0)) && (month < 2 || (month == 2 && day <= 28)))
{
day--;
}
return ( day % 7 + 1 );
}
C/C++ Code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
uint8_t calculateWeekday(uint16_t year, uint8_t month, int32_t day)
{
day += 6; // 1.1.2000 was a saturday
day += (year-2000) * 365.24219;
if (month > 11) day+=334;
else if (month > 10) day+=304;
else if (month > 9) day+=273;
else if (month > 8) day+=243;
else if (month > 7) day+=212;
else if (month > 6) day+=181;
else if (month > 5) day+=151;
else if (month > 4) day+=120;
else if (month > 3) day+=90;
else if (month > 2) day+=59;
else if (month > 1) day+=31;
if ((year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0)) && (month < 2 || (month == 2 && day <= 28)))
{
day--;
}
return ( day % 7 + 1 );
}
@dot: Diese perfekte Formel von Gauß versteht man nicht leicht. Es gibt übrigens noch mehr Systeme zur Berechnung.
@neuer_user: Vielleicht nehmen wir auch deine Formel. Noch ist alles offen.
_________________ OS-Development-, C++, Win32-API-, MFC-, Chemie-, Robotik- und Flugsimulator-Tutorials
http://www.henkessoft.de/index.htm
Zuletzt bearbeitet von Erhard Henkes am 00:06:15 02.11.2011, insgesamt 2-mal bearbeitet
dot
Mitglied
Benutzerprofil
Anmeldungsdatum: 20.05.2004
Beiträge: 3858
dot Mitglied
00:06:19 02.11.2011 Titel:
Zitieren
Erhard Henkes schrieb: Diese perfekte Formel versteht man nicht. Es gibt übrigens noch mehr Systeme zur Berechnung.
Was genau versteht man daran nicht, im Wikipedia-Artikel ist doch eine komplette Herleitung!?
_________________ one point of view will never reveal the entire scene.
Erhard Henkes
Mitglied
Benutzerprofil
Anmeldungsdatum: 25.04.2000
Beiträge: 11924
Erhard Henkes Mitglied
00:09:20 02.11.2011 Titel:
Zitieren
Welche Formel wir verwenden werden, entscheidet letztendlich das Team. Der Thread ist noch zu frisch. Danke auf jeden Fall für den Tipp.
_________________ OS-Development-, C++, Win32-API-, MFC-, Chemie-, Robotik- und Flugsimulator-Tutorials
http://www.henkessoft.de/index.htm
neuer_user
Mitglied
Benutzerprofil
Anmeldungsdatum: 28.12.2010
Beiträge: 210
neuer_user Mitglied
00:10:53 02.11.2011 Titel:
Zitieren
Meine Version ist länger.
Mich stört diese Kommaangabe
Code: (year-2000) * 365.24219 ;
Code: (year-2000) * 365.24219 ;
Code: (year-2000) * 365.24219 ;
Erhard Henkes
Mitglied
Benutzerprofil
Anmeldungsdatum: 25.04.2000
Beiträge: 11924
Erhard Henkes Mitglied
00:17:18 02.11.2011 Titel:
Zitieren
Ja, das stimmt. Man könnte vielleicht auch 146097.0 / 400.0 verwenden.
Wenn wir eine kürzere Formel für month ==> day finden, ist unsere Formel viel schöner. Sie muss ja nur ab 2000 und nicht vorher gelten.
- isLeapyear(...) könnte man auslagern
- die Zahlen der Tage für einen abgeschlossenen Monat könnte man in ein Array packen
_________________ OS-Development-, C++, Win32-API-, MFC-, Chemie-, Robotik- und Flugsimulator-Tutorials
http://www.henkessoft.de/index.htm
Zuletzt bearbeitet von Erhard Henkes am 00:22:10 02.11.2011, insgesamt 2-mal bearbeitet
dot
Mitglied
Benutzerprofil
Anmeldungsdatum: 20.05.2004
Beiträge: 3858
dot Mitglied
00:19:44 02.11.2011 Titel:
Zitieren
Erhard Henkes schrieb: Sie muss ja nur ab 2000 und nicht vorher gelten.
So haben schon viele gedacht...
_________________ one point of view will never reveal the entire scene.
Erhard Henkes
Mitglied
Benutzerprofil
Anmeldungsdatum: 25.04.2000
Beiträge: 11924
Erhard Henkes Mitglied
00:37:28 02.11.2011 Titel:
Zitieren
C/C++ Code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
static uint16_t days[12] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
static bool isLeapyear(uint16_t year)
{
return (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0));
}
static uint8_t calculateWeekday(uint16_t year, uint8_t month, int32_t day)
{
day += 6; // 1.1.2000 was a saturday
day += (year-2000) * 365.24219 + days[month-1];
if (isLeapyear(year) && (month < 2 || (month == 2 && day <= 28)))
{
day--;
}
return ( day % 7 + 1 );
}
C/C++ Code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
static uint16_t days[12] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
static bool isLeapyear(uint16_t year)
{
return (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0));
}
static uint8_t calculateWeekday(uint16_t year, uint8_t month, int32_t day)
{
day += 6; // 1.1.2000 was a saturday
day += (year-2000) * 365.24219 + days[month-1];
if (isLeapyear(year) && (month < 2 || (month == 2 && day <= 28)))
{
day--;
}
return ( day % 7 + 1 );
}
C/C++ Code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
static uint16_t days[12] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
static bool isLeapyear(uint16_t year)
{
return (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0));
}
static uint8_t calculateWeekday(uint16_t year, uint8_t month, int32_t day)
{
day += 6; // 1.1.2000 was a saturday
day += (year-2000) * 365.24219 + days[month-1];
if (isLeapyear(year) && (month < 2 || (month == 2 && day <= 28)))
{
day--;
}
return ( day % 7 + 1 );
}
So sieht das doch schon richtig fein aus.
Verflixt! beim 31.12.2099 kommt Mittwoch raus, ist aber Donnerstag. Die genaue Kommazahl ist offenbar nicht hilfreich. Nein, daran liegt es nicht.
_________________ OS-Development-, C++, Win32-API-, MFC-, Chemie-, Robotik- und Flugsimulator-Tutorials
http://www.henkessoft.de/index.htm
Zuletzt bearbeitet von Erhard Henkes am 00:43:54 02.11.2011, insgesamt 2-mal bearbeitet
volkard
Moderator
Benutzerprofil
Anmeldungsdatum: 06.04.2000
Beiträge: 24356
volkard Moderator
00:54:37 02.11.2011 Titel:
Zitieren
Erhard Henkes schrieb: Verflixt! beim 31.12.2099 kommt Mittwoch raus, ist aber Donnerstag. Die genaue Kommazahl ist offenbar nicht hilfreich. Nein, daran liegt es nicht.
Woher kommt die 365.24219?
_________________http://www.venganza.info/
plonk fürs Forum v1.02
Erhard Henkes
Mitglied
Benutzerprofil
Anmeldungsdatum: 25.04.2000
Beiträge: 11924
Erhard Henkes Mitglied
01:01:45 02.11.2011 Titel:
Zitieren
volkard
Moderator
Benutzerprofil
Anmeldungsdatum: 06.04.2000
Beiträge: 24356
volkard Moderator
01:04:43 02.11.2011 Titel:
Zitieren
Sag mir nicht, daß Du da einfach das tropische Jahr aus dem Lexikon kopiert hast. Das darf ja nicht wahr sein.
Jedes Jahr hat 365 Tage. 365
Jedes vierte hat einen Tag mehr. +0.25
Jedes hundertste einen Tag weniger. -0.01
Jedes vierhundertste einen mehr. +0.0025
sind für mich 365.2425
Erhard schrieb: 146097.0 / 400.0
Ach nööö!
_________________http://www.venganza.info/
plonk fürs Forum v1.02
Erhard Henkes
Mitglied
Benutzerprofil
Anmeldungsdatum: 25.04.2000
Beiträge: 11924
Erhard Henkes Mitglied
01:11:12 02.11.2011 Titel:
Zitieren
Ich denke, es liegt daran, dass ich bei dem falsch eingestellten Datum kompiliert habe. Nach rebuild in 2011 klappt es wieder.
Die Zahl dort ist nicht entscheidend, ob 365.2419, 365.2425 oder 365.25
Wir nehmen aber Volkard's Zahl, weil die nachvollziehbar ist (wenn sie auch nicht stimmt):
C/C++ Code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
static uint16_t days[12] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
static bool isLeapyear(uint16_t year)
{
return (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0));
}
static uint8_t calculateWeekday(uint16_t year, uint8_t month, int32_t day)
{
day += 6; // 1.1.2000 was a saturday
day += (year-2000) * 365.2425 + days[month-1];
if (isLeapyear(year) && (month < 2 || (month == 2 && day <= 28)))
{
day--;
}
return ( day % 7 + 1 );
}
C/C++ Code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
static uint16_t days[12] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
static bool isLeapyear(uint16_t year)
{
return (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0));
}
static uint8_t calculateWeekday(uint16_t year, uint8_t month, int32_t day)
{
day += 6; // 1.1.2000 was a saturday
day += (year-2000) * 365.2425 + days[month-1];
if (isLeapyear(year) && (month < 2 || (month == 2 && day <= 28)))
{
day--;
}
return ( day % 7 + 1 );
}
C/C++ Code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
static uint16_t days[12] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
static bool isLeapyear(uint16_t year)
{
return (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0));
}
static uint8_t calculateWeekday(uint16_t year, uint8_t month, int32_t day)
{
day += 6; // 1.1.2000 was a saturday
day += (year-2000) * 365.2425 + days[month-1];
if (isLeapyear(year) && (month < 2 || (month == 2 && day <= 28)))
{
day--;
}
return ( day % 7 + 1 );
}
31.12.2099 ist ein Donnerstag! yep.
_________________ OS-Development-, C++, Win32-API-, MFC-, Chemie-, Robotik- und Flugsimulator-Tutorials
http://www.henkessoft.de/index.htm
Zuletzt bearbeitet von Erhard Henkes am 01:16:25 02.11.2011, insgesamt 3-mal bearbeitet
volkard
Moderator
Benutzerprofil
Anmeldungsdatum: 06.04.2000
Beiträge: 24356
volkard Moderator
01:15:56 02.11.2011 Titel:
Zitieren
Erhard Henkes
Mitglied
Benutzerprofil
Anmeldungsdatum: 25.04.2000
Beiträge: 11924
Erhard Henkes Mitglied
01:20:44 02.11.2011 Titel:
Zitieren
Zitat: Ich weiß schon, weshalb ich bei Dir nicht mitspiele.
Eigentlich schade. Mit dir als Math Geek könnte das richtig gut werden, aber wir schaffen das auch so. Ist sowieso mehr Praxis als Theorie.
Diese Wochentag-Formel ist ursprünglich nicht von mir, ich wollte sie nur verfeinern oder zumindest korrekt machen.
Entscheidend ist, dass der korrekte Tag heraus kommt, und das klappt nun.
_________________ OS-Development-, C++, Win32-API-, MFC-, Chemie-, Robotik- und Flugsimulator-Tutorials
http://www.henkessoft.de/index.htm
volkard
Moderator
Benutzerprofil
Anmeldungsdatum: 06.04.2000
Beiträge: 24356
volkard Moderator
01:26:29 02.11.2011 Titel:
Zitieren
Erhard Henkes schrieb: Wir nehmen aber Volkard's Zahl, weil die nachvollziehbar ist (wenn sie auch nicht stimmt)
Sie stimmt natürlich, weil der gregorianische Kalender abgebildet werden soll und nichts anderes.
Naja, Du hattest die richtige Zahl schon in der Hand: 146097.0/400.0=365.2425
_________________http://www.venganza.info/
plonk fürs Forum v1.02
Erhard Henkes
Mitglied
Benutzerprofil
Anmeldungsdatum: 25.04.2000
Beiträge: 11924
Erhard Henkes Mitglied
01:31:41 02.11.2011 Titel:
Zitieren
OK, dann nehmen wir den Bruch. Dann ist neuer_user auch zufrieden.
C/C++ Code: 1 2 3 4 5 6 7 8 9 10 11 12
1 2 3 4 5 6 7 8 9 10 11 12
static uint8_t calculateWeekday(uint16_t year, uint8_t month, int32_t day)
{
day += 6; // 1.1.2000 was a saturday
day += (year-2000) * 146097.0/400.0 + days[month-1];
if (isLeapyear(year) && (month < 2 || (month == 2 && day <= 28)))
{
day--;
}
return ( day % 7 + 1 );
}
C/C++ Code: 1 2 3 4 5 6 7 8 9 10 11 12
static uint8_t calculateWeekday(uint16_t year, uint8_t month, int32_t day)
{
day += 6; // 1.1.2000 was a saturday
day += (year-2000) * 146097.0/400.0 + days[month-1];
if (isLeapyear(year) && (month < 2 || (month == 2 && day <= 28)))
{
day--;
}
return ( day % 7 + 1 );
}
C/C++ Code: 1 2 3 4 5 6 7 8 9 10 11 12
static uint8_t calculateWeekday(uint16_t year, uint8_t month, int32_t day)
{
day += 6; // 1.1.2000 was a saturday
day += (year-2000) * 146097.0/400.0 + days[month-1];
if (isLeapyear(year) && (month < 2 || (month == 2 && day <= 28)))
{
day--;
}
return ( day % 7 + 1 );
}
_________________ OS-Development-, C++, Win32-API-, MFC-, Chemie-, Robotik- und Flugsimulator-Tutorials
http://www.henkessoft.de/index.htm
Erhard Henkes
Mitglied
Benutzerprofil
Anmeldungsdatum: 25.04.2000
Beiträge: 11924
Erhard Henkes Mitglied
01:36:56 02.11.2011 Titel:
Zitieren
Ich finde, dass sich diese Formel nun sehen lassen kann. Wenn man im Datum zurück geht, kann man diese nun sicher auch ab 1980 einsetzen.
_________________ OS-Development-, C++, Win32-API-, MFC-, Chemie-, Robotik- und Flugsimulator-Tutorials
http://www.henkessoft.de/index.htm
Zuletzt bearbeitet von Erhard Henkes am 01:41:23 02.11.2011, insgesamt 1-mal bearbeitet
volkard
Moderator
Benutzerprofil
Anmeldungsdatum: 06.04.2000
Beiträge: 24356
volkard Moderator
01:42:28 02.11.2011 Titel:
Zitieren
Da sich der Kalender alle 400 Jahre wiederholt, kannste statt j-2000 auch j-1600 schreiben. Oder j-0.
_________________http://www.venganza.info/
plonk fürs Forum v1.02
Zuletzt bearbeitet von volkard am 02:12:34 02.11.2011, insgesamt 2-mal bearbeitet
Erhard Henkes
Mitglied
Benutzerprofil
Anmeldungsdatum: 25.04.2000
Beiträge: 11924
Erhard Henkes Mitglied
01:49:42 02.11.2011 Titel:
Zitieren
Danke für den Hinweis. Mit meinem Win XP SP3 kann ich nur von 1.1.1980 bis 31.12.2099 experimentell mit VBox testen. Qemu macht die Grätsche (schwach gebastelt), und GNU GCC versagt beim Compilieren, wenn die Zeit aus den Fugen ist.
Habe gerade bei meinem Sohn Win 7 gecheckt, selber Murks: 1980 - 2099.
_________________ OS-Development-, C++, Win32-API-, MFC-, Chemie-, Robotik- und Flugsimulator-Tutorials
http://www.henkessoft.de/index.htm
Zuletzt bearbeitet von Erhard Henkes am 02:05:19 02.11.2011, insgesamt 1-mal bearbeitet
Erhard Henkes
Mitglied
Benutzerprofil
Anmeldungsdatum: 25.04.2000
Beiträge: 11924
Erhard Henkes Mitglied
01:58:43 02.11.2011 Titel:
Zitieren
http://www.thkoehler.de/midnightblue/m_kal.htm
Volkard hat Recht. 1.1.1600 ist ein Samstag.
@Volkard: 0 ist allerdings nicht brauchbar wegen dem 15.10.1582 (Beginn der gregorianischen Zeitrechnung). Da hat der gute Gregor 10 Tage ausgelassen (4.10. ==> 15.10.1582 ).
_________________ OS-Development-, C++, Win32-API-, MFC-, Chemie-, Robotik- und Flugsimulator-Tutorials
http://www.henkessoft.de/index.htm
Zuletzt bearbeitet von Erhard Henkes am 02:05:03 02.11.2011, insgesamt 2-mal bearbeitet
volkard
Moderator
Benutzerprofil
Anmeldungsdatum: 06.04.2000
Beiträge: 24356
volkard Moderator
02:07:30 02.11.2011 Titel:
Zitieren
Erhard Henkes schrieb: @Volkard: 0 ist allerdings nicht brauchbar wegen dem 15.10.1582 (Beginn der gregorianischen Zeitrechnung). Da hat der gute Gregor 10 Tage ausgelassen (4.10. ==> 15.10.1582 ).
Doch.
Es geht immernoch nur darum, den gregorianischen Kalender abzubilden. Für Eingaben nach dem 15.10.1582 klappt doch alles mit j-0.
_________________http://www.venganza.info/
plonk fürs Forum v1.02
Erhard Henkes
Mitglied
Benutzerprofil
Anmeldungsdatum: 25.04.2000
Beiträge: 11924
Erhard Henkes Mitglied
02:11:17 02.11.2011 Titel:
Zitieren
Hast Recht.
C/C++ Code: // Gregorian calender started 15th October 1582
static uint8_t calculateWeekday(uint16_t year, uint8_t month, int32_t day)
{
day += 6; // 1.1.1600 was a saturday
day += (year/*-1600*/ ) * 146097.0/400.0 + days[month-1];
C/C++ Code: // Gregorian calender started 15th October 1582
static uint8_t calculateWeekday(uint16_t year, uint8_t month, int32_t day)
{
day += 6; // 1.1.1600 was a saturday
day += (year/*-1600*/ ) * 146097.0/400.0 + days[month-1];
C/C++ Code: // Gregorian calender started 15th October 1582
static uint8_t calculateWeekday(uint16_t year, uint8_t month, int32_t day)
{
day += 6; // 1.1.1600 was a saturday
day += (year/*-1600*/ ) * 146097.0/400.0 + days[month-1];
So könnte man das evtl. machen, damit Theorie und Praxis zu ihrem Recht kommen.
_________________ OS-Development-, C++, Win32-API-, MFC-, Chemie-, Robotik- und Flugsimulator-Tutorials
http://www.henkessoft.de/index.htm
volkard
Moderator
Benutzerprofil
Anmeldungsdatum: 06.04.2000
Beiträge: 24356
volkard Moderator
02:13:34 02.11.2011 Titel:
Zitieren
Sogar
C/C++ Code: day += 6; // 1.1.0 was a saturday
C/C++ Code: day += 6; // 1.1.0 was a saturday
C/C++ Code: day += 6; // 1.1.0 was a saturday
wobei hier das "was" nicht "war", sondern "wäre" heißt, wenn es da den greg Kalender schon gegeben hätte und wenn es ein Jahr 0 gäbe.
Ich würde einfach alle gregorianisch lassen. Daten vorher werden halt falsch berechnet. Muß ins User-Handbuch.
_________________http://www.venganza.info/
plonk fürs Forum v1.02
Erhard Henkes
Mitglied
Benutzerprofil
Anmeldungsdatum: 25.04.2000
Beiträge: 11924
Erhard Henkes Mitglied
02:20:17 02.11.2011 Titel:
Zitieren
Jetzt muss ich dich in die Schranken weisen.
Das ist ja ein Denken wie bei "1984".
So machen wir es, damit wir die Zeit vor 2000 auch korrekt abdecken:
C/C++ Code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
static uint16_t days[12] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
static bool isLeapyear(uint16_t year)
{
return (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0));
}
// Gregorian calender started 15th October 1582
static uint8_t calculateWeekday(uint16_t year, uint8_t month, int32_t day)
{
day += 6; // 1.1.1600 was a saturday
day += (year/*-1600*/ ) * 146097.0/400.0 + days[month-1];
if (isLeapyear(year) && (month < 2 || (month == 2 && day <= 28)))
{
day--;
}
return ( day % 7 + 1 );
}
C/C++ Code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
static uint16_t days[12] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
static bool isLeapyear(uint16_t year)
{
return (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0));
}
// Gregorian calender started 15th October 1582
static uint8_t calculateWeekday(uint16_t year, uint8_t month, int32_t day)
{
day += 6; // 1.1.1600 was a saturday
day += (year/*-1600*/ ) * 146097.0/400.0 + days[month-1];
if (isLeapyear(year) && (month < 2 || (month == 2 && day <= 28)))
{
day--;
}
return ( day % 7 + 1 );
}
C/C++ Code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
static uint16_t days[12] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
static bool isLeapyear(uint16_t year)
{
return (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0));
}
// Gregorian calender started 15th October 1582
static uint8_t calculateWeekday(uint16_t year, uint8_t month, int32_t day)
{
day += 6; // 1.1.1600 was a saturday
day += (year/*-1600*/ ) * 146097.0/400.0 + days[month-1];
if (isLeapyear(year) && (month < 2 || (month == 2 && day <= 28)))
{
day--;
}
return ( day % 7 + 1 );
}
_________________ OS-Development-, C++, Win32-API-, MFC-, Chemie-, Robotik- und Flugsimulator-Tutorials
http://www.henkessoft.de/index.htm
volkard
Moderator
Benutzerprofil
Anmeldungsdatum: 06.04.2000
Beiträge: 24356
volkard Moderator
02:23:15 02.11.2011 Titel:
Zitieren
Aber ich glaube, es wird doch
C/C++ Code: static uint8_t calculateWeekday(uint16_t year, uint8_t month, int8_t day){
return (calculateDaysFromDate(year,month,day)+3)%7;
}
C/C++ Code: static uint8_t calculateWeekday(uint16_t year, uint8_t month, int8_t day){
return (calculateDaysFromDate(year,month,day)+3)%7;
}
C/C++ Code: static uint8_t calculateWeekday(uint16_t year, uint8_t month, int8_t day){
return (calculateDaysFromDate(year,month,day)+3)%7;
}
Man will ja auch die Differenz zwischen zwei Daten ausrechnen können. DIe +3 ist geraten. Das %7, damit Tage bei 0 beginnen wie rechtschaffene enums und Arrayindizes.
_________________http://www.venganza.info/
plonk fürs Forum v1.02
Erhard Henkes
Mitglied
Benutzerprofil
Anmeldungsdatum: 25.04.2000
Beiträge: 11924
Erhard Henkes Mitglied
02:25:20 02.11.2011 Titel:
Zitieren
volkard
Moderator
Benutzerprofil
Anmeldungsdatum: 06.04.2000
Beiträge: 24356
volkard Moderator
02:38:57 02.11.2011 Titel:
Zitieren
Erhard Henkes
Mitglied
Benutzerprofil
Anmeldungsdatum: 25.04.2000
Beiträge: 11924
Erhard Henkes Mitglied
02:55:07 02.11.2011 Titel:
Zitieren
Erhard Henkes
Mitglied
Benutzerprofil
Anmeldungsdatum: 25.04.2000
Beiträge: 11924
Erhard Henkes Mitglied
03:15:42 02.11.2011 Titel:
Zitieren
... und nun für Fanatiker:
http://de.wikipedia.org/wiki/Schaltsekunde
Zitat: Die Anweisung, eine Schaltsekunde einzufügen, wird immer dann gegeben, wenn für die nächste Zukunft zu erwarten ist, dass der Unterschied zwischen UTC und UT1 über 0,9 Sekunden anwächst. Nach 23:59:59 UTC der genannten Tage wird eine zusätzliche Sekunde bei 23:59:60 eingefügt, bevor die Uhr auf 00:00:00 des Folgetages vorrückt. Das bedeutet, dass der Tag mit der Schaltsekunde aus 86401 Atomsekunden, statt der üblichen 86400, besteht.
http://de.wikipedia.org/wiki/Erdrotation
Zitat: Die durchschnittliche Dauer einer Umdrehung bezüglich des als ruhend angenommenen kosmischen Hintergrundes – der mittlere siderische Tag – beträgt 23 h 56 min 4,10 s ... Die Zeitspanne, die die Erde braucht, um nach einer Umdrehung wieder dieselbe Stellung bezüglich des Frühlingspunktes einzunehmen, ist ein Sterntag. Deshalb dauert ein Sterntag nur 23 h 56 min 4,09 s. Die Präzession der Erde hingegen ist der Grund dafür, dass ein siderischer Tag etwa 8 Millisekunden länger ist als ein Sterntag.
_________________ OS-Development-, C++, Win32-API-, MFC-, Chemie-, Robotik- und Flugsimulator-Tutorials
http://www.henkessoft.de/index.htm
Mr X
Mitglied
Benutzerprofil
Anmeldungsdatum: 18.09.2007
Beiträge: 1076
Mr X Mitglied
10:19:56 02.11.2011 Titel:
Zitieren
Erhard Henkes schrieb: Jetzt muss ich dich in die Schranken weisen.
Das ist ja ein Denken wie bei "1984".
So machen wir es, damit wir die Zeit vor 2000 auch korrekt abdecken:
C/C++ Code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
static uint16_t days[12] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
static bool isLeapyear(uint16_t year)
{
return (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0));
}
// Gregorian calender started 15th October 1582
static uint8_t calculateWeekday(uint16_t year, uint8_t month, int32_t day)
{
day += 6; // 1.1.1600 was a saturday
day += (year/*-1600*/ ) * 146097.0/400.0 + days[month-1];
if (isLeapyear(year) && (month < 2 || (month == 2 && day <= 28)))
{
day--;
}
return ( day % 7 + 1 );
}
C/C++ Code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
static uint16_t days[12] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
static bool isLeapyear(uint16_t year)
{
return (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0));
}
// Gregorian calender started 15th October 1582
static uint8_t calculateWeekday(uint16_t year, uint8_t month, int32_t day)
{
day += 6; // 1.1.1600 was a saturday
day += (year/*-1600*/ ) * 146097.0/400.0 + days[month-1];
if (isLeapyear(year) && (month < 2 || (month == 2 && day <= 28)))
{
day--;
}
return ( day % 7 + 1 );
}
C/C++ Code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
static uint16_t days[12] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
static bool isLeapyear(uint16_t year)
{
return (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0));
}
// Gregorian calender started 15th October 1582
static uint8_t calculateWeekday(uint16_t year, uint8_t month, int32_t day)
{
day += 6; // 1.1.1600 was a saturday
day += (year/*-1600*/ ) * 146097.0/400.0 + days[month-1];
if (isLeapyear(year) && (month < 2 || (month == 2 && day <= 28)))
{
day--;
}
return ( day % 7 + 1 );
}
Die Fließkommaoperationen könnte man sich doch bei der Variante sparen, oder?
volkard
Moderator
Benutzerprofil
Anmeldungsdatum: 06.04.2000
Beiträge: 24356
volkard Moderator
10:32:18 02.11.2011 Titel:
Zitieren
Mr X schrieb: Die Fließkommaoperationen könnte man sich doch bei der Variante sparen, oder?
Sagen wir mal, wir wollen nur die Division durch 100 bezahlen. Die anderen sind dann nur /4 und sehr billig.
jhd=jahr/100;//bezahlt
rest=jahr%100;//gibt es kostenlos dazu
Jedes Jahr hat 365 Tage. tage=jahr*365;
Jedes vierte Jahr hat einen mehr. tage+=jahr/4;
Jedes hundertste hat einen weniger. tage-=jhd;
Jedes vierhundertste hat einen mehr. tage+=jhd/4.
Für die Schaltjahresberechnung haben wir schon zwei Divisionen bezahlt. Die könnte man wohl einsparen, wenn man sich die Variablen jhd und rest teilt; es bleibt nur noch eine Division übrig, die man insgesamt bezahlt. Und die wird zu einer Multiplikation, weil der Divisor compilezeitkonstant ist.
_________________http://www.venganza.info/
plonk fürs Forum v1.02
Shiba
Mitglied
Benutzerprofil
Anmeldungsdatum: 26.09.2002
Beiträge: 199
Shiba Mitglied
14:19:27 02.11.2011 Titel:
[OT] @E. Henkes
Zitieren
Auf Deiner Webseite hat Du eine Unterseite zur Chemie.
Meine Anmerkung zum 1. Absatz "Physik liefert die Elementarteilchen für die Chemie":
Nein, so kann man das nicht sehen, sondern:
Chemie ist die Physik der ersten Elektronenschale
(Bitte nicht nach Orbitalen fragen )
Zu Deinem Datumsproblem, empfehl ich Dir:
http://manfred.wilzeck.de/Datum_berechnen.html
Zuletzt bearbeitet von Shiba am 14:25:49 02.11.2011, insgesamt 1-mal bearbeitet
Erhard Henkes
Mitglied
Benutzerprofil
Anmeldungsdatum: 25.04.2000
Beiträge: 11924
Erhard Henkes Mitglied
00:49:34 03.11.2011 Titel:
Zitieren
Zitat: Chemie ist die Physik der ersten Elektronenschale
Schau dir mal Elektronen in inneren d-Schalen an bei Übergangsmetallkomplexen (Ligandenfeldtheorie), dann siehst du, dass deine Aussage nicht korrekt ist.
... und ich dachte immer meine Homepage wäre schwierig lesbar. Das ist echt der Hammer. Die muss gut sein.
Übrigens haben wir kein Problem, unsere Funktion arbeitet korrekt. Das Hauptproblem ist noch, dass sie zu oft aufgerufen wird. Das werden wir ändern. Wenn diese später einmal pro Tag angesprochen wird und nicht jede Sekunde, benötigen wir da keine ausgefeilte Performance-Optimierung.
_________________ OS-Development-, C++, Win32-API-, MFC-, Chemie-, Robotik- und Flugsimulator-Tutorials
http://www.henkessoft.de/index.htm
Zuletzt bearbeitet von Erhard Henkes am 00:50:19 03.11.2011, insgesamt 1-mal bearbeitet
neuer_user
Mitglied
Benutzerprofil
Anmeldungsdatum: 28.12.2010
Beiträge: 210
neuer_user Mitglied
12:58:57 03.11.2011 Titel:
Zitieren
Zitat: Zitat: Chemie ist die Physik der ersten Elektronenschale
Schau dir mal Elektronen in inneren d-Schalen an bei Übergangsmetallkomplexen (Ligandenfeldtheorie), dann siehst du, dass deine Aussage nicht korrekt ist.
in der schule wird aber immer gesagt
Zitat: Chemie ist die Physik der ersten Elektronenschale
Shiba
Mitglied
Benutzerprofil
Anmeldungsdatum: 26.09.2002
Beiträge: 199
Shiba Mitglied
16:46:51 03.11.2011 Titel:
Zitieren
Physiker sehen das im Allgemeinen auch so.
Besonders Feststoffphysiker.
Aber Physiker pflegen auch ein spezielles Verhältnis zu Chemikern.
Zuletzt bearbeitet von Shiba am 16:48:22 03.11.2011, insgesamt 1-mal bearbeitet
Erhard Henkes
Mitglied
Benutzerprofil
Anmeldungsdatum: 25.04.2000
Beiträge: 11924
Erhard Henkes Mitglied
20:46:48 03.11.2011 Titel:
Zitieren
Zitat: in der schule wird aber immer gesagt
Da reden Lehrer, die nehmen es nicht so genau und sind zumeist mehrere Jahrzehnte hinter dem aktuellen Wissensstand zurück.
_________________ OS-Development-, C++, Win32-API-, MFC-, Chemie-, Robotik- und Flugsimulator-Tutorials
http://www.henkessoft.de/index.htm
neuer_user
Mitglied
Benutzerprofil
Anmeldungsdatum: 28.12.2010
Beiträge: 210
neuer_user Mitglied
21:15:28 03.11.2011 Titel:
Zitieren
einer von denen glaube ich nicht
Erhard Henkes
Mitglied
Benutzerprofil
Anmeldungsdatum: 25.04.2000
Beiträge: 11924
Erhard Henkes Mitglied
21:50:12 03.11.2011 Titel:
Zitieren
MrX hat auf integer umgebaut:
C/C++ Code: 1 2 3 4 5 6 7 8 9 10 11 12
1 2 3 4 5 6 7 8 9 10 11 12
static uint8_t calculateWeekday(uint16_t year, uint8_t month, int32_t day)
{
day += 6; // 1.1.1600 was a saturday
day += (year/*-1600*/ * 146097)/400 + days[month-1];
if (isLeapyear(year) && (month < 2 || (month == 2 && day <= 28)))
{
day--;
}
return (day % 7 + 1);
}
C/C++ Code: 1 2 3 4 5 6 7 8 9 10 11 12
static uint8_t calculateWeekday(uint16_t year, uint8_t month, int32_t day)
{
day += 6; // 1.1.1600 was a saturday
day += (year/*-1600*/ * 146097)/400 + days[month-1];
if (isLeapyear(year) && (month < 2 || (month == 2 && day <= 28)))
{
day--;
}
return (day % 7 + 1);
}
C/C++ Code: 1 2 3 4 5 6 7 8 9 10 11 12
static uint8_t calculateWeekday(uint16_t year, uint8_t month, int32_t day)
{
day += 6; // 1.1.1600 was a saturday
day += (year/*-1600*/ * 146097)/400 + days[month-1];
if (isLeapyear(year) && (month < 2 || (month == 2 && day <= 28)))
{
day--;
}
return (day % 7 + 1);
}
Kleine Testvariante:
C/C++ Code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
#include "stdio.h "
int days[12] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
int isLeapyear(int year)
{
return (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0));
}
int calculateWeekdayFloat(int year, int month, int day)
{
day += 6; // 1.1.1600 was a saturday
day += year/*-1600*/ * 365.2425 + days[month-1];
if (isLeapyear(year) && (month < 2 || (month == 2 && day <= 28)))
{
day--;
}
return (day % 7 + 1);
}
int calculateWeekdayInteger(int year, int month, int day)
{
day += 6; // 1.1.1600 was a saturday
day += (year/*-1600*/ * 146097)/400 + days[month-1];
if (isLeapyear(year) && (month < 2 || (month == 2 && day <= 28)))
{
day--;
}
return (day % 7 + 1);
}
int main()
{
int y,m,d;
for (y=0; y<=12000; y++)
{
printf("%u ", y);
for (m=1; m<=12; m++)
{
for (d=1; d<=31; d++)
{
if (calculateWeekdayFloat(y,m,d) == (calculateWeekdayInteger(y,m,d))){}
else
{
printf("fehler ");
for (;;);
}
}
}
}
}
C/C++ Code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
#include "stdio.h "
int days[12] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
int isLeapyear(int year)
{
return (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0));
}
int calculateWeekdayFloat(int year, int month, int day)
{
day += 6; // 1.1.1600 was a saturday
day += year/*-1600*/ * 365.2425 + days[month-1];
if (isLeapyear(year) && (month < 2 || (month == 2 && day <= 28)))
{
day--;
}
return (day % 7 + 1);
}
int calculateWeekdayInteger(int year, int month, int day)
{
day += 6; // 1.1.1600 was a saturday
day += (year/*-1600*/ * 146097)/400 + days[month-1];
if (isLeapyear(year) && (month < 2 || (month == 2 && day <= 28)))
{
day--;
}
return (day % 7 + 1);
}
int main()
{
int y,m,d;
for (y=0; y<=12000; y++)
{
printf("%u ", y);
for (m=1; m<=12; m++)
{
for (d=1; d<=31; d++)
{
if (calculateWeekdayFloat(y,m,d) == (calculateWeekdayInteger(y,m,d))){}
else
{
printf("fehler ");
for (;;);
}
}
}
}
}
C/C++ Code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
#include "stdio.h "
int days[12] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
int isLeapyear(int year)
{
return (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0));
}
int calculateWeekdayFloat(int year, int month, int day)
{
day += 6; // 1.1.1600 was a saturday
day += year/*-1600*/ * 365.2425 + days[month-1];
if (isLeapyear(year) && (month < 2 || (month == 2 && day <= 28)))
{
day--;
}
return (day % 7 + 1);
}
int calculateWeekdayInteger(int year, int month, int day)
{
day += 6; // 1.1.1600 was a saturday
day += (year/*-1600*/ * 146097)/400 + days[month-1];
if (isLeapyear(year) && (month < 2 || (month == 2 && day <= 28)))
{
day--;
}
return (day % 7 + 1);
}
int main()
{
int y,m,d;
for (y=0; y<=12000; y++)
{
printf("%u ", y);
for (m=1; m<=12; m++)
{
for (d=1; d<=31; d++)
{
if (calculateWeekdayFloat(y,m,d) == (calculateWeekdayInteger(y,m,d))){}
else
{
printf("fehler ");
for (;;);
}
}
}
}
}
Dürfte also klappen.
_________________ OS-Development-, C++, Win32-API-, MFC-, Chemie-, Robotik- und Flugsimulator-Tutorials
http://www.henkessoft.de/index.htm
Nächstes Thema anzeigen
Vorheriges Thema anzeigen
Sie können keine Beiträge in dieses Forum schreiben. Sie können auf Beiträge in diesem Forum nicht antworten. Sie können Ihre Beiträge in diesem Forum nicht bearbeiten. Sie können Ihre Beiträge in diesem Forum nicht löschen. Sie können an Umfragen in diesem Forum nicht mitmachen.