本文整理汇总了C++中QDateTime::offsetFromUtc方法的典型用法代码示例。如果您正苦于以下问题:C++ QDateTime::offsetFromUtc方法的具体用法?C++ QDateTime::offsetFromUtc怎么用?C++ QDateTime::offsetFromUtc使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDateTime
的用法示例。
在下文中一共展示了QDateTime::offsetFromUtc方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: copyTimeSpec
void AbstractDateTime::copyTimeSpec(const QDateTime &from,
QDateTime &to)
{
switch(from.timeSpec())
{
case Qt::UTC:
/* Fallthrough. */
case Qt::LocalTime:
{
to.setTimeSpec(from.timeSpec());
return;
}
case Qt::OffsetFromUTC:
{
to.setOffsetFromUtc(from.offsetFromUtc());
Q_ASSERT(to.timeSpec() == Qt::OffsetFromUTC);
return;
}
case Qt::TimeZone:
{
to.setTimeZone(from.timeZone());
return;
}
}
}
示例2: filterAcceptsRow
bool SortFilterModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
{
if (filterRole() == "fromNow" && sourceModel()->roleNames().values().contains("start")) {
QModelIndex index = sourceModel()->index(source_row, 0, source_parent);
QDateTime date = sourceModel()->data(index, sourceModel()->roleNames().key("start")).toDateTime();
QDateTime currentDateTime = QDateTime::currentDateTime();
int localTimeZoneOffset = currentDateTime.offsetFromUtc();
currentDateTime.setMSecsSinceEpoch(currentDateTime.currentMSecsSinceEpoch() + localTimeZoneOffset*1000);
return date >= currentDateTime;
} else {
if (m_hide && sourceModel()->roleNames().values().contains("hideInSchedule")) {
QModelIndex index = sourceModel()->index(source_row, 0, source_parent);
bool willBeHidden = sourceModel()->data(index, sourceModel()->roleNames().key("hideInSchedule")).toBool();
if (willBeHidden)
return false;
}
return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
}
}
示例3:
template <> RubyValue Conversion<QDateTime>::to(const QDateTime &dateTime)
{
RubyValue sec = rb_rational_new(RubyValue::from(dateTime.toMSecsSinceEpoch()), RubyValue::from(1000));
RubyValue time = rb_time_num_new(sec, RubyValue::from(dateTime.offsetFromUtc()));
return time.send(RUBYQML_INTERN("to_datetime"));
}
示例4: if
//.........这里部分代码省略.........
int64_t domainLoNSecs = this->domainLo % MILLISECOND_NS;
if (domainLoNSecs < 0)
{
domainLoMSecs -= 1;
domainLoNSecs += MILLISECOND_NS;
}
int64_t starttime, prevstart;
switch(granularity)
{
case Timescale::YEAR:
{
int yeardelta = (int) (deltatick / YEAR_NS);
Q_ASSERT((deltatick % YEAR_NS) == 0);
QDateTime date = QDateTime::fromMSecsSinceEpoch(domainLoMSecs - 1, this->tz);
int curryear = ceildiv(date.date().year(), yeardelta) * yeardelta;
date.setDate(QDate(curryear, 1, 1));
date.setTime(QTime());
if (domainLoMSecs == date.toMSecsSinceEpoch() && domainLoNSecs > 0)
{
date = date.addYears(yeardelta);
}
/* TODO: this multiplication might overflow */
starttime = date.toMSecsSinceEpoch() * MILLISECOND_NS;
prevstart = starttime;
/* This is the lowest granularity, so we need to check for overflow. */
while (starttime <= this->domainHi && starttime >= prevstart)
{
ticks.append({ starttime, getTimeTickLabel(starttime, date, granularity, !this->promoteTicks) });
date = date.addYears(yeardelta);
prevstart = starttime;
starttime = date.toMSecsSinceEpoch() * MILLISECOND_NS;
}
break;
}
case Timescale::MONTH:
{
int monthdelta = (int) (deltatick / MONTH_NS);
Q_ASSERT((deltatick % MONTH_NS) == 0);
QDateTime date = QDateTime::fromMSecsSinceEpoch(domainLoMSecs - 1, this->tz);
date.setTime(QTime());
/* currmonth is an int from 0 to 11. */
int currmonth = ceildiv(date.date().month() - 1, monthdelta) * monthdelta;
int curryear = date.date().year() + (currmonth / 12);
currmonth %= 12;
date.setDate(QDate(curryear, currmonth + 1, 1));
date.setTime(QTime());
if (domainLoMSecs == date.toMSecsSinceEpoch() && domainLoNSecs > 0)
{
date = date.addMonths(monthdelta);
}
starttime = date.toMSecsSinceEpoch() * (int64_t) MILLISECOND_NS;
prevstart = starttime;
while (starttime <= this->domainHi && starttime >= prevstart)
{
ticks.append({ starttime, getTimeTickLabel(starttime, date, granularity, !this->promoteTicks) });
date = date.addMonths(monthdelta);
prevstart = starttime;
starttime = date.toMSecsSinceEpoch() * (int64_t) MILLISECOND_NS;
}
break;
}
default:
starttime = ceildiv(this->domainLo, (int64_t) deltatick) * deltatick;
if (granularity == Timescale::DAY || granularity == Timescale::HOUR)
{
/* I'm assuming that the timezone offset is never in smaller granularity than minutes. */
QDateTime d = QDateTime::fromMSecsSinceEpoch(ceildiv(starttime, MILLISECOND_NS), this->tz);
starttime -= SECOND_NS * (int64_t) d.offsetFromUtc();
while (starttime > this->domainLo)
{
starttime -= deltatick;
}
while (starttime < this->domainLo)
{
starttime += deltatick;
}
}
prevstart = starttime;
while (starttime <= this->domainHi && starttime >= prevstart) {
// Add the tick to ticks
QDateTime date = QDateTime::fromMSecsSinceEpoch(ceildiv(starttime, MILLISECOND_NS), this->tz);
ticks.append({ starttime, getTimeTickLabel(starttime, date, granularity, !this->promoteTicks) });
prevstart = starttime;
starttime += deltatick;
}
break;
}
return ticks;
}