1 ///////////////////////////////////////////////////////////
2 // Softwarebauelemente I, Aufgabe M6.2.
3 //
4 // author: Stephan Brumme
5 // last changes: December 29, 2000
6
7
8 // include the header file
9 #include "MDate.h"
10
11 // standard timer library
12 #include <time.h>
13
14 // needed to display data in MDate::Show(..)
15 #include <iostream>
16
17
18 // initializes a TDate struct with the current date
19 void MDate::Today(TDate& TheDate)
20 {
21 // the following code is taken from MSDN
22
23 // use system functions to get the current date as UTC
24 time_t secondsSince1970;
25 time(&secondsSince1970);
26
27 // convert UTC to local time zone
28 struct tm *localTime;
29 localTime = localtime(&secondsSince1970);
30
31 // store retrieved data
32 TheDate.Day = localTime->tm_mday;
33 TheDate.Month = localTime->tm_mon + 1;
34 TheDate.Year = localTime->tm_year + 1900;
35 }
36
37
38 // initializes a TDate struct with a specified date
39 // !!! does not verify for validity !!!
40 void MDate::InitDate(TDate& TheDate, Ordinal TheDay, Ordinal TheMonth, Ordinal TheYear)
41 {
42 // nothing special ...
43 TheDate.Day = TheDay;
44 TheDate.Month = TheMonth;
45 TheDate.Year = TheYear;
46 }
47
48
49 // compares two dates
50 Boolean MDate::EqualValue(const TDate& Date1, const TDate& Date2)
51 {
52 return ((Date1.Day == Date2.Day ) &&
53 (Date1.Month == Date2.Month) &&
54 (Date1.Year == Date2.Year));
55 }
56
57
58 // copy a date
59 Boolean MDate::Copy(TDate& Date1, const TDate& Date2)
60 {
61 // both dates must differ
62 if (EqualValue(Date1, Date2))
63 return false;
64
65 Date1.Day = Date2.Day;
66 Date1.Month = Date2.Month;
67 Date1.Year = Date2.Year;
68
69 // successfully done
70 return true;
71 }
72
73
74 // displays a TDate
75 void MDate::Show(const TDate& TheDate)
76 {
77 std::cout << TheDate.Day << "." << TheDate.Month << "." << TheDate.Year << std::endl;
78 }
79