Exemplo n.º 1
0
String BaseDateAndTimeInputType::serializeWithComponents(const DateComponents& date) const
{
    Decimal step;
    if (!element()->getAllowedValueStep(&step))
        return date.toString();
    if (step.remainder(msecPerMinute).isZero())
        return date.toString(DateComponents::None);
    if (step.remainder(msecPerSecond).isZero())
        return date.toString(DateComponents::Second);
    return date.toString(DateComponents::Millisecond);
}
DateTimeNumericFieldElement::Step DateTimeEditBuilder::createStep(double msPerFieldUnit, double msPerFieldSize) const
{
    const Decimal msPerFieldUnitDecimal(static_cast<int>(msPerFieldUnit));
    const Decimal msPerFieldSizeDecimal(static_cast<int>(msPerFieldSize));
    Decimal stepMilliseconds = stepRange().step();
    ASSERT(!msPerFieldUnitDecimal.isZero());
    ASSERT(!msPerFieldSizeDecimal.isZero());
    ASSERT(!stepMilliseconds.isZero());

    DateTimeNumericFieldElement::Step step(1, 0);

    if (stepMilliseconds.remainder(msPerFieldSizeDecimal).isZero())
        stepMilliseconds = msPerFieldSizeDecimal;

    if (msPerFieldSizeDecimal.remainder(stepMilliseconds).isZero() && stepMilliseconds.remainder(msPerFieldUnitDecimal).isZero()) {
        step.step = static_cast<int>((stepMilliseconds / msPerFieldUnitDecimal).toDouble());
        step.stepBase = static_cast<int>((stepRange().stepBase() / msPerFieldUnitDecimal).floor().remainder(msPerFieldSizeDecimal / msPerFieldUnitDecimal).toDouble());
    }
    return step;
}