Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
BPrivate::Network::BHttpTime Class Reference

Utility class that can parse and format HTTP Date strings. More...

Classes

class  InvalidInput
 Error that indicates that a string cannot be parsed as a valid HTTP timestamp. More...
 

Public Member Functions

 BHttpTime () noexcept
 Constructs a new object and sets the timestamp to the current time.
 
 BHttpTime (BDateTime date)
 Constructs a new object and sets the timestamp to date.
 
 BHttpTime (const BString &dateString)
 Constructs a new object and parses the timestamp from dateString.
 
BDateTime DateTime () const noexcept
 Get the current timestamp.
 
BHttpTimeFormat DateTimeFormat () const noexcept
 Get the format that the current timestamp parsed from.
 
void SetTo (BDateTime date)
 Set the current timestamp to date.
 
void SetTo (const BString &string)
 Set the current timestamp by parsing string.
 
BString ToString (BHttpTimeFormat outputFormat=BHttpTimeFormat::RFC1123) const
 Formats the timestamp to a string.
 

Detailed Description

Utility class that can parse and format HTTP Date strings.

See the description of the module in HttpTime.h for more information about HTTP timestamps.

Note that for quick conversions of a BDateTime into a BString and vice versa, you can also use the format_http_time() and parse_http_time() utilities.

Since
Haiku R1

Constructor & Destructor Documentation

◆ BHttpTime() [1/3]

BPrivate::Network::BHttpTime::BHttpTime ( )
noexcept

Constructs a new object and sets the timestamp to the current time.

Since
Haiku R1

◆ BHttpTime() [2/3]

BPrivate::Network::BHttpTime::BHttpTime ( BDateTime  date)

Constructs a new object and sets the timestamp to date.

Parameters
dateA valid BDateTime object for the desired timestamp.
Exceptions
BHttpTime::InvalidInputThe date does not contain a valid timestamp.
Since
Haiku R1

◆ BHttpTime() [3/3]

BPrivate::Network::BHttpTime::BHttpTime ( const BString dateString)

Constructs a new object and parses the timestamp from dateString.

Parameters
dateStringA string that contains a valid HTTP timestamp. The dateString must not contain any characters, other than the timestamp. It is up to the caller to sanitize any input, including trimming whitespace at the beginning and end of the string.
Exceptions
BHttpTime::InvalidInputThe dateString cannot be parsed as a valid timestamp.
Since
Haiku R1

Member Function Documentation

◆ DateTime()

BDateTime BPrivate::Network::BHttpTime::DateTime ( ) const
noexcept

Get the current timestamp.

Returns
A valid BDateTime object that contains the timestamp that this object is currently set to.
Since
Haiku R1

◆ DateTimeFormat()

BHttpTimeFormat BPrivate::Network::BHttpTime::DateTimeFormat ( ) const
noexcept

Get the format that the current timestamp parsed from.

If the timestamp was parsed from a string, this method supplies a bit of information about what format the original string was in. Note that for both the RFC 1132 and RFC 850 formats, the parsing is slightly less strict than the RFC prescribes. This may mean that if you parse a non-canonical string, and then format it back using the same format specifier, the two strings may differ in content.

If the timestamp was set by setting it to a BDateTime object, then this will always return BHttpTimeFormat::RFC1123.

Returns
The BHttpTimeFormat that describes the format the input string was in, or BHttpTimeFormat::RFC1123 if the timestamp was set by a BDateTime.
Since
Haiku R1

◆ SetTo() [1/2]

void BPrivate::Network::BHttpTime::SetTo ( BDateTime  date)

Set the current timestamp to date.

Parameters
dateA valid BDateTime object for the desired timestamp.
Exceptions
BHttpTime::InvalidInputThe date does not contain a valid timestamp.
Since
Haiku R1

◆ SetTo() [2/2]

void BPrivate::Network::BHttpTime::SetTo ( const BString string)

Set the current timestamp by parsing string.

Parameters
stringA string that contains a valid HTTP timestamp. The dateString must not contain any characters, other than the timestamp. It is up to the caller to sanitize any input, including trimming whitespace at the beginning and end of the string.
Exceptions
BHttpTime::InvalidInputThe dateString cannot be parsed as a valid timestamp.
Since
Haiku R1

◆ ToString()

BString BPrivate::Network::BHttpTime::ToString ( BHttpTimeFormat  outputFormat = BHttpTimeFormat::RFC1123) const

Formats the timestamp to a string.

Parameters
outputFormatThe requested outputformat. The default is the recommended RFC 1123 format.
Returns
A string that contains the formatted timestamp.
Exceptions
std::bad_allocIn the future this method may throw this exception when the memory for the output string cannot be allocated.
Since
Haiku R1