npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ethereum-datetime

v1.0.0

Published

Date-Time utilities for ethereum contracts.

Downloads

14

Readme

Ethereum Date and Time tools

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

Contract Address: 0x1a6184CD4C5Bea62B0116de7962EE7315B7bcBce

Compiled with:

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