-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Fix display time of milestones #18753
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
db7c4a7
Fix display time of milestones
schorsch13 0130bed
Move the SecToTime function
schorsch13 fecd959
Rename the sec_to_time file
schorsch13 268f28d
Updated formatting
schorsch13 449f5cc
Include copyright notice in sec_to_time.go
schorsch13 5090a37
Apply PR review suggestions
schorsch13 f0cf5c3
Rename hrs var and combine conditions
schorsch13 67efab5
Update unit tests to match new time pattern
schorsch13 b19873e
Merge branch 'main' into fix/milestone-update-time
lunny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright 2021 Gitea. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package util | ||
|
||
import ( | ||
"fmt" | ||
) | ||
schorsch13 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// SecToTime converts an amount of seconds to a human-readable string (example: 66s -> 1min 6s) | ||
func SecToTime(duration int64) string { | ||
schorsch13 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
seconds := duration % 60 | ||
minutes := (duration / (60)) % 60 | ||
hours := duration / (60 * 60) % 24 | ||
days := duration / (60 * 60) / 24 | ||
|
||
var hrs string | ||
schorsch13 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if days > 1 { | ||
hrs = fmt.Sprintf("%d days", days) | ||
} else { | ||
hrs = fmt.Sprintf("%d day", days) | ||
} | ||
if hours > 0 { | ||
if days == 0 { | ||
schorsch13 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
hrs = fmt.Sprintf("%dh", hours) | ||
} else { | ||
hrs = fmt.Sprintf("%s %dh", hrs, hours) | ||
} | ||
} | ||
if minutes > 0 { | ||
if days == 0 && hours == 0 { | ||
hrs = fmt.Sprintf("%dmin", minutes) | ||
} else { | ||
hrs = fmt.Sprintf("%s %dmin", hrs, minutes) | ||
} | ||
} | ||
if seconds > 0 { | ||
if days == 0 && hours == 0 && minutes == 0 { | ||
hrs = fmt.Sprintf("%ds", seconds) | ||
} else { | ||
hrs = fmt.Sprintf("%s %ds", hrs, seconds) | ||
} | ||
} | ||
|
||
return hrs | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright 2021 Gitea. All rights reserved. | ||
schorsch13 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package util | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestSecToTime(t *testing.T) { | ||
assert.Equal(t, SecToTime(10), "10s") | ||
assert.Equal(t, SecToTime(100), "1min 40s") | ||
assert.Equal(t, SecToTime(1000), "16min 40s") | ||
assert.Equal(t, SecToTime(10000), "2h 46min 40s") | ||
assert.Equal(t, SecToTime(100000), "1 day 3h 46min 40s") | ||
assert.Equal(t, SecToTime(1000000), "11 days 13h 46min 40s") | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.