dart-lang / i18n

A general mono-repo for Dart i18n and l10n packages.
BSD 3-Clause "New" or "Revised" License
58 stars 34 forks source link

Deincrementing a date, then formatting it causes this library to count back up #828

Closed s1nistr4 closed 2 months ago

s1nistr4 commented 2 months ago
    void initState() {
        super.initState();

        setState(() {
            DateFormat f = DateFormat("SS");

            internalTime = widget.startDate;
            displayedTime = f.format(internalTime);
        });

        Timer.periodic(new Duration(seconds: 1), (timer) {
            setState(() {
                DateFormat f = DateFormat("SS");

                DateTime deIncrement = internalTime.subtract(new Duration(seconds: 1));
                print(deIncrement);
                print(f.format(deIncrement));

                internalTime = deIncrement;
                displayedTime = f.format(deIncrement);
            });
        });

Doing this will make the format inherit the previous time and keep it the same instead of properly deincrementing it.

mosuem commented 2 months ago

The pattern S denotes fractional seconds. You probably want to use s for seconds, see the docs.