Coder Social home page Coder Social logo

naguissa / uunixdate Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 0.0 11 KB

Tiny and simplified Arduino library to convert dates to and from unix timestamp

License: GNU Lesser General Public License v3.0

C++ 100.00%
arduino arduino-library clock datetime rtc timestamp unix-timestamp

uunixdate's Introduction

Arduino, ESP8266, STM32, ESP32 and others uRTCLib

Master status: Build Status

What is this repository for?

Tiny and simplified library to convert to and from UNIX timestamps.

This code is a simplified version of Adafruit's RTCLib https://github.com/adafruit/RTClib

WARNING: This library is ONLY prepared to work with dates from 2000-01-01 and is not accurate past 2100-01-01

This library doesn't take in consideration TimeZone and Daylight saving. If you want to adapt to these adding or substracting hours * 3600 to the timestamp (at input if you feed it to library or to timestamp() return value)

Supported features:

  • Convert from date (Y-M-D h:m:s) to UNIX timestamp and viceversa

How do I get set up?

You can get it from Arduino libraries directly, searching by uUnixDate.

For manual installation:

  • Get the ZIP.
  • Rename to uUnixDate.zip
  • Install library on Arduino

Documentation and extras

You can find all documentation and extras in this repository: https://github.com/Naguissa/uUnixDate_doc_and_extras

You can read documentation online here: https://naguissa.github.io/uUnixDate_doc_and_extras/

Examples

Included on example folder, available on Arduino IDE.

Who do I talk to?

Contribute

Any code contribution, report or comment are always welcome. Don't hesitate to use GitHub for that.

Thanks for your support.

Contributors hall of fame: https://www.foroelectro.net/hall-of-fame-f32/contributors-contribuyentes-t271.html

uunixdate's People

Contributors

naguissa avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

uunixdate's Issues

timestamp() function returns wrong unix time 2nd round

I have found that when I load an unixDate(year,mes,dia,hora,minuto,seg) the timestamp is calculated wrong, it returns exactly 432000 seconds (5 days) after the right time. I assume that may be it does not have in count the leap years which have been 5 from year 2000 without counting it. What seems strange to me that if I load an unixDate(timestamp) it returns the right date... there is a fragment of the code I have used to explain better... this code is running on ESP32 microcontroller.

uUnixDate dateA = uUnixDate(year1,mes,dia,hora,minuto,seg);
Serial.print(dateA.year());
Serial.print(dateA.month());
Serial.print(dateA.day());
Serial.print(dateA.hour());
Serial.print(dateA.minute());
Serial.print(dateA.second());
Serial.print(dateA.timestamp());  
uUnixDate dateC = uUnixDate(dateA.timestamp());
Serial.print(dateC.year());
Serial.print(dateC.month());
Serial.print(dateC.day());
Serial.print(dateC.hour());
Serial.print(dateC.minute());
Serial.print(dateC.second());
Serial.print(dateC.timestamp());

// date A is 2023/7/26 23:8:18 dateA.timestamp 1690844898
// date C is 2023/7/31 23:8:18 dateC.timestamp 1690844898

for the same timestamp the 2 dates can't be different...

timestamp() function returns wrong unix time

I found a problem with this function.

When I run:

uUnixDate now = uUnixDate(2023, 3, 24, 17, 19, 21);  // uUnixDate(Year, Month, Day, Hour, Minute, Second)
Serial.println(now.timestamp());

I end up with: 1679937561

Upon conversion, this value is: March 27, 2023 5:19:21 PM
It should be: March 24, 2023.

That is 3 days more than what it should be.

This is a major bug, how do we fix this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.