• Stars
    star
    391
  • Rank 110,003 (Top 3 %)
  • Language
    Go
  • License
    MIT License
  • Created almost 3 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Go library for printing human readable, relative time differences πŸ•°οΈ

Go Reference Go Report Card CI codecov

timediff

timediff is a Go package for printing human readable, relative time differences. Output is based on ranges defined in the Day.js JavaScript library, and can be customized if needed. It's currently used by the mergestat command-line interface.

go get github.com/mergestat/timediff
import (
    "github.com/mergestat/timediff"
)
str1 := timediff.TimeDiff(time.Now().Add(-10 * time.Second))
fmt.Println(str1) // a few seconds ago

str2 := timediff.TimeDiff(time.Now().Add(-3 * time.Minute))
fmt.Println(str2) // 3 minutes ago

str3 := timediff.TimeDiff(time.Now().Add(-23 * time.Hour))
fmt.Println(str3) // a day ago

str4 := timediff.TimeDiff(time.Now().Add(23 * time.Hour))
fmt.Println(str4) // in a day

str5 := timediff.TimeDiff(time.Now().Add(10 * time.Hour))
fmt.Println(str5) // in 10 hours
str := timediff.TimeDiff(time.Now().Add(-3 * time.Minute), timediff.WithLocale("pt-BR"))
fmt.Println(str) // 3 minutos atrΓ‘s

Here are examples of durations and their corresponding string outputs (taken from test output), using default options:

-864000h   100 years ago
-172800h   20 years ago
-17280h    2 years ago
-8640h     a year ago
-7200h1m   a year ago
-7200h     10 months ago
-6480h     9 months ago
-1920h     3 months ago
-1104h     2 months ago
-1080h     a month ago
-624h      a month ago
-600h      25 days ago
-240h      10 days ago
-36h       2 days ago
-24h       a day ago
-22h       a day ago
-21h30m    a day ago
-21h       21 hours ago
-20h       20 hours ago
-2h        2 hours ago
-90m       2 hours ago
-89m       an hour ago
-80m       an hour ago
-1h        an hour ago
-60m       an hour ago
-45m       an hour ago
-44m       44 minutes ago
-10m       10 minutes ago
-2m        2 minutes ago
-90s       2 minutes ago
-89s       a minute ago
-45s       a minute ago
-44s       a few seconds ago
-10s       a few seconds ago
10s        in a few seconds
44s        in a few seconds
45s        in a minute
89s        in a minute
90s        in 2 minutes
2m         in 2 minutes
10m        in 10 minutes
44m        in 44 minutes
45m        in an hour
60m        in an hour
1h         in an hour
80m        in an hour
89m        in an hour
90m        in 2 hours
2h         in 2 hours
20h        in 20 hours
21h        in 21 hours
21h30m     in a day
22h        in a day
24h        in a day
36h        in 2 days
240h       in 10 days
600h       in 25 days
624h       in a month
1080h      in a month
1104h      in 2 months
1920h      in 3 months
6480h      in 9 months
7200h      in 10 months
7200h1m    in a year
8640h      in a year
17280h     in 2 years
172800h    in 20 years
864000h    in 100 years

More Repositories

1

mergestat-lite

Query git repositories with SQL. Generate reports, perform status checks, analyze codebases. πŸ” πŸ“Š
Go
3,449
star
2

mergestat

MergeStat enables anyone to ask questions about the history and contents of source code.
TypeScript
461
star
3

scribe

Command line interface for translating natural language prompts into SQL queries using the OpenAI API
Go
34
star
4

treequery

Run Tree-sitter queries on source code
Go
24
star
5

fluentgraphql

Fluent GraphQL client library in Golang
Go
20
star
6

go-mysql-sqlite-server

Experimental implementation of a SQLite backend for go-mysql-server
Go
18
star
7

termbar

Generate terminal charts in Go πŸ“Š
Go
18
star
8

dblite

SQLite extension for accessing other SQL databases, in SQLite
Go
11
star
9

pqueue

Go library for using PostgreSQL as a job queue
Go
7
star
10

gitutils

Golang library for programmatically working with the git command (via the os/exec package).
Go
7
star
11

mysql-server

Query git repositories as MySQL
Go
6
star
12

mergestat-git-dbt

Example dbt project showcasing various uses of git stats data from MergeStat
6
star
13

kyc

kyc is a tool for deriving facts about source code in a git repo
Go
6
star
14

syncs

MergeStat container based syncs
TypeScript
5
star
15

helm-charts

Helm charts for MergeStat capabilities
Smarty
4
star
16

blocks

Mergestat UI Components
TypeScript
4
star
17

gitgoperfs

For comparing the relative performance of interacting with git from go using go-git, git2go and parsing output of the git command.
Go
4
star
18

git-delivery

Serve files from git repositories over HTTP
Go
4
star
19

haystack

Haystack (as in, "finding a needle in a haystack") is a Go library for searching the contents of git repositories, backed by SQLite.
Go
3
star
20

sqlq

sqlq is a SQL-backed, persistent, job queuing solution.
Go
2
star
21

sqlc-compile-bug

1
star
22

fuse-examples-screenshots

1
star
23

docs

MergeStat documentation site
JavaScript
1
star
24

homebrew-mergestat

Brew Formula for the MergeStat CLI
Ruby
1
star
25

homebrew-treequery

Ruby
1
star
26

askgit-docs

1
star
27

blocks-legacy

React UI kit for MergeStat web interfaces
TypeScript
1
star
28

broker-proto

gRPC protobuf for the MergeStat broker
Go
1
star
29

bulk

CLI for running bulk actions (ad-hoc scripts) on sets of Git repositories
Go
1
star
30

homebrew-scribe

Ruby
1
star