Type: Package
Title: Working with Ethiopian Dates
Version: 0.2.0
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.
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.3.2
LinkingTo: Rcpp
Imports: Rcpp, stringr, vctrs
Suggests: dplyr, ggplot2, knitr, rmarkdown, scales, testthat (≥ 3.0.0)
Config/testthat/edition: 3
URL: https://guturago.github.io/ethiodate/
VignetteBuilder: knitr
Depends: R (≥ 4.1.0)
NeedsCompilation: yes
Packaged: 2025-05-28 16:19:28 UTC; Gute
Author: Gutama Girja Urago ORCID iD [aut, cre, cph]
Maintainer: Gutama Girja Urago <girjagutama@gmail.com>
Repository: CRAN
Date/Publication: 2025-05-28 16:50:02 UTC

Monthly FAO Food Price Index 2001-2023

Description

A subset of data from the FAO Food Price Index for Ethiopia.

Usage

cpieth

Format

cpieth

A data frame with 270 rows and 2 columns:

date

Date (GC)

cpi

Consumer price index

Source

https://data360.worldbank.org/en/indicator/FAO_CP_23014?country=ETH


Create an Ethiopian Date Object

Description

Convert an object to an Ethiopian date.

Usage

eth_date(x, ...)

## S3 method for class 'numeric'
eth_date(x, origin = NULL, ...)

## 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, ...)

Arguments

x

a numeric, character, Date, POSIXct or POSIXt vector.

...

further arguments to be passed to specific methods (see above).

origin

a ethdate or Date object, or something that can be coerced by eth_date(origin, ...). Default: the Unix epoch of "1970-01-01" GC ("1962-04-23" EC).

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.

Details

eth_date() internally stores the number of days as an integer since the Unix epoch of "1970-01-01" GC ("1962-04-23" EC). Days before "1962-04-23" EC are represented as negative integers. 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.

Value

a vector of an 'ethdate' object corresponding to x.

Author(s)

Gutama Girja Urago

See Also

eth_make_date() eth_parse_date()

Examples


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

Description

Make Ethiopian date from year, month and day components.

Usage

eth_make_date(year, month, day)

Arguments

year

an integer vector of Ethiopian year.

month

an integer vector of Ethiopian month.

day

an integer vector of Ethiopian day.

Details

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.

Value

a vector of an 'ethdate' object.

Author(s)

Gutama Girja Urago

See Also

eth_date() eth_parse_date()

Examples

eth_make_date(2017, 01, 15)

Parse Ethiopian Date

Description

Parse Ethiopian date from character vector that has a non-digit separator.

Usage

eth_parse_date(x, format = "%Y-%m-%d", lang = c("lat", "amh", "en"))

Arguments

x

a character vector.

format

a format in in which x is composed. See strptime.

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.

Details

x must include a non-digit separator and exactly three components of the date (year, month, and day).

Value

a vector of an'ethdate' object.

Author(s)

Gutama Girja Urago

See Also

eth_date() eth_make_date()

Examples

eth_parse_date("2017-01-01")
s <- c("01/01/2013", "06/13/2011")
eth_parse_date(s, format = "%d/%m/%Y")

See Month or Day Names

Description

Small functions that displays texts.

Usage

eth_show(x = c("%B", "%b", "%A", "%a"), lang = c("lat", "amh", "en"))

eth_today(...)

eth_now(...)

Arguments

x

what you want to see.

lang

language of the text.

...

arguments that passes to format()

Details

eth_show() displays the underlying month and weekday names that is used by eth_parse_date().

Value

Except for eth_date(), which returns an ethdate object, other functions return a character vector.

Author(s)

Gutama Girja Urago

Examples

eth_show()
eth_show("%A", "amh")
eth_today()
eth_now()


Ethiopian Date Components

Description

Small functions that helps to extract parts of Ethiopian date objects.

Usage

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)

Arguments

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?

Value

a vector

Author(s)

Gutama Girja Urago

Examples

today <- eth_date(Sys.Date())
eth_year(today)
eth_month(today)
eth_monthname(today)
eth_day(today)
eth_weekday(today)

Plotting Ethiopian Date

Description

Helper functions to plot an ethdate object using ggplot2.

Usage

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")

Arguments

breaks

A numeric vector of positions or eth_breaks() function.

labels

A character vector giving labels (must be same length as breaks) or eth_labels() function.

...

further arguments to be passed to ggplot2::scale_x_continuous() or ggplot2::scale_y_continuous().

n

A number of breaks.

pretty

Logical; if TRUE, use pretty() for rounded breaks.

format

A format for the ethdate.

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.

Details

eth_labels() and eth_breaks() are designed to be used only in the ⁠scale_(x|y)_ethdate⁠ functions.

Value

Maps ethdate objects on ggplot2 layers.

Author(s)

Gutama Girja Urago

Examples


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()

Utils

Description

Small helper functions.

Usage

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.character(x, ...)

## S3 method for class 'ethdate'
format(x, format = "%Y-%m-%d", lang = c("lat", "amh", "en"), ...)

Arguments

x

an ethdate or numeric vector.

...

further arguments to be passed to specific methods.

format

a format for character date.

lang

a language.

Value

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.

Examples

is_eth_leap(2011)