| Title: | Working with Ethiopian Dates |
|---|---|
| Description: | A robust and efficient solution for working with Ethiopian dates. It can seamlessly convert to and from Gregorian dates. It is designed to be compatible with the 'tidyverse' data workflow, including plotting with 'ggplot2'. It ensures lightning-fast computations by integrating high-performance 'C++' code through 'Rcpp' package. |
| Authors: | Gutama Girja Urago [aut, cre, cph] (ORCID: <https://orcid.org/0000-0001-5588-2301>) |
| Maintainer: | Gutama Girja Urago <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.3.1 |
| Built: | 2026-05-21 06:04:38 UTC |
| Source: | https://github.com/guturago/ethiodate |
A subset of data from the FAO Food Price Index for Ethiopia.
cpiethcpieth
cpiethA data frame with 270 rows and 2 columns:
Date (GC)
Consumer price index
https://data360.worldbank.org/en/indicator/FAO_CP_23014?country=ETH
Convert an object to an Ethiopian date.
eth_date(x, ...) ## Default S3 method: eth_date(x, ...) ## S3 method for class 'numeric' eth_date(x, origin, ...) ## S3 method for class 'character' eth_date(x, format = "%Y-%m-%d", lang = c("lat", "amh", "en"), ...) ## S3 method for class 'Date' eth_date(x, ...) ## S3 method for class 'POSIXct' eth_date(x, ...) ## S3 method for class 'POSIXt' eth_date(x, ...) ## S3 method for class 'factor' eth_date(x, ...)eth_date(x, ...) ## Default S3 method: eth_date(x, ...) ## S3 method for class 'numeric' eth_date(x, origin, ...) ## S3 method for class 'character' eth_date(x, format = "%Y-%m-%d", lang = c("lat", "amh", "en"), ...) ## S3 method for class 'Date' eth_date(x, ...) ## S3 method for class 'POSIXct' eth_date(x, ...) ## S3 method for class 'POSIXt' eth_date(x, ...) ## S3 method for class 'factor' eth_date(x, ...)
x |
a numeric, character, Date, POSIXct or POSIXt vector. |
... |
further arguments to be passed to specific methods (see above). |
origin |
a ethdate, Date object, or something that can be coerced by
|
format |
format argument for character method to parse the date. |
lang |
a language in which month names are written, if included in x. Use "lat" for Amharic month names written in Latin alphabets, "amh" for month names written in Amharic alphabets, and "en" for English month names. |
eth_date() internally stores the number of days as double since the Unix epoch of "1970-01-01" GC ("1962-04-23" EC).
Days before "1962-04-23" EC are represented as negative numbers.
This makes it easy to convert from and to base Date objects.
The conversion of numeric vectors assumes that the vector represents a number of days since
the origin ("1962-04-23" EC if origin is NULL). For the date objects, it extracts underlying
numeric values and convert it to an ethiodate object. To convert from POSIXct or POSIXt,
it coerces these objects to base Date objects and then applies the conversion.
To parse a character vector, a valid format must be supplied. The default is "%Y-%m-%d".
Please see the details section of strptime. Factors can also be coerced
to ethdate after being internally converted to character.
a vector of an 'ethdate' object corresponding to x.
Gutama Girja Urago
eth_make_date() eth_parse_date()
eth_date(Sys.Date()) eth_date(Sys.time()) x <- 7 eth_date(x) eth_date(x, origin = Sys.Date()) eth_date(x, origin = eth_today()) eth_date(x, origin = "2017-01-01") eth_date(x, origin = "01-01-2017", format = "%d-%m-%Y") s <- c("01/01/2013", "06/13/2011") eth_date(s, format = "%d/%m/%Y")eth_date(Sys.Date()) eth_date(Sys.time()) x <- 7 eth_date(x) eth_date(x, origin = Sys.Date()) eth_date(x, origin = eth_today()) eth_date(x, origin = "2017-01-01") eth_date(x, origin = "01-01-2017", format = "%d-%m-%Y") s <- c("01/01/2013", "06/13/2011") eth_date(s, format = "%d/%m/%Y")
Make Ethiopian date from year, month and day components.
eth_make_date(year, month, day)eth_make_date(year, month, day)
year |
an integer vector of Ethiopian year. |
month |
an integer vector of Ethiopian month. |
day |
an integer vector of Ethiopian day. |
This function makes an Ethiopian date object from three integer vectors of an equal length.
It validates the date and returns NA for invalid dates. It accounts for leap years.
a vector of an 'ethdate' object.
Gutama Girja Urago
eth_make_date(2017, 01, 15)eth_make_date(2017, 01, 15)
Parse Ethiopian date from character vector that has a non-digit separator.
eth_parse_date(x, format = "%Y-%m-%d", lang = c("lat", "amh", "en"))eth_parse_date(x, format = "%Y-%m-%d", lang = c("lat", "amh", "en"))
x |
a character vector. |
format |
a format in in which x is composed. See |
lang |
a language in which month names are written, if included in x. Use "lat" for Amharic month names written in Latin alphabets, "amh" for month names written in Amharic alphabets, and "en" for English month names. |
x must include a non-digit separator and exactly three components of the date (year, month, and day).
a vector of an'ethdate' object.
Gutama Girja Urago
eth_parse_date("2017-01-01") s <- c("01/01/2013", "06/13/2011") eth_parse_date(s, format = "%d/%m/%Y")eth_parse_date("2017-01-01") s <- c("01/01/2013", "06/13/2011") eth_parse_date(s, format = "%d/%m/%Y")
Small functions that displays texts.
eth_show(x = c("%B", "%b", "%A", "%a"), lang = c("lat", "amh", "en")) eth_today(...) eth_now(...)eth_show(x = c("%B", "%b", "%A", "%a"), lang = c("lat", "amh", "en")) eth_today(...) eth_now(...)
x |
what you want to see. |
lang |
language of the text. |
... |
arguments that passes to |
eth_show() displays the underlying month and weekday names that is used by eth_parse_date().
Except for eth_date(), which returns an ethdate object, other functions return a character vector.
Gutama Girja Urago
eth_show() eth_show("%A", "amh") eth_today() eth_now()eth_show() eth_show("%A", "amh") eth_today() eth_now()
Small functions that helps to extract parts of Ethiopian date objects.
eth_year(x) eth_month(x) eth_monthname(x, lang = c("lat", "amh", "en"), abbreviate = FALSE) eth_day(x) eth_weekday(x, lang = c("lat", "amh", "en"), abbreviate = FALSE) eth_quarter(x)eth_year(x) eth_month(x) eth_monthname(x, lang = c("lat", "amh", "en"), abbreviate = FALSE) eth_day(x) eth_weekday(x, lang = c("lat", "amh", "en"), abbreviate = FALSE) eth_quarter(x)
x |
a vector of an Ethiopian date object |
lang |
a language. 'lat' for Amharic written in Latin alphabets, 'amh' for Amharic, and 'en' for English |
abbreviate |
Do you want to get an abbreviated month or weekday names? |
a vector
Gutama Girja Urago
today <- eth_date(Sys.Date()) eth_year(today) eth_month(today) eth_monthname(today) eth_day(today) eth_weekday(today)today <- eth_date(Sys.Date()) eth_year(today) eth_month(today) eth_monthname(today) eth_day(today) eth_weekday(today)
Helper functions to plot an ethdate object using ggplot2.
scale_x_ethdate(breaks = eth_breaks(), labels = eth_labels(), ...) scale_y_ethdate(breaks = eth_breaks(), labels = eth_labels(), ...) eth_breaks(n = 5, pretty = TRUE) eth_labels(format = "%b %d, %Y", lang = "lat")scale_x_ethdate(breaks = eth_breaks(), labels = eth_labels(), ...) scale_y_ethdate(breaks = eth_breaks(), labels = eth_labels(), ...) eth_breaks(n = 5, pretty = TRUE) eth_labels(format = "%b %d, %Y", lang = "lat")
breaks |
A numeric vector of positions or |
labels |
A character vector giving labels (must be same length as breaks) or
|
... |
further arguments to be passed to |
n |
A number of breaks. |
pretty |
Logical; if TRUE, use pretty() for rounded breaks. |
format |
A format for the |
lang |
A language for the month or weekday names if involved. Use "lat" for Latin alphabets "amh" for Amharic alphabets, and "en" for English names. |
eth_labels() and eth_breaks() are designed to be used only in the scale_(x|y)_ethdate functions.
Maps ethdate objects on ggplot2 layers.
Gutama Girja Urago
library(ggplot2) cpieth[["ethdt"]] <- eth_date(cpieth$date) ggplot(cpieth, aes(ethdt, cpi)) + geom_line() + scale_x_ethdate(breaks = eth_breaks(6), labels = eth_labels("%Y"), name = "Year (EC)") + theme_bw()library(ggplot2) cpieth[["ethdt"]] <- eth_date(cpieth$date) ggplot(cpieth, aes(ethdt, cpi)) + geom_line() + scale_x_ethdate(breaks = eth_breaks(6), labels = eth_labels("%Y"), name = "Year (EC)") + theme_bw()
Small helper functions.
## S3 method for class 'ethdate' format(x, format = "%Y-%m-%d", lang = c("lat", "amh", "en"), ...) is_eth_date(x) is_eth_leap(x) ## S3 method for class 'ethdate' as.Date(x, ...) ## S3 method for class 'ethdate' as.double(x, ...) ## S3 method for class 'ethdate' as.integer(x, ...) ## S3 method for class 'ethdate' as.character(x, ...)## S3 method for class 'ethdate' format(x, format = "%Y-%m-%d", lang = c("lat", "amh", "en"), ...) is_eth_date(x) is_eth_leap(x) ## S3 method for class 'ethdate' as.Date(x, ...) ## S3 method for class 'ethdate' as.double(x, ...) ## S3 method for class 'ethdate' as.integer(x, ...) ## S3 method for class 'ethdate' as.character(x, ...)
x |
an ethdate or numeric vector. |
format |
a format for character date. |
lang |
a language. |
... |
further arguments to be passed to specific methods. |
is_eth_leap() returns a boolean vector,
as.Date() returns a Date object,
as.numeric() returns number of date since 1970-01-01 GC (1962-04-23 EC), and
as.character() returns formatted character date.
is_eth_leap(2011)is_eth_leap(2011)