Correctadif date

pull/2/head
Jean-Marc MEESSEN 4 years ago
parent 55e96d88f2
commit 1077b7254f

@ -48,6 +48,7 @@ func buildOutputFilename(output string, input string, overwrite bool) (outputFil
if output != "" { if output != "" {
info, err := os.Stat(output) info, err := os.Stat(output)
if os.IsNotExist(err) { if os.IsNotExist(err) {
//File doesn't exist, so we're good
return output, true return output, true
} }
//It exisits but is a directory //It exisits but is a directory
@ -58,10 +59,10 @@ func buildOutputFilename(output string, input string, overwrite bool) (outputFil
if overwrite { if overwrite {
//user accepted to overwrite the file //user accepted to overwrite the file
return output, true return output, true
} else {
fmt.Println("File already exists. Use --overwrite flag if necessary.")
return "", false
} }
fmt.Println("File already exists. Use --overwrite flag if necessary.")
return "", false
} }
return outputFilename, true return outputFilename, true

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"os" "os"
"strings" "strings"
"time"
) )
/* /*
@ -44,9 +45,8 @@ func buildAdif(fullLog []LogLine) (adifList []string) {
for _, logLine := range fullLog { for _, logLine := range fullLog {
adifLine := "" adifLine := ""
adifLine = adifLine + adifElement("STATION_CALLSIGN", logLine.MyCall) adifLine = adifLine + adifElement("STATION_CALLSIGN", logLine.MyCall)
adifLine = adifLine + adifElement("CALL", logLine.Call) adifLine = adifLine + adifElement("CALL", logLine.Call)
//TODO: strip the delimiters of the date adifLine = adifLine + adifElement("QSO_DATE", adifDate(logLine.Date))
adifLine = adifLine + adifElement("QSO_DATE", logLine.Date)
adifLine = adifLine + adifElement("TIME_ON", logLine.Time) adifLine = adifLine + adifElement("TIME_ON", logLine.Time)
adifLine = adifLine + adifElement("BAND", logLine.Band) adifLine = adifLine + adifElement("BAND", logLine.Band)
adifLine = adifLine + adifElement("MODE", logLine.Mode) adifLine = adifLine + adifElement("MODE", logLine.Mode)
@ -104,3 +104,16 @@ func checkFileError(e error) {
panic(e) panic(e)
} }
} }
//adifDate converts a date in YYYY-MM-DD format to YYYYMMDD
func adifDate(inputDate string) (outputDate string) {
const RFC3339FullDate = "2006-01-02"
date, err := time.Parse(RFC3339FullDate, inputDate)
//error should never happen
if err != nil {
panic(err)
}
outputDate = fmt.Sprintf("%04d%02d%02d", date.Year(), date.Month(), date.Day())
return outputDate
}

@ -37,8 +37,8 @@ func Test_adifElement(t *testing.T) {
func Test_buildAdif(t *testing.T) { func Test_buildAdif(t *testing.T) {
sampleFilledLog1 := []LogLine{ sampleFilledLog1 := []LogLine{
{MyCall: "ON4KJM/P", Call: "S57LC", Date: "20200524", Time: "1310", Band: "20m", Frequency: "14.045", Mode: "CW", RSTsent: "599", RSTrcvd: "599", MyWWFF: "ONFF-0259", Operator: "ON4KJM", Nickname: "ONFF-0259-1"}, {MyCall: "ON4KJM/P", Call: "S57LC", Date: "2020-05-24", Time: "1310", Band: "20m", Frequency: "14.045", Mode: "CW", RSTsent: "599", RSTrcvd: "599", MyWWFF: "ONFF-0259", Operator: "ON4KJM", Nickname: "ONFF-0259-1"},
{MyCall: "ON4KJM/P", Call: "ON4LY", Date: "20200524", Time: "1312", Band: "20m", Mode: "CW", RSTsent: "559", RSTrcvd: "599", MyWWFF: "ONFF-0259", Operator: "ON4KJM"}, {MyCall: "ON4KJM/P", Call: "ON4LY", Date: "2020-05-24", Time: "1312", Band: "20m", Mode: "CW", RSTsent: "559", RSTrcvd: "599", MyWWFF: "ONFF-0259", Operator: "ON4KJM"},
} }
expectedOutput1 := []string{ expectedOutput1 := []string{
@ -72,3 +72,33 @@ func Test_buildAdif(t *testing.T) {
}) })
} }
} }
func Test_adifDate(t *testing.T) {
type args struct {
inputDate string
}
tests := []struct {
name string
args args
wantOutputDate string
}{
{
"Happy case",
args{inputDate: "2020-06-13"},
"20200613",
},
//Panics as expected but I don't know how to test this.
// {
// "Bad format",
// args{inputDate: "2020-13-06"},
// "20200613",
// },
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if gotOutputDate := adifDate(tt.args.inputDate); gotOutputDate != tt.wantOutputDate {
t.Errorf("adifDate() = %v, want %v", gotOutputDate, tt.wantOutputDate)
}
})
}
}

Loading…
Cancel
Save