Skip to content

Commit cd1b7cd

Browse files
committed
Updates
1 parent f33cd8e commit cd1b7cd

File tree

2 files changed

+107
-7
lines changed

2 files changed

+107
-7
lines changed

projects/go-homo-sapiens-time.txt

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
Go Homo Sapiens Time is a Go package that provides utilities for converting human-readable time strings to milliseconds and vice-versa. It's a Go port of the popular JavaScript library homo-sapiens-time.
2+
---
3+
Go Homo Sapiens Time is a Go package that provides utilities for converting human-readable time strings to milliseconds and vice-versa. It's a Go port of the popular JavaScript library [homo-sapiens-time](https://github.com/fezcode/homo-sapiens-time).
4+
5+
## Installation
6+
7+
To install the package, use `go get`:
8+
9+
```bash
10+
go get github.com/fezcode/go-homo-sapiens-time
11+
```
12+
13+
## Usage
14+
15+
Here's how to use the functions provided by the package:
16+
17+
### Convert a time string to milliseconds
18+
19+
```go
20+
package main
21+
22+
import (
23+
"fmt"
24+
"github.com/fezcode/go-homo-sapiens-time"
25+
)
26+
27+
func main() {
28+
ms := homo_sapiens_time.TimeStringToMs("1h 30m")
29+
fmt.Println(ms) // Output: 5400000
30+
}
31+
```
32+
33+
### Convert milliseconds to a time string
34+
35+
```go
36+
package main
37+
38+
import (
39+
"fmt"
40+
"github.com/fezcode/go-homo-sapiens-time"
41+
)
42+
43+
func main() {
44+
timeString, err := homo_sapiens_time.MsToTimeString(5400000, nil)
45+
if err != nil {
46+
fmt.Println("Error:", err)
47+
return
48+
}
49+
fmt.Println(timeString) // Output: 1h 30m
50+
}
51+
```
52+
53+
### Add a duration to the current time
54+
55+
```go
56+
package main
57+
58+
import (
59+
"fmt"
60+
"time"
61+
"github.com/fezcode/go-homo-sapiens-time"
62+
)
63+
64+
func main() {
65+
futureTime := homo_sapiens_time.ImpreciseDurationAddedToNow("1d 2h")
66+
fmt.Println("Current time:", time.Now())
67+
fmt.Println("Future time:", futureTime)
68+
}
69+
```
70+
71+
## API
72+
73+
### `TimeStringToMs(str string) int`
74+
75+
Converts a human-readable time string (e.g., "1h 30m") into the equivalent number of milliseconds.
76+
77+
### `MsToTimeString(ms int, opts *MsToTimeStringOptions) (string, error)`
78+
79+
Converts a duration in milliseconds to a human-readable time string. The `opts` parameter allows for customization:
80+
81+
- `Auto`: If `true`, the function will automatically determine the units to use.
82+
- `Units`: A slice of strings representing the units to use (e.g., `[]string{"h", "m", "s"}`).
83+
- `ShowEmpty`: If `true`, units with a value of 0 will be included in the output.
84+
- `SortUnits`: If `true`, the units in the output string will be sorted.
85+
86+
### `ImpreciseDurationAddedToNow(str string) time.Time`
87+
88+
Adds a duration specified in a human-readable time string to the current time and returns the resulting `time.Time`.
89+
90+
### `GetMSEquivalent(unitType string, count int) int`
91+
92+
A helper function that converts a given amount of a specific time unit to milliseconds.

projects/projects.json

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@
3636
"technologies": ["Rust", "SVG"]
3737
},
3838
{
39-
"slug": "go-tournament-brackets",
40-
"title": "Go Tournament Bracket Generator Lib",
39+
"slug": "go-homo-sapiens-time",
40+
"title": "Go Homo Sapiens Time",
4141
"size": 1,
42-
"link": "https://github.com/fezcode/go-tournament-brackets",
42+
"link": "https://github.com/fezcode/go-homo-sapiens-time",
4343
"pinned": false,
4444
"isActive": true,
4545
"technologies": ["Go"]
@@ -53,16 +53,24 @@
5353
"isActive": false,
5454
"technologies": ["JavaScript"]
5555
},
56+
{
57+
"slug": "go-tournament-brackets",
58+
"title": "Go Tournament Bracket Generator Lib",
59+
"size": 2,
60+
"link": "https://github.com/fezcode/go-tournament-brackets",
61+
"pinned": false,
62+
"isActive": true,
63+
"technologies": ["Go"]
64+
},
5665
{
5766
"slug": "open-tab-with-respect",
5867
"title": "Open Tab with Respect",
59-
"size": 2,
68+
"size": 1,
6069
"link": "https://github.com/fezcode/open-tab-with-respect",
6170
"pinned": false,
6271
"isActive": true,
6372
"technologies": ["WebExtension", "JavaScript", "Firefox", "HTML", "CSS"]
6473
},
65-
6674
{
6775
"slug": "clipboard-concat",
6876
"title": "Clipboard Concat",
@@ -84,10 +92,10 @@
8492
{
8593
"slug": "firefox-themes",
8694
"title": "Firefox Themes",
87-
"size": 1,
95+
"size": 3,
8896
"link": "https://github.com/fezcode",
8997
"pinned": false,
9098
"isActive": false,
9199
"technologies": ["WebExtension", "JavaScript", "Firefox", "HTML", "CSS"]
92100
}
93-
]
101+
]

0 commit comments

Comments
 (0)