FMI Ticket System
| Kamen Mladenov | FMI Computer Science Year 1 Group 6 | Project 1 | Project Topic 4 |
Public Member Functions | List of all members
Date Class Reference

Stores a day, month and year. More...

#include <Date.h>

Public Member Functions

 Date ()
 Sets date as 01 May 2022.
 
 Date (const char *str)
 Parses string. More...
 
 Date (unsigned short day, unsigned short month, unsigned short year)
 Sets day, month and year. More...
 
unsigned short get_day () const
 Returns the day.
 
bool set_day (unsigned short day)
 Sets the day. More...
 
unsigned short get_month () const
 Returns the month.
 
bool set_month (unsigned short month)
 Sets the month. More...
 
unsigned short get_year () const
 Returns the year.
 
bool set_year (unsigned short year)
 Sets the year. More...
 
String createString () const
 Returns the date as a String object. More...
 
void read (std::istream &istr)
 Reads date from stream. More...
 
void write (std::ostream &ostr)
 Writes date to stream. More...
 
int compare (const Date &other) const
 Compares two dates. More...
 

Detailed Description

Stores a day, month and year.

Constructor & Destructor Documentation

◆ Date() [1/2]

Date::Date ( const char *  str)

Parses string.

Parameters
strC-style string

Values are initialized with zeroes. Then it parses the string:

Skips spaces, saves day with atoi, skips two characters, skips spaces, saves month with atoi, skips two characters, skips spaces, saves year with atoi.

Values are validated with setters. You should always have spaces between day, month and year and no non-numeric characters between them.

Remarks
If there are non-numeric characters, as per atoi() spec, the appropriate property is zero.

◆ Date() [2/2]

Date::Date ( unsigned short  day,
unsigned short  month,
unsigned short  year 
)

Sets day, month and year.

Initializes values with zeroes and then uses setters to save the function arguments.

Member Function Documentation

◆ compare()

int Date::compare ( const Date &  other) const

Compares two dates.

Returns
-1 if this < other, 1 if this > other, 0 if this == other

◆ createString()

String Date::createString ( ) const

Returns the date as a String object.

Returns
String object in the format "day.month.year"
Note
Currently there isn't any way to change the formatting

◆ read()

void Date::read ( std::istream &  istr)

Reads date from stream.

Parameters
istrAn input stream

Directly reads bytes from stream (calls read() function).

Remarks
Doesn't alter the stream in any other way.
Note
Best used with binary ifstream

◆ set_day()

bool Date::set_day ( unsigned short  newDay)

Sets the day.

Returns
Whether newDay was saved or not

If newDay is equal to 0, or is more than the appropriate days in the month, the day isn't set.

◆ set_month()

bool Date::set_month ( unsigned short  newMonth)

Sets the month.

Returns
Whether newMonth was saved or not

If newMonth is equal to 0 or is more than 12, the month isn't set.

◆ set_year()

bool Date::set_year ( unsigned short  newYear)

Sets the year.

Returns
Whether year was saved or not

Year isn't set when newYear is zero

◆ write()

void Date::write ( std::ostream &  ostr)

Writes date to stream.

Parameters
ostrAn output stream

Directly writes bytes to stream (calls write() function).

Remarks
Doesn't alter the stream in any other way.
Note
Best used with binary ofstream

The documentation for this class was generated from the following files: