33 lines
576 B
Go
33 lines
576 B
Go
|
package vote
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
type Vote struct {
|
||
|
Elector string
|
||
|
Choice Choice
|
||
|
timestamp time.Time
|
||
|
}
|
||
|
|
||
|
func NewVote(elector string, choice Choice) Vote {
|
||
|
return Vote{
|
||
|
Elector: elector,
|
||
|
Choice: choice,
|
||
|
timestamp: time.Now().UTC(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func NewVoteWithTimestamp(elector string, choice Choice, timestamp time.Time) Vote {
|
||
|
return Vote{
|
||
|
Elector: elector,
|
||
|
Choice: choice,
|
||
|
timestamp: timestamp,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (vote Vote) String() string {
|
||
|
return fmt.Sprintf("%s %s %s", vote.timestamp.Format(time.DateTime), vote.Choice, vote.Elector)
|
||
|
}
|