Git Product home page Git Product logo

Comments (2)

dmitshur avatar dmitshur commented on June 29, 2024

This came up in the past as:

from go-humanize.

dustin avatar dustin commented on June 29, 2024

Perhaps it would be good to understand why go only rolls up to the nearest hour. I suppose if we're approximating, we can throw away precision and be fairly loose with what a day is. This seems consistent with the idea of humanization.

Formatting is the hard part here. I suspect we'd want a data-driven language for formatting strings, e.g., one would like to express the example above as:

humanize.Duration("%y %m %w %d %H %M %S", d)

where the variables, e.g. %d expands into one of three string segments based on cardinality:

0: ""
1: "1 day"
n: n + " days"

The formatting table is fairly straightforward, but space consumption might be slightly tricky. In our case here, we'd want to consume any whitespace around the zero case, as it is effectively a lexical black hole absorbing the space made for time units that aren't relevant for its case.

An optional operator might cause the 0 case to be treated as the n case (or just supply a modified expansion table). This depends on how interesting such a case is.

from go-humanize.

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.