Coder Social home page Coder Social logo

Comments (4)

rdelgatte avatar rdelgatte commented on June 26, 2024

FYI this happened since we migrated from lts-14.16 to resolver: lts-15.0

from cron.

sir4ur0n avatar sir4ur0n commented on June 26, 2024

After some investigation:
I think the problem is in System.Cron.Schedule.findNextMinuteDelay, in particular on this line:

m     = (read (formatTime defaultTimeLocale fmtMinutes now) :: Int) + 1

If the current minute is 59, then this returns 60 (thanks Captain Obvious!).

Now the interesting bit:

-- With time-1.8.0.2
λ> parseTimeOrError True defaultTimeLocale "%F %H:%M" "2020-02-26 17:60" :: UTCTime
2020-02-26 18:00:00 UTC
it :: UTCTime
-- With time-1.9.3
λ> parseTimeOrError True defaultTimeLocale "%F %H:%M" "2020-02-26 17:60" :: UTCTime
*** Exception: parseTimeOrError: no parse of "2020-02-26 17:60"
CallStack (from HasCallStack):
  error, called at libraries/time/lib/Data/Time/Format/Parse.hs:82:12 in time-1.9.3:Data.Time.Format.Parse

The behavior changed in time library!

Proposal:

  • Extract the pure function so that it's testable in isolation (and actually add tests 😆 )
findNextMinuteDelay :: IO (UTCTime, Int)
findNextMinuteDelay = getCurrentTime >>= findNextMinuteDelay'

findNextMinuteDelay' :: UTCTime -> (UTCTime, Int)
findNextMinuteDelay' now = ...
  • Simplify this function by:
    • Relying on addUTCTime to first add a minute to now. This will be simpler and correctly handle the "off by 1" problem for 60 minutes
    • Manipulating seconds (numbers) instead of parsing
oneMinute :: NominalDiffTime
oneMinute = 60

addUTCTime oneMinute now

How does that sound?

Thank you!

If you (@MichaelXavier) are ok with this proposal, we (me or someone in my team) can try to propose a PR to apply those changes (but it would still be your duty to publish a new release to fix this bug).

Please let us know!

from cron.

MichaelXavier avatar MichaelXavier commented on June 26, 2024

@sir4ur0n I'd take that PR. Thanks for planning that out and stepping up to fix 😁

from cron.

paolino avatar paolino commented on June 26, 2024

good, maybe we can have it in for lts-15.3 ?
Nice work anyway removing partial parsing!

from cron.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.