?
Hier hab ich mal etwas ist zwar nicht gut Kommentiert aber ich glaub das man
damit zurecht kommt.
Berechnet die Kalenderwoche nach DIN 1535 oder so ähnlich.
H-Datei
#pragma once
#include "atlcomtime.h"
// Klasse von COleDateTime abgeleitet
class AFX_EXT_CLASS CMyDateTime :
public COleDateTime
{
public:
CMyDateTime(void);
~CMyDateTime(void);
// Zuweisungsoperator
const CMyDateTime& operator=(const COleDateTime& date);
protected:
// Hier die eigentliche Berechnung der Kalenderwoche nach DIN 1535
int KalW(void);
public:
//int ISOWeek(void);
// Übergabe als String in der Form TT.MM.JJJJ
int ISOWeek(const CString& str);
// Übergabe als COleDateTime Referenz
int ISOWeek(COleDateTime& dt);
// Übergabe als Jahr Monat und Tag als String
int ISOWeek(const CString& sYear, const CString& sMonth, const CString& sDay);
// Jahr Monat Tag als int
int ISOWeek(int iYear, int iMonth, int iDay);
// Gibt 0 oder 1 zurück ob das jahr ein Schaltjahr ist
int GetLeapYear(void);
};
Cpp-Datei
#include "StdAfx.h"
#include "mydatetime.h"
#include <stdlib.h>
CMyDateTime::CMyDateTime(void)
{
}
CMyDateTime::~CMyDateTime(void)
{
}
// Zuweisungsoperator
const CMyDateTime& CMyDateTime::operator=(const COleDateTime& date)
{
if( this == &date )
return *this;
m_dt = date.m_dt;
return *this;
}
//int CMyDateTime::ISOWeek(void)
//{
// return KalW();
//}
// Übergabe als String in der Form TT.MM.JJJJ
int CMyDateTime::ISOWeek(const CString& str)
{
ParseDateTime(str);
return KalW();
}
// Übergabe als COleDateTime Referenz
int CMyDateTime::ISOWeek(COleDateTime& dt)
{
m_dt = dt.m_dt;
return KalW();
}
// Übergabe als Jahr Monat und Tag als String
int CMyDateTime::ISOWeek(const CString& sYear,
const CString& sMonth,
const CString& sDay)
{
SetDate(atoi(sYear), atoi(sMonth), atoi(sDay));
return KalW();
}
// Jahr Monat Tag als int
int CMyDateTime::ISOWeek(int iYear, int iMonth, int iDay)
{
SetDate(iYear, iMonth, iDay);
return KalW();
}
// Gibt 0 oder 1 zurück ob das jahr ein Schaltjahr ist
int CMyDateTime::GetLeapYear(void)
{
return GetYear()%4 == 0 && GetYear()%100 != 0 || GetYear()%400 == 0;
}
int CMyDateTime::KalW(void)
{
ASSERT(m_dt != 0.0);
if( m_dt == 0.0 )
return -1;
COleDateTime year, tmp;
int iDt;
year = (m_dt + ( 8 - GetDayOfWeek()) % 7 - 3);
tmp.SetDate(year.GetYear(), 1, 1);
iDt = (int)(m_dt - tmp.m_dt - 3 + (tmp.GetDayOfWeek() + 1) % 7)/7+1;
return iDt;
}
Ich hoffe das ihr damit klar kommt.
Gruß Jochen