# ethereum-datetime

> Date-Time utilities for ethereum contracts.

Latest version **1.0.0** (published 2018-03-31) · ISC license · 0 weekly downloads

## Install

```sh
npm install ethereum-datetime
pnpm add ethereum-datetime
yarn add ethereum-datetime
bun add ethereum-datetime
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2018-03-31 |
| First published | 2018-03-31 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 41.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 380 |
| Author | Piper Merriam |
| Maintainers | uluhonolulu |
| Keywords | ethereum, solidity, datetime |

## Links

- npm: https://www.npmjs.com/package/ethereum-datetime
- Repository: git@github.com:pipermerriam/ethereum-datetime
- Homepage: https://github.com/pipermerriam/ethereum-datetime
- Issues: https://github.com/pipermerriam/ethereum-datetime/issues
- npm.io page: https://npm.io/package/ethereum-datetime

## Alternatives

- [@js-joda/timezone](https://npm.io/package/@js-joda/timezone.md) — 383.4K weekly downloads
- [chartjs-adapter-moment](https://npm.io/package/chartjs-adapter-moment.md) — 210.8K weekly downloads
- [strftime](https://npm.io/package/strftime.md) — 171.2K weekly downloads
- [vue-flatpickr-component](https://npm.io/package/vue-flatpickr-component.md) — 115.8K weekly downloads
- [timepicker](https://npm.io/package/timepicker.md) — 51.0K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2018-03-31

## README

## Ethereum Date and Time tools

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

Contract Address: `0x1a6184CD4C5Bea62B0116de7962EE7315B7bcBce`  

Compiled with:

```bash
$ solc --version
solc, the solidity compiler commandline interface
Version: 0.1.3-1736fe80/RelWithDebInfo-Darwin/unknown/JIT linked to libethereum-0.9.92-dcf2fd11/RelWithDebInfo-Darwin/unknown/JIT
$ solc contracts/DateTime.sol --optimize --bin
```

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

* `isLeapYear(uint16 year) constant returns (bool)`

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


* `parseTimestamp(uint timestamp) internal returns (DateTime dt)`

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


* `getYear(uint timestamp) constant returns (uint16)`

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


* `getMonth(uint timestamp) constant returns (uint16)`

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


* `getDay(uint timestamp) constant returns (uint16)`

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


* `getHour(uint timestamp) constant returns (uint16)`

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


* `getMinute(uint timestamp) constant returns (uint16)`

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


* `getSecond(uint timestamp) constant returns (uint16)`

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


* `getWeekday(uint timestamp) constant returns (uint8)`

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


* `toTimestamp(uint16 year, uint8 month, uint8 day, uint8 hour, uint8 minute, uint8 second) constant returns (uint timestamp)`
* `toTimestamp(uint16 year, uint8 month, uint8 day, uint8 hour, uint8 minute) constant returns (uint timestamp)`
* `toTimestamp(uint16 year, uint8 month, uint8 day, uint8 hour) constant returns (uint timestamp)`
* `toTimestamp(uint16 year, uint8 month, uint8 day) constant returns (uint timestamp)`

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

---
_Source: https://npm.io/package/ethereum-datetime · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
