Giter Site home page Giter Site logo

Teach -x time unit shortcuts about pbpst HOT 11 CLOSED

tmplt avatar tmplt commented on September 15, 2024
Teach -x time unit shortcuts

from pbpst.

Comments (11)

HalosGhost avatar HalosGhost commented on September 15, 2024

Okay, here's where this gets dicey: how complex are you hoping the sufficies to be?

e.g., are you hoping to be able to say -x 3h22m12s, -x 3.75h or will allowing only whole numbers and a single suffix be sufficient?

If the restriction of a single suffix and an integer value is acceptable, then this does not bother me at all, and it should not take long to implement. If you are hoping for more complex values, this could be a rabbit-hole of parsing.

from pbpst.

tmplt avatar tmplt commented on September 15, 2024

A single suffix and integer is enough for my usages.

For more complex sunsets like -x 3.75h -x $(bc <<< "3.75 * 60 ^ 2" could be used — which does print it as a float; I'm unsure if pbpst truncates to int. If it doesn't, perhaps it could ignore the floating part (e.g. interpret 3.75 as 3) instead of having to create a trivial wrapper script?

from pbpst.

HalosGhost avatar HalosGhost commented on September 15, 2024

It should, at the moment, truncate (we use scanf()).

One other consideration: I suspect the sufficies I will support will be the following: d(ays), h(ours), m(inutes), s(econds).

However, all of the sufficies (other than seconds) would actually just be a shortcut for seconds (e.g., 1d == 86400s which is not, strictly speaking, true). Is that amenable? Dealing with time in an accurate fashion is incredibly difficult, so it should just be known that these units are not “correct”, they are just shorthand for seconds.

from pbpst.

tmplt avatar tmplt commented on September 15, 2024

I'm not entirely use what you mean. A day (and night) is 24 which is 24 * 60 ^ 2 == 86400s; is that not accurate?

from pbpst.

HalosGhost avatar HalosGhost commented on September 15, 2024

Not quite; things like leap seconds tend to throw a wrench in the mix.

For a list of things that devs often assume incorrectly about time, see this article.

from pbpst.

tmplt avatar tmplt commented on September 15, 2024

I see. Well, I'm okay with that caveat.

from pbpst.

HalosGhost avatar HalosGhost commented on September 15, 2024

All right; in that case, this should not be difficult to do.

from pbpst.

HalosGhost avatar HalosGhost commented on September 15, 2024

@tmplt, a20ed59 adds this functionality.

It scans for a double, but casts to an int, so it will truncate the value; in addition, it only checks for a single character, which means anything following that is ignored.

$ pbpst -S#f somefile -x 5m

This means that the above will set a sunset 300 seconds into the future and is exactly the same as this:

$ pbpst -S#f somefile -x 5.7min

Finally, to remain backwards compatible, and to gracefully fallback to something sensible, if you pass an unexpected unit, or you pass no unit at all, pbpst assumes you meant seconds.

Can you test this and make sure it works the way you expect? I will then document it and close the issue.

from pbpst.

tmplt avatar tmplt commented on September 15, 2024

It works as expected. Thank you!

from pbpst.

HalosGhost avatar HalosGhost commented on September 15, 2024

Good to hear it. I am going to change a bit of the implementation to be safer (casting from a double to an int without a few checks is a BadIdea™), and simpler (deduplicating some code). But it should not change the behavior.

I will push the documentation and updates tonight.

from pbpst.

HalosGhost avatar HalosGhost commented on September 15, 2024

ad45d65 closes this issue.

@tmplt, one extra thing to note; I changed the cast to unsigned to take place a moment later which means that instead of truncating the count before the multiplier, it will truncate afterwards.

i.e., 5.5m == 330 rather than 300. I would suspect this is actually preferred,

from pbpst.

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.