-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
73 lines (56 loc) · 1.39 KB
/
Copy pathconfig.go
File metadata and controls
73 lines (56 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright 2023 Bill Nixon. All rights reserved.
// Use of this source code is governed by the license found in the LICENSE file.
package main
import (
"fmt"
"time"
"github.com/bnixon67/webapp/webauth"
)
// Config represents the overall application configuration.
type Config struct {
webauth.Config // Inherit webapp.Config
}
const timeLayout = "2006-01-02 15:04:05 MST"
func (app *BidApp) GetTimeConfig(name string) (time.Time, error) {
var t time.Time
ci, err := app.BidDB.GetConfigItem(name)
if err != nil {
return t, err
}
// TODO: define config variable for timezone
loc, err := time.LoadLocation("America/Chicago")
if err != nil {
return t, err
}
t, err = time.ParseInLocation(timeLayout, ci.Value, loc)
if err != nil {
return t, err
}
return t, err
}
func (app *BidApp) ConfigAuction() error {
var err error
s := "auction_start"
app.AuctionStart, err = app.GetTimeConfig(s)
if err != nil {
return fmt.Errorf("%q %w", s, err)
}
s = "auction_end"
app.AuctionEnd, err = app.GetTimeConfig(s)
if err != nil {
return fmt.Errorf("%q %w", s, err)
}
return err
}
func (app *BidApp) IsAuctionStarted() bool {
return time.Now().After(app.AuctionStart)
}
func (app *BidApp) IsAuctionEnded() bool {
return time.Now().After(app.AuctionEnd)
}
func (app *BidApp) IsAuctionOpen() bool {
if app.IsAuctionStarted() && !app.IsAuctionEnded() {
return true
}
return false
}