zipios
2.2.0
Zipios – a small C++ library that provides easy access to .zip files.
|
#include <dosdatetime.hpp>
Public Types | |
typedef uint32_t | dosdatetime_t |
Public Member Functions | |
int | daysInMonth () const |
Calculate the number of days in this date's month. More... | |
dosdatetime_t | getDOSDateTime () const |
Retrieve the DOSDateTime value as is. More... | |
int | getHour () const |
Get the hour. More... | |
int | getMDay () const |
Get the day of the month. More... | |
int | getMinute () const |
Get the minute. More... | |
int | getMonth () const |
Get the month. More... | |
int | getSecond () const |
Get the second. More... | |
std::time_t | getUnixTimestamp () const |
Retrieve the DOSDateTime as a Unix timestamp. More... | |
int | getYear () const |
Get the year. More... | |
bool | isValid () const |
Check whether this DOS Date & Date is valid. More... | |
void | setDOSDateTime (dosdatetime_t datetime) |
Set the DOSDateTime value as is. More... | |
void | setHour (int hour) |
Set the hour. More... | |
void | setMDay (int mday) |
Set the day of the month. More... | |
void | setMinute (int minute) |
Set the minute. More... | |
void | setMonth (int month) |
Set the month. More... | |
void | setSecond (int second) |
Set the second. More... | |
void | setUnixTimestamp (std::time_t unix_timestamp) |
Set the DOSDateTime value from a Unix timestamp. More... | |
void | setYear (int year) |
Set the year. More... | |
Static Public Attributes | |
static dosdatetime_t const | g_max_dosdatetime = 0xFF9FBF7D |
static dosdatetime_t const | g_min_dosdatetime = 0x00210000 |
Protected Attributes | |
dosdatetime_t | m_dosdatetime = 0 |
Definition at line 44 of file dosdatetime.hpp.
typedef uint32_t zipios::DOSDateTime::dosdatetime_t |
Definition at line 47 of file dosdatetime.hpp.
int zipios::DOSDateTime::daysInMonth | ( | ) | const |
This function uses this object's current month to determine how many days are expected in that month.
If the month field is invalid (not a number between 1 and 12 inclusive) then the function returns -1 to indicate an error.
The number of days is always 30 or 31 except for the month of February in which case the function may return 28 or 29. For this reason, your date must have the month and year you want to use to get a valid result when calling this function.
Definition at line 173 of file dosdatetime.cpp.
References zipios::anonymous_namespace{dosdatetime.cpp}::g_days_in_month, zipios::dosdatetime_convert_t::m_dosdatetime, zipios::dosdatetime_convert_t::m_fields, zipios::dosdatetime_convert_t::fields::m_month, and zipios::dosdatetime_convert_t::fields::m_year.
DOSDateTime::dosdatetime_t zipios::DOSDateTime::getDOSDateTime | ( | ) | const |
This function returns the DOSDateTime value as is. It can then be used in the zip file.
Definition at line 481 of file dosdatetime.cpp.
References zipios::dosdatetime_convert_t::m_dosdatetime.
Referenced by zipios::FileEntry::getTime(), main(), zipios::ZipCentralDirectoryEntry::write(), and zipios::ZipLocalEntry::write().
int zipios::DOSDateTime::getHour | ( | ) | const |
This function returns the hour this DOSDateTime object represents.
The hour is between 0 and 23 inclusive.
Definition at line 249 of file dosdatetime.cpp.
References zipios::dosdatetime_convert_t::m_dosdatetime, zipios::dosdatetime_convert_t::m_fields, and zipios::dosdatetime_convert_t::fields::m_hour.
int zipios::DOSDateTime::getMDay | ( | ) | const |
This function returns the day of month this DOSDateTime object represents.
The day is between 1 and 31. To know whether a day is valid, use the daysInMonth() function which returns the maximum number of days for a given month.
Definition at line 267 of file dosdatetime.cpp.
References zipios::dosdatetime_convert_t::m_dosdatetime, zipios::dosdatetime_convert_t::m_fields, and zipios::dosdatetime_convert_t::fields::m_mday.
int zipios::DOSDateTime::getMinute | ( | ) | const |
This function returns the minute this DOSDateTime object represents.
The minute is between 0 and 59 inclusive.
Definition at line 233 of file dosdatetime.cpp.
References zipios::dosdatetime_convert_t::m_dosdatetime, zipios::dosdatetime_convert_t::m_fields, and zipios::dosdatetime_convert_t::fields::m_minute.
int zipios::DOSDateTime::getMonth | ( | ) | const |
This function returns the month this DOSDateTime object represents.
The month is between 1 and 12.
Definition at line 283 of file dosdatetime.cpp.
References zipios::dosdatetime_convert_t::m_dosdatetime, zipios::dosdatetime_convert_t::m_fields, and zipios::dosdatetime_convert_t::fields::m_month.
int zipios::DOSDateTime::getSecond | ( | ) | const |
This function returns the second this DOSDateTime object represents.
The second is between 0 and 59 inclusive.
Definition at line 217 of file dosdatetime.cpp.
References zipios::dosdatetime_convert_t::m_dosdatetime, zipios::dosdatetime_convert_t::m_fields, and zipios::dosdatetime_convert_t::fields::m_second.
std::time_t zipios::DOSDateTime::getUnixTimestamp | ( | ) | const |
This function returns the DOSDateTime converted to a Unix timestamp. On 64 bit platforms, all DOSDateTime can be converted to a Unix timestamp. On a 32 bit platform, however, dates after 2037 can't be represented by the Unix timestamp so this function throws (note that we did not check the exact threshold because at this point I don't think it's too important.)
InvalidException | On 32 bit platform, dates that can't be represented in a Unix timestamp throw this exception. |
Definition at line 591 of file dosdatetime.cpp.
References zipios::dosdatetime_convert_t::m_dosdatetime, zipios::dosdatetime_convert_t::m_fields, zipios::dosdatetime_convert_t::fields::m_hour, zipios::dosdatetime_convert_t::fields::m_mday, zipios::dosdatetime_convert_t::fields::m_minute, zipios::dosdatetime_convert_t::fields::m_month, zipios::dosdatetime_convert_t::fields::m_second, and zipios::dosdatetime_convert_t::fields::m_year.
Referenced by main(), zipios::ZipCentralDirectoryEntry::read(), zipios::ZipLocalEntry::read(), and zipios::FileEntry::setTime().
int zipios::DOSDateTime::getYear | ( | ) | const |
This function returns the year this DOSDateTime object represents.
The year is limited between 1980 and 2107.
Definition at line 299 of file dosdatetime.cpp.
References zipios::dosdatetime_convert_t::m_dosdatetime, zipios::dosdatetime_convert_t::m_fields, and zipios::dosdatetime_convert_t::fields::m_year.
bool zipios::DOSDateTime::isValid | ( | ) | const |
This function verifies to see whether the DOS Date & Time it holds is valid. By default, the value is set to zero which represents an invalid date (not set).
Definition at line 139 of file dosdatetime.cpp.
References zipios::dosdatetime_convert_t::m_dosdatetime, zipios::dosdatetime_convert_t::m_fields, zipios::dosdatetime_convert_t::fields::m_hour, zipios::dosdatetime_convert_t::fields::m_mday, zipios::dosdatetime_convert_t::fields::m_minute, zipios::dosdatetime_convert_t::fields::m_month, and zipios::dosdatetime_convert_t::fields::m_second.
void zipios::DOSDateTime::setDOSDateTime | ( | dosdatetime_t | datetime | ) |
This function sets this DOSDateTime object's timestamp to the specified value. Any value is accepted by this function. To verify that the new value is a valid date, use the isValid() function.
[in] | datetime | The DOS Date & Time value. |
Definition at line 495 of file dosdatetime.cpp.
References zipios::dosdatetime_convert_t::m_dosdatetime.
Referenced by main(), zipios::ZipCentralDirectoryEntry::read(), zipios::ZipLocalEntry::read(), and zipios::FileEntry::setTime().
void zipios::DOSDateTime::setHour | ( | int | hour | ) |
This function can be used to only change the hour of a DOSDateTime object.
InvalidException | The hour is expected to be set to a number between 0 and 23 inclusive. |
[in] | hour | The new DOSDateTime number of hours. |
Definition at line 379 of file dosdatetime.cpp.
References zipios::dosdatetime_convert_t::m_dosdatetime, zipios::dosdatetime_convert_t::m_fields, and zipios::dosdatetime_convert_t::fields::m_hour.
void zipios::DOSDateTime::setMDay | ( | int | mday | ) |
This function can be used to only change the day of the month of a DOSDateTime object.
InvalidException | The day of the month is expected to be set to a number between 1 and 31 inclusive. An exception is raised if out of that range. Note that no exception is raised if the day is invalid for a certain month because at this point we can't be sure what the month will be. To verify once you are done setting all the individual values, call isValid() to do a final verification. |
[in] | mday | The new DOSDateTime day of the month. |
Definition at line 409 of file dosdatetime.cpp.
References zipios::dosdatetime_convert_t::m_dosdatetime, zipios::dosdatetime_convert_t::m_fields, and zipios::dosdatetime_convert_t::fields::m_mday.
void zipios::DOSDateTime::setMinute | ( | int | minute | ) |
This function can be used to only change the minute of a DOSDateTime object.
InvalidException | The minute is expected to be set to a number between 0 and 59 inclusive. |
[in] | minute | The new DOSDateTime number of minutes. |
Definition at line 354 of file dosdatetime.cpp.
References zipios::dosdatetime_convert_t::m_dosdatetime, zipios::dosdatetime_convert_t::m_fields, and zipios::dosdatetime_convert_t::fields::m_minute.
void zipios::DOSDateTime::setMonth | ( | int | month | ) |
This function can be used to only change the month of a DOSDateTime object.
InvalidException | The month is expected to be set to a number between 1 and 12 inclusive. |
[in] | month | The ne DOSDateTime month. |
Definition at line 433 of file dosdatetime.cpp.
References zipios::dosdatetime_convert_t::m_dosdatetime, zipios::dosdatetime_convert_t::m_fields, and zipios::dosdatetime_convert_t::fields::m_month.
void zipios::DOSDateTime::setSecond | ( | int | second | ) |
This function can be used to only change the second of a DOSDateTime object.
Leap seconds are not supported. Trying to pass 60 to this function raises an InvalidException error.
InvalidException | The second is expected to be set to a number between 0 and 59 inclusive. No exception is raised if an odd number is passed down. Bit 0 is simply ignored. |
[in] | second | The new DOSDateTime number of seconds. |
Definition at line 329 of file dosdatetime.cpp.
References zipios::dosdatetime_convert_t::m_dosdatetime, zipios::dosdatetime_convert_t::m_fields, and zipios::dosdatetime_convert_t::fields::m_second.
void zipios::DOSDateTime::setUnixTimestamp | ( | std::time_t | unix_timestamp | ) |
This function accepts a Unix timestamp that gets converted to a DOSDateTime object.
A Unix timestamp is a time_t number representing seconds. 0 represents the date Jan 1, 1970 at 00:00:00.
The smallest Unix timestamp that can be represented in a DOSDateTime object is 315532800 (0x12cea600) in UTC. Since the timestamp gets converted to local time, though, the boundaries vary with the user's timezone.
The minimum date is represented as 0x00210000 in a DOSDateTime object. This represents Jan 1, 1980 at 00:00:00, local time.
The largest Unix timestamp that can be represented in a DOSDateTime object is 4354819199 (0x10391447f) in UTC, since the timestamp gets converted to local time, though, the boundaries vary with the user's timezone.
The maximum date is represented as 0xff9fbf7d in a DOSDateTime object. Note that the Unix timestamp requires a 64 bit time_t
representation in order to reach the maximum DOSDateTime. With a 32 bit number, the maximum is around 2037, about 70 years short. This maximum date represents Dec 31, 2107 at 23:59:59, local time.
The DOSDateTime object only holds even seconds. Odd seconds are lost at the time this function gets called.
InvalidException | In 64 bits, a Unix timestamp can represent very large dates in both directions (in the past and future.) If the Unix timestamp represents a local date and time before Jan 1, 1980 at 00:00:00 or after Dec 31, 2107 at 23:59:58, then this function raises this exception. It is likely to raise an exception on Dec 31, 2107 at 23:59:59 because we round the time to the next even second. |
[in] | unix_timestamp | The time and stamp in Unix format. |
Definition at line 542 of file dosdatetime.cpp.
References zipios::dosdatetime_convert_t::m_dosdatetime, zipios::dosdatetime_convert_t::m_fields, zipios::dosdatetime_convert_t::fields::m_hour, zipios::dosdatetime_convert_t::fields::m_mday, zipios::dosdatetime_convert_t::fields::m_minute, zipios::dosdatetime_convert_t::fields::m_month, zipios::dosdatetime_convert_t::fields::m_second, and zipios::dosdatetime_convert_t::fields::m_year.
Referenced by zipios::FileEntry::getTime(), main(), zipios::ZipCentralDirectoryEntry::write(), and zipios::ZipLocalEntry::write().
void zipios::DOSDateTime::setYear | ( | int | year | ) |
This function can be used to only change the year this DOSDateTime object represents.
InvalidException | The year is limited between 1980 and 2107. This exception is raised if the year to out of this range. |
Definition at line 459 of file dosdatetime.cpp.
References zipios::dosdatetime_convert_t::m_dosdatetime, zipios::dosdatetime_convert_t::m_fields, and zipios::dosdatetime_convert_t::fields::m_year.
|
static |
Definition at line 50 of file dosdatetime.hpp.
|
static |
Definition at line 49 of file dosdatetime.hpp.
|
protected |
Definition at line 72 of file dosdatetime.hpp.