Learn R Programming

ethiodate (version 0.3.1)

eth_date: Create an Ethiopian Date Object

Description

Convert an object to an Ethiopian date.

Usage

eth_date(x, ...)

# S3 method for default eth_date(x, ...)

# S3 method for numeric eth_date(x, origin, ...)

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

# S3 method for Date eth_date(x, ...)

# S3 method for POSIXct eth_date(x, ...)

# S3 method for POSIXt eth_date(x, ...)

# S3 method for factor eth_date(x, ...)

Value

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

Arguments

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 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.

Author

Gutama Girja Urago

Details

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.

See Also

eth_make_date() eth_parse_date()

Examples

Run this code

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



Run the code above in your browser using DataLab