3rd Repo, trying to figure this out.
Fork of SOFT253_Template_Weather_OS_54 by
Diff: LocalDate/LocalDate.cpp
- Revision:
- 83:0d3572a8a851
- Parent:
- 82:668b51a39148
- Child:
- 85:422d0a1b95cf
--- a/LocalDate/LocalDate.cpp Thu May 11 15:53:15 2017 +0000 +++ b/LocalDate/LocalDate.cpp Thu May 11 19:23:55 2017 +0000 @@ -1,85 +1,95 @@ #include "LocalDate.h" #include <stdio.h> -// -// CONSTRUCTORS -// - LocalDate::LocalDate(int d, int m, int y,int h,int mm,int s) - { - day = d; - month = m; - year = y; - hour = h; - min = mm; - sec = s; - } - LocalDate::LocalDate() - { - day = 12; - month = 12; - year = 2012; - hour = 12; - min = 12; - sec = 12; - } - LocalDate::LocalDate(LocalDate *localDate) +LocalDate::LocalDate(int d, int m, int y,int h,int mm,int s) +{ + day = d; + month = m; + year = y; + hour = h; + min = mm; + sec = s; +} + +LocalDate::LocalDate() +{ + day = 12; + month = 12; + year = 2012; + hour = 12; + min = 12; + sec = 12; +} + +LocalDate::LocalDate(LocalDate *localDate) +{ + day = localDate->day; + month = localDate->month; + year = localDate->year; + hour = localDate->hour; + min = localDate->min; + sec = localDate->sec; +} + +/** + Sets values to passed in localDate object. + + @param localDate : LocalDate object storing data. +*/ +void LocalDate::setValues(LocalDate *localDate) +{ + day = localDate->day; + month = localDate->month; + year = localDate->year; + hour = localDate->hour; + min = localDate->min; + sec = localDate->sec; +} + +/** + Takes data stored in LocalDate objects and formats it. + + @return charArray : Char array containing formatted data to be printed. +*/ +char* LocalDate::ToString() +{ + char *charArray = new char[40]; + snprintf(charArray, 256, "%i/%i/%i, %i:%i:%i",day,month,year,hour,min,sec); + return charArray; +} + +/** + Increases time stored in object by one second, calculating the new time. +*/ +void LocalDate::TickSecond() +{ + sec++; + if(sec == 60) { - day = localDate->day; - month = localDate->month; - year = localDate->year; - hour = localDate->hour; - min = localDate->min; - sec = localDate->sec; - } - void LocalDate::setValues(LocalDate *localDate) - { - day = localDate->day; - month = localDate->month; - year = localDate->year; - hour = localDate->hour; - min = localDate->min; - sec = localDate->sec; - } - -// -// PUBLIC METHODS: -// - char* LocalDate::ToString() - { - char *charArray = new char[40]; - snprintf(charArray, 256, "%i/%i/%i, %i:%i:%i",day,month,year,hour,min,sec); - return charArray; - } - - void LocalDate::TickSecond() - { - // ARRON TODO: Fix so time accounts for days in different months/leap years etc. + sec=0; + min++; + if(min==60) + { + + min = 0; + hour++; - sec++; - if(sec == 60) - { - sec=0; - min++; - if(min==60) + if(hour ==24) { - min = 0; - hour++; - if(hour ==24) + hour = 0; + day++; + + if(day ==31) { - hour = 0; - day++; - if(day ==31) + day = 0; + month++; + if(month==13) { - day = 0; - month++; - if(month==13) - { - month = 1; - year++; - } + month = 1; + year++; } } } } - } +}