zipios  2.2.0
Zipios – a small C++ library that provides easy access to .zip files.
Public Types | Public Member Functions | Static Public Attributes | Protected Attributes | List of all members
zipios::DOSDateTime Class Reference

#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
 

Detailed Description

Definition at line 44 of file dosdatetime.hpp.

Member Typedef Documentation

Definition at line 47 of file dosdatetime.hpp.

Member Function Documentation

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.

Note
This function is used to verify that the date month day is valid.
Returns
The number of days in this date's current month.
See also
isValid()

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.

Returns
The dosdatetime_t timestamp.

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.

Returns
The hour this DOS Date & Time represents.

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.

Returns
The day of the month this DOS Date & Time represents.

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.

Returns
The minute this DOS Date & Time represents.

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.

Returns
The month this DOS Date & Time represents.

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.

Note
The DOSDateTime format only supports 5 bits for seconds. In other words, the number can't go all the way from 0 to 59. Instead, the second is saved without bit 0. In other words, only an even number of second is saved. In other words, 0, 2, 4, 6, up to 58.
Returns
The second this DOS Date & Time represents.

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.)

Exceptions
InvalidExceptionOn 32 bit platform, dates that can't be represented in a Unix timestamp throw this exception.
Returns
The Unix timestamp representing the DOSDateTime object.
See also
setUnixTimestamp()

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.

Returns
The year this DOS Date & Time represents.

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).

Note
Remember that Zip file Date & Time are saved in an old MS-DOS format which did not respect UTC. It instead represents local time. This function returns true when the local time is valid, since the same time will be shared around the globe, it will alway sbe considered valid, but the Unix timestamp can look like a mismatch (the minimum and maximum possible time stamps represented in a Unix time_t variable will vary depending on your timezone settings.)
Returns
true if the date is considered valid (represents an actual date and time).
See also
daysInMonth()

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.

Parameters
[in]datetimeThe 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.

Exceptions
InvalidExceptionThe hour is expected to be set to a number between 0 and 23 inclusive.
Parameters
[in]hourThe 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.

Exceptions
InvalidExceptionThe 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.
Parameters
[in]mdayThe 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.

Exceptions
InvalidExceptionThe minute is expected to be set to a number between 0 and 59 inclusive.
Parameters
[in]minuteThe 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.

Exceptions
InvalidExceptionThe month is expected to be set to a number between 1 and 12 inclusive.
Parameters
[in]monthThe 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.

Note
The DOSDateTime format only supports 5 bits for seconds. In other words, the number can't go all the way from 0 to 59. Instead, the second is saved without bit 0. In other words, only an even number of second is saved. In other words, 0, 2, 4, 6, up to 58.

Leap seconds are not supported. Trying to pass 60 to this function raises an InvalidException error.

Exceptions
InvalidExceptionThe 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.
Parameters
[in]secondThe 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.

Exceptions
InvalidExceptionIn 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.
Parameters
[in]unix_timestampThe 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.

Exceptions
InvalidExceptionThe year is limited between 1980 and 2107. This exception is raised if the year to out of this range.
Returns
The year this DOS Date & Time represents.

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.

Member Data Documentation

DOSDateTime::dosdatetime_t const zipios::DOSDateTime::g_max_dosdatetime = 0xFF9FBF7D
static

Definition at line 50 of file dosdatetime.hpp.

DOSDateTime::dosdatetime_t const zipios::DOSDateTime::g_min_dosdatetime = 0x00210000
static

Definition at line 49 of file dosdatetime.hpp.

dosdatetime_t zipios::DOSDateTime::m_dosdatetime = 0
protected

Definition at line 72 of file dosdatetime.hpp.


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