Skip to content

Commit

Permalink
Merge pull request #12 from uelei/fix/invalid-request-after-holidays
Browse files Browse the repository at this point in the history
Fix invalid requests after holidays
  • Loading branch information
uelei authored Nov 16, 2023
2 parents 869d80d + c1b957b commit 76c8a80
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions pkg/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func GenerateYesterdayString() time.Time {
currentTime := time.Now()

// Calculate yesterday's date
yesterday := currentTime.AddDate(0, 0, -2)
yesterday := currentTime.AddDate(0, 0, -4)

return yesterday
}
Expand Down Expand Up @@ -60,10 +60,15 @@ func ParseStringToDate(dateString string) time.Time {
}

func PadNumberWithZero(value float64) string {
return fmt.Sprintf("%.4f", value)
return fmt.Sprintf("%.4f", value)
}

func FormatGetResult(rates []DayValues, currency string) {
if len(rates) == 0 {
fmt.Println("No rates found for:", currency)
return

}

rate := rates[len(rates)-1]

Expand All @@ -76,7 +81,7 @@ func FormatGetResult(rates []DayValues, currency string) {
fmt.Println("|# 1,00 Sell: ", PadNumberWithZero(rate.CotacaoVenda), " #|")
fmt.Println("|# #|")
fmt.Println("|##==============================##|")
fmt.Println("| Rate Date ", rate.DataHoraCotacao[:10] , " |")
fmt.Println("| Rate Date ", rate.DataHoraCotacao[:10], " |")
fmt.Println(" ---------------------------------- ")

}
2 changes: 1 addition & 1 deletion pkg/lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestGenerateYesterdayString(t *testing.T) {

currentTime := time.Now()

if result.Day() != currentTime.Day()-2 {
if result.Day() != currentTime.Day()-4 {
t.Fatal("error creating yesterday date")
}
}
Expand Down

0 comments on commit 76c8a80

Please sign in to comment.