Skip to content

Commit

Permalink
fixed type conversion and added example for nagerdate
Browse files Browse the repository at this point in the history
  • Loading branch information
nirokay committed Jul 24, 2024
1 parent 082f617 commit c6d5b79
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 16 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"Rica",
"Thuringia",
"Vorpommern",
"Würtemberg"
"Würtemberg",
"Новый"
],
"asciidoc.antora.enableAntoraSupport": false
}
27 changes: 16 additions & 11 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,31 @@ You do not see your country in this list? Help us by expanding the API wrappers!
== Examples

```nim
# European holiday API
import std/[strformat]
import holidapi/country/europe
import holidapi/api/nagerdate

let
holidaysInEnglish: seq[Holiday] = Netherlands.getHolidays(2024)
holidaysInDutch {.used.}: seq[Holiday] = Netherlands.getHolidays(2024, Dutch)

for holiday in holidaysInEnglish:
holidays: seq[Holiday] = SouthKorea.getHolidays(2024, bothNames)
# `bothNames` will get the english and local name of the holiday
# example:
#
# - South Korea: New Year's Day (새해)
# - France: New Year's Day (Jour de l'an)
# - Russia: New Year's Day (Новый год)

for holiday in holidays:
echo &"{holiday.name} is on the " & holiday.dateTime.format("yyyy-MM-dd") &
&" and goes on for " & $holiday.duration.inDays() & " day(s)!"

```
```nim
# European holiday API (for single country)
# European holiday API
import std/[strformat]
import holidapi/country/europe/germany
import holidapi/api/openholidaysapi

let
holidaysInEnglish: seq[Holiday] = getHolidays(2024)
holidaysInGerman {.used.}: seq[Holiday] = getHolidays(2024, German)
holidaysInEnglish: seq[Holiday] = Netherlands.getHolidays(2024)
holidaysInDutch {.used.}: seq[Holiday] = Netherlands.getHolidays(2024, Dutch)

for holiday in holidaysInEnglish:
echo &"{holiday.name} is on the " & holiday.dateTime.format("yyyy-MM-dd") &
Expand All @@ -45,7 +50,7 @@ for holiday in holidaysInEnglish:
```nim
# Alternative German API
import std/[strformat]
import holidapi/country/europe/germany_alt
import holidapi/api/feiertageapi

const
year: int = 2024
Expand Down
2 changes: 1 addition & 1 deletion holidapi.nimble
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Package

version = "1.0.1"
version = "1.0.2"
author = "nirokay"
description = "Nim wrappers for holiday APIs."
license = "GPL-3.0-only"
Expand Down
2 changes: 1 addition & 1 deletion src/holidapi/apis/nagerdate.nim
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,4 @@ proc getHolidays*(country: string|NagerDateApiCountry, year: int, names: NagerDa
response = url.requestParsedData(seq[NagerDateRawHoliday])

for holiday in response:
result.add holiday.toHoliday()
result.add holiday.toHoliday(names)
12 changes: 10 additions & 2 deletions src/holidapi/types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,16 @@ proc toHoliday*(holiday: NagerDateRawHoliday, nameType: NagerDateNameLanguage =
name: (
case nameType:
of englishName: holiday.name
of localName: holiday.localName
of bothNames: holiday.name & "(" & holiday.localName & ")"
of localName:
if holiday.localName != "":
holiday.localName
else:
holiday.name
of bothNames:
if holiday.localName != "":
holiday.name & " (" & holiday.localName & ")"
else:
holiday.name
),
date: holiday.date,
dateTime: holiday.date.parse(dateFormat),
Expand Down

0 comments on commit c6d5b79

Please sign in to comment.