Skip to content

Latest commit

History

21 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Time: Dates and Periods in Lua

A module for the manipulation of dates and periods according to the Gregorian calendar.

Features

  • microsecond (1-millionth of a second) precision
  • leap years are taken into account
  • leap seconds not taken into account
  • convenience utilities (day of week, leap years, end of month)
  • current time (local and UTC)
  • sleep
  • based on Claus Tøndering's calendar algorithms and the corresponding C implementation
localtime=require"time"locald1=time.date(2012, 4, 30) -- A date at 00:00 AM.-- Arithmetic operators are supported:localp1=time.hours(13) +time.minutes(30) -- A period.locald2=d1+p1-- The same date above at 1:30 PM.assert(d2-d1==p1)
-- To / from strings, same functionality for periods:localdatestr="2012-04-30T13:30:00.000000"locald3=time.todate(datestr)
assert(d2==d3)
assert(tostring(d2) ==datestr)
-- Comparison operators are supported:assert(time.minutes(1) ==time.seconds(60))
assert(time.minutes(1) >time.seconds(59))
assert(d2>d1)
print(time.nowlocal()) -- Now, according to local clock.print(time.nowutc()) -- Now, according to UTC clock.time.sleep(time.seconds(1)) -- Sleep for 1 second.

Install

This module is included in the ULua distribution, to install it use:

upkg add time

Alternatively, manually install this module making sure that all dependencies listed in the require section of __meta.lua are installed as well.

Documentation

Refer to the official documentation.

About

Time: Dates and Periods in Lua

Resources

Stars

28 stars

Watchers

5 watching

Forks

Releases

Packages

Contributors

Languages