Giter VIP home page Giter VIP logo

Comments (2)

aekiss avatar aekiss commented on July 4, 2024

Just a thought - would it be more error-tolerant to use >= rather than == in these adjustments, then subtracting off the factor? Otherwise it assumes rollovers of exactly 1. I guess that should always be the case, but there's probably no harm in coding more defensively...
https://github.com/wavebitscientific/datetime-fortran/blob/master/src/lib/mod_datetime.f90#L1225-L1241

I'm suggesting something like

  if(num2date % millisecond >= 1000)then
    num2date % millisecond = num2date % millisecond - 1000
    call num2date % addSeconds(1)
  endif

  if(num2date % second >= 60)then
    num2date % second = num2date % second - 60
    call num2date % addMinutes(1)
  endif
  if(num2date % minute >= 60)then
    num2date % minute = num2date % minute - 60
    call num2date % addHours(1)
  endif
  if(num2date % hour >= 24)then
    num2date % hour = num2date % hour - 24
    call num2date % addDays(1)
  endif

(which will still mess up if the rollover is huge)

from datetime-fortran.

milancurcic avatar milancurcic commented on July 4, 2024

You are correct, it should compare with 24, not 60. I also like the defensive approach by @aekiss. Do either of you mind submitting a PR?

from datetime-fortran.

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.