Comments (10)
How would you specify it?
Unless you have a good proposal to do this, it seems like it's be shorter to simply implement what you want yourself in your project, custom for your needs. As an example, I wanted something like humanize.Time
except to have it always say "less than a minute ago" for time spans of less than a minute. I just wrote it, the func was 4 lines of code.
from go-humanize.
Also, have you seen humanize.RelTime
? It lets you specify custom labels for times that earlier and later.
from go-humanize.
@shurcooL - Thanks! Accutally I want something like '12s ago' or '21 days'(I don't want to use week
) . I've wrote the code and will submit a PR for it.
from go-humanize.
I'd like this as well, seems to be a common mistake that libs like this append "ago".
EDIT: just saw the RelTime comment haha. That works. Wouldn't mind having humanize.Duration(n)
with no "ago", then you can easily have Resolved in %s
-> Resolved in 5 minutes
etc, letting the dev append whatever is appropriate for their domain.
from go-humanize.
@tj, humanize.Duration(n)
sounds reasonable to me at a surface glance. But please run that proposal by @dustin. It's really hard to control feature-creep in the API of this library. We still haven't even merged #26 after all this time.
from go-humanize.
Hmm actually on second thought I do think it would be nice, I just got bit by it adding the opinionated "now" for tiny deltas.
from go-humanize.
I'll send up a PR in a few minutes.
On Wed, Apr 20, 2016 at 5:21 PM TJ Holowaychuk [email protected]
wrote:
Hmm actually on second thought I do think it would be nice, I just got bit
by it adding the opinionated "now" for tiny deltas—
You are receiving this because you were mentioned.Reply to this email directly or view it on GitHub
#25 (comment)
from go-humanize.
Sorry, took me a bit more than a couple of minutes to get off the bus, but I think this may do what you want.
In particular:
- Arbitrary ranges.
- Nanosecond precision.
The first one was I think what was being asked for in particular.
The second is required because the way it was implemented rounded everything to seconds. The general vision of RelTime
was to show time for humans on a page where things are meant to be presented in human scales. time.Duration.String()
seems well suited for the rest of these cases, but there are plenty of reasons to allow people to specify their own arbitrary boundaries.
from go-humanize.
Understandable. I was thinking it could be something like:
func Time(t time.Time) string {
if t.Before(time.Now()) {
return Duration(time.Now().Sub(t)) + " ago"
} else {
return Duration(t.Sub(time.Now())) + " from now"
}
}
Then if you have a different domain like mine where you'd just like to say "Resolved in X minutes" or similar it's no problem, no strings.Trim()
required with RelTime
.
from go-humanize.
I guess for my case rounding up or down entire hours etc is not precise enough anyway haha, but hey 😄
from go-humanize.
Related Issues (20)
- Bytes returns 32 MB for 31450000 bytes instead of 31 MB HOT 2
- How to convert decimal to million or billion formats? HOT 1
- Force to show decimal in CommafWithDigits HOT 1
- Lost zeros using SIWithDigits with 0 decimals 200.0 becomes "2" HOT 5
- New git tags? HOT 1
- Set github workflow permissions to read only HOT 1
- RFE: Add unit-specific Byte/IByte
- Create a Security Policy
- Hash Pin Dependencies and Dependency Update tool HOT 3
- Incorrect year length HOT 1
- [Feature Request] FormatFloatNoTrailingZero
- Option to elide space between value and units HOT 1
- Option to force sub-whole digits for whole inputs HOT 1
- Comma should be Thousands separator HOT 3
- PluralWord should return singular word with a 0 quantity HOT 3
- Allow to skip trailing spaces in humanize.RelTime
- Tag releases to support go.mod semantic versioning HOT 1
- Added `ComputeBytes` and `ComputeIBytes`
- [Feature Request] Support localization in Time HOT 1
- money notation
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-humanize.