haskell / time

A time library
http://hackage.haskell.org/package/time
Other
120 stars 80 forks source link

Incredibly poor name for nominalDiffTimeToSeconds #127

Closed erikd closed 4 years ago

erikd commented 4 years ago

This function:

nominalDiffTimeToSeconds :: NominalDiffTime -> Pico

is incredibly poorly named. It would be better named nominalDiffTimeToPico.

AshleyYakeley commented 4 years ago

nominalDiffTimeToPico is no good, because it doesn't tell you how much you'll get for your time.

nominalDiffTimeToSeconds gives you 1 for each second of time.

erikd commented 4 years ago

I actually can't even use nominalDiffTimeToSeconds because I am still on time-1.8. HOwever, reading the name and the type I still have zero idea of what it is actually going to do.

Using the time-1.8 is pretty painful too. I can use diffUTCTime which returns NominalDiffTime. However, with 1.8 there does not seem to be any way to create a guaranteed correct NominalDiffTime from a constant. Of course fromIntegral is available, but that can't create time differences of less than 1 second.

After spending way more time than I should have to do something that should be incredibly simple, I ended up using fromRational to get some that was actually correct. The types in the time library prevented some mistakes (by hiding type constructors) but encouraged other mistakes like using fromIntegral.

AshleyYakeley commented 4 years ago

nominalDiffTimeToSeconds returns the amount of seconds in a NominalDiffTime.

Going the other direction, if you want to create a NominalDiffTime from a given number of seconds, use secondsToNominalDiffTime. For example, secondsToNominalDiffTime 0.5 gives you a NominalDiffTime of 0.5 seconds.

This seems really straightforward to me.

erikd commented 4 years ago

The function secondsToNominalDiffTime does not exist in time-1.8 which introduced NominalDiffTime with only a tiny number of useful functions to operate on it.

AshleyYakeley commented 4 years ago

Just to clarify, you are reporting an issue that you already know has been fixed in the latest version, is that correct?

What do you hope to achieve by this?

erikd commented 4 years ago

I still think nominalDiffTimeToSeconds is confusing and misleading. I was hoping that would be improved or corrected before regular people like me try to use it.

AshleyYakeley commented 4 years ago

It gets the number of seconds in a NominalDiffTime. What else would it be called?