Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
QDatePattern Class Reference

A description of a serialization format for a date. More...

#include <qttemporalpattern_p.h>

Collaboration diagram for QDatePattern:

Public Member Functions

bool isValid () const noexcept
void setLocale (const QLocale &loc)
const QLocalelocale () const noexcept
 Returns the current locale in use by this pattern.
void setBaseYear (int centuryStart)
void clearBaseYear () noexcept
std::optional< int > baseYear () const noexcept
void setCalendar (QCalendar cal)
QCalendar calendar () const noexcept
 Returns the current calendar in use by this pattern.
Q_CORE_EXPORT QtTemporalPattern::ParseResult< QDateparse (QStringView text, QDate defaults={}) const
 Parse and return the date represented by text.
Q_CORE_EXPORT QString serialize (const QDate &date) const
 Serialize the given date to a string representation.

Static Public Member Functions

static Q_CORE_EXPORT QDatePattern fromQtFormat (QStringView format)
 Construct a QDatePattern described by the given format string.
static QDatePattern forLocale (const QLocale &locale, QLocale::FormatType format=QLocale::LongFormat)
 Construct a QDatePattern appropriate to the given locale.

Detailed Description

A description of a serialization format for a date.

Since
6.12

Definition at line 277 of file qttemporalpattern_p.h.

Member Function Documentation

◆ baseYear()

std::optional< int > QDatePattern::baseYear ( ) const
inlinenoexcept

Definition at line 303 of file qttemporalpattern_p.h.

◆ calendar()

QCalendar QDatePattern::calendar ( ) const
inlinenoexcept

Returns the current calendar in use by this pattern.

\fn QDatePattern::setCalendar(QCalendar calendar) noexcept

! [set-calendar] Sets the calendar used by this pattern. This influences the names and lengths of months and how these vary from year to year. In some cases it may also influence the number of months in the year or even the pattern and names of days of the week.

By default the Gregorian calendar is used.

See also
getCalendar(), QCalendar ! [set-calendar]
setCalendar()

Definition at line 306 of file qttemporalpattern_p.h.

◆ clearBaseYear()

void QDatePattern::clearBaseYear ( )
inlinenoexcept

Definition at line 302 of file qttemporalpattern_p.h.

◆ forLocale()

QDatePattern QDatePattern::forLocale ( const QLocale & locale,
QLocale::FormatType format = QLocale::LongFormat )
inlinestatic

Construct a QDatePattern appropriate to the given locale.

The format can be used to select how compact or expansive the pattern is.

See also
fromQtFormat

Definition at line 314 of file qttemporalpattern_p.h.

◆ fromQtFormat()

QDatePattern QDatePattern::fromQtFormat ( QStringView format)
static

Construct a QDatePattern described by the given format string.

See also
forLocale()

Definition at line 1196 of file qttemporalpattern.cpp.

◆ isValid()

bool QDatePattern::isValid ( ) const
inlinenoexcept

Definition at line 294 of file qttemporalpattern_p.h.

References QtTemporalPattern::Clear.

◆ locale()

const QLocale & QDatePattern::locale ( ) const
inlinenoexcept

Returns the current locale in use by this pattern.

See also
setLocale()

Definition at line 299 of file qttemporalpattern_p.h.

◆ parse()

QtTemporalPattern::ParseResult< QDate > QDatePattern::parse ( QStringView text,
QDate defaults = {} ) const

Parse and return the date represented by text.

\fn QDatePattern::setBaseYear(int centuryStart) noexcept

! [set-base-year] Configures the handling of two-digit years, if any are present in the pattern.

If a two-digit year is present, the year ending in those two digits in the range from centuryStart to {centuryStart + 99} shall be its default interpretation. This may be amended if the month, day of the month and day of the week indicate some other nearby century.

Note
the years here, including centuryStart, are expressed with respect to {calendar()}, whose year numbering need not match that of the Gregorian calendar.

Calling this method makes no difference unless the pattern does in fact use a two-digit year, nor does it affect serialization.

See also
clearBaseYear() ! [set-base-year]
\fn QDatePattern::clearBaseYear() noexcept

! [clear-base-year] Leaves the handling of two-digit years to other fields to disambiguate.

This is the default state, so has no effect unless \l setBaseYear() has previously been called.

If a two-digit year is present, this leaves unspecified which hundred years to presume it lies within. If a two-digit year is present and other fields of the pattern do not suffice to make clear which hundred years to select based on the given last two digits, the text produced when serializing with this format shall generally be ambiguous. While readers of the text may be able to disambiguate the year anyway, there is scope for misunderstanding if their heuristics for doing so do not match your expectation. On parsing, the pattern may deliver a result that is off by some whole number of centuries from what the parsed text's author intended.

See also
setBaseYear(), isValid() ! [clear-base-year]
\fn QDatePattern::baseYear() const noexcept

! [get-base-year]

Returns the current base year, with respect to \c{calendar()}, used by this
pattern if it needs to resolve a two-digit year. The result is \c
{std::nullopt} when no base year is set, which is the default state.

\sa setBaseYear()

! [get-base-year]

parser-defaults

Definition at line 1164 of file qttemporalpattern.cpp.

◆ serialize()

QString QDatePattern::serialize ( const QDate & date) const

Serialize the given date to a string representation.

See also
parse()

Definition at line 1184 of file qttemporalpattern.cpp.

◆ setBaseYear()

void QDatePattern::setBaseYear ( int centuryStart)
inline

Definition at line 301 of file qttemporalpattern_p.h.

◆ setCalendar()

void QDatePattern::setCalendar ( QCalendar cal)
inline

Definition at line 305 of file qttemporalpattern_p.h.

◆ setLocale()

void QDatePattern::setLocale ( const QLocale & loc)
inline
\fn QDatePattern::isValid() const noexcept

\include qttemporalpattern.cpp {is-valid} {date}

! [base-year-disambiguates] The ambiguity of two-digit years may be resolved by configuring the hundred years among which to select a matching years. ! [base-year-disambiguates]

\sa setBaseYear()

set-locale

Definition at line 298 of file qttemporalpattern_p.h.


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