Initial import
This commit is contained in:
33
protocol/aprs/time.go
Normal file
33
protocol/aprs/time.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package aprs
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
type TimeFormatError struct {
|
||||
Time string
|
||||
}
|
||||
|
||||
func (err TimeFormatError) Error() string {
|
||||
return fmt.Sprintf("aprs: unknown time stamp %q", err.Time)
|
||||
}
|
||||
|
||||
func ParseTime(s string) (time.Time, error) {
|
||||
if len(s) < 7 {
|
||||
return time.Time{}, TimeFormatError{s}
|
||||
}
|
||||
|
||||
switch {
|
||||
case s[6] == 'z': // Day/Hours/Minutes (DHM) format
|
||||
return time.Parse("021504", s[:6])
|
||||
case s[6] == '/': // Day/Hours/Minutes (DHM) format
|
||||
return time.Parse("021504", s[:6])
|
||||
case s[6] == 'h': // Hours/Minutes/Seconds (HMS) format
|
||||
return time.Parse("150405", s[:6])
|
||||
case len(s) >= 8: // Month/Day/Hours/Minutes (MDHM) format
|
||||
return time.Parse("01021504", s[:8])
|
||||
default:
|
||||
return time.Time{}, TimeFormatError{s}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user