
Parse Ethiopian Dates
parsing.Rmd
Introduction
The Ethiopian calendar is widely used in Ethiopia and differs significantly from the Gregorian calendar. It has 13 months: 12 months of 30 days and a 13th month (Pagumē) of 5 or 6 days, depending on the year.
The ethiodate
package provides tools for parsing,
converting, and working with Ethiopian dates in R. This vignette
demonstrates how to parse Ethiopian dates from strings or numeric
formats and convert them into ethdate
objects.
Parsing Ethiopian Dates
From Character Strings
You can parse Ethiopian dates from standard character representations
like “2015-01-01” (Ethiopian calendar). Use
eth_parse_date()
:
library(ethiodate)
eth_parse_date("2015-01-01")
#> [1] "2015-01-01"
You can also provide a vector of dates:
eth_dates <- c("2015-01-01", "2015-02-15", "2015-13-05")
eth_parse_date(eth_dates)
#> [1] "2015-01-01" "2015-02-15" "2015-13-05"
If you are parsing dates from string, you must provide correct
formatting using format
argument and the string must have
consistent pattern. This argument accepts ISO 8601 formats, use
?strptime
for more.
Examples
x <- c("01/17/2025", "05/12/2017")
eth_parse_date(x, format = "%m/%d/%Y")
#> [1] "2025-01-17" "2017-05-12"
You can also parse date that contains month names if specify the exact format as follows:
eth_parse_date("Meskerem 25, 2017", format = "%B %d, %Y")
#> [1] "2017-01-25"
eth_parse_date("መስከረም 25, 2017", format = "%B %d, %Y", lang = "amh")
#> [1] "2017-01-25"
eth_parse_date("Sep 25, 2017", format = "%b %d, %Y", lang = "en")
#> [1] "2017-01-25"
From Numeric
ethate
is just a numeric vector, under the hood,
representing number of days since 1970-01-01 GC (1962-04-12 EC). The
date before the origin is represented by negative values. This makes it
to seamlessly integrate features if base R Date object. For
instance;
# The same origin
eth_parse_date("1962-04-23") |> unclass()
#> [1] 0
as.Date("1970-01-01") |> unclass()
#> [1] 0
So, you can supply number of days from a custom origin to construct
Ethiopian date object. If the origin is missing, the default is
1962-04-23 EC. See ?eth_date
for more.
From Components
Constructing ethdate
object from separate vector of
year, month and day is supported.
eth_make_date(2017, 1, 1)
#> [1] "2017-01-01"
y <- c(2022, 2025)
m <- c(5, 9)
d <- c(15, 19)
eth_make_date(y, m, d)
#> [1] "2022-05-15" "2025-09-19"
Invalid and Missing Values
ethiodate
validates every values before coercing it to
ethdate
object. For instance, 13th month has 6 days only
during leap year. If you supply such erroneous values, you will
NA's
along with warnig message.
Conversion
Conversion between Ethiopian and Gregorian calendar is fully supported.
To Ethiopian
To Gregorian
Operations
As any other date objects, ethdate
supports date
operations. A unit any arithmetric operations is date.
Conclusion
Parsing Ethiopian dates is a crucial step in analyzing data collected
in the Ethiopian calendar system. The ethiodate
package
provides a consistent and robust interface for converting string
representations of Ethiopian dates into properly classed objects ready
for further analysis or conversion.
For more functionality, see ?eth_date
,
?eth_parse_date
, ?eth_make_date
, and the rest
of the package documentation.