pipermerriam / ethereum-datetime

Date-Time utilities for ethereum contracts.
MIT License
378 stars 139 forks source link

Ethereum Date and Time tools

Contract which implements utilities for working with datetime values in ethereum.

Contract Deployments:

To verify, you need to compare the code on the blockchain with the runtime code which can be gotten from solc contracts/DateTime.sol --optimize --bin-runtime.

Also you can find it already verified at https://etherscan.io/address/0x1a6184cd4c5bea62b0116de7962ee7315b7bcbce#code

DateTime struct

Internally, the following struct is used to represent date-time object.

struct DateTime {
        uint16 year;
        uint8 month;
        uint8 day;
        uint8 hour;
        uint8 minute;
        uint8 second;
        uint8 weekday;
}

API

Given an integer year value, returns whether it is a leap year.

Given a unix timestamp, returns the DateTime representation of it.

Given a unix timestamp, returns the DateTime.year value for the timestamp.

Given a unix timestamp, returns the DateTime.month value for the timestamp.

Given a unix timestamp, returns the DateTime.day value for the timestamp.

Given a unix timestamp, returns the DateTime.hour value for the timestamp.

Given a unix timestamp, returns the DateTime.minute value for the timestamp.

Given a unix timestamp, returns the DateTime.second value for the timestamp.

Given a unix timestamp, returns the DateTime.weekday value for the timestamp.

Returns the unix timestamp representation for the given date and time values.