Skip to content

Commit

Permalink
Fix Week of Code description being wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
diamondburned committed Mar 19, 2024
1 parent d27c9e0 commit ef33e5e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
36 changes: 36 additions & 0 deletions server/frontend/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/Masterminds/sprig/v3"
"github.com/dustin/go-humanize"
"github.com/dustin/go-humanize/english"
"github.com/yuin/goldmark"
"libdb.so/tmplutil"
)
Expand Down Expand Up @@ -66,7 +67,42 @@ func NewTemplater(fs fs.FS) *tmplutil.Templater {
int(d.Seconds())%60)
}
},
"humanizeDuration": func(d time.Duration) string {
plural0 := func(n int, singular, plural string) string {
if n == 0 {
return ""
}
return english.Plural(n, singular, plural)
}

join := func(s ...string) string {
ss := s[:0]
for _, v := range s {
if v != "" {
ss = append(ss, v)
}
}
return strings.Join(ss, " ")
}

switch {
case d < time.Second:
return "now"
case d < time.Minute:
return plural0(int(d.Seconds()), "second", "seconds")
case d < time.Hour:
return join(
plural0(int(d.Minutes()), "minute", "minutes"),
plural0(int(d.Seconds())%60, "second", "seconds"))
default:
return join(
plural0(int(d.Hours()), "hour", "hours"),
plural0(int(d.Minutes())%60, "minute", "minutes"),
plural0(int(d.Seconds())%60, "second", "seconds"))
}
},
"ordinal": humanize.Ordinal,
"plural": english.Plural,
},
),
}
Expand Down
7 changes: 5 additions & 2 deletions server/frontend/pages/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ <h2>Week of Code</h2>
skills.
</p>
<p>
A new problem opens everyday at midnight (PST). Solve problems online or in-person with your
team!
{{ if .Problems.Schedule }}
A new problem opens up every
<b>{{ humanizeDuration .Problems.Schedule.ReleaseEvery }}</b>.
{{ end }}
Solve problems online or in-person with your team!
</p>

<div class="grid">
Expand Down
6 changes: 6 additions & 0 deletions server/problem/problemset.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ func NewProblemSetWithSchedule(problems []Problem, schedule *ProblemReleaseSched
}
}

// Schedule returns the release schedule of the problem set. If the problem set
// does not have a release schedule, it returns nil.
func (p *ProblemSet) Schedule() *ProblemReleaseSchedule {
return p.schedule
}

// StartedAt returns the time at which the first problem is released. If the
// problem set does not have a release schedule, it returns the zero time.
func (p *ProblemSet) StartedAt() time.Time {
Expand Down

0 comments on commit ef33e5e

Please sign in to comment.