Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

stepelu/lua-time

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 

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
local time = require "time"

local d1 = time.date(2012, 4, 30) -- A date at 00:00 AM.

-- Arithmetic operators are supported:
local p1 = time.hours(13) + time.minutes(30) -- A period.
local d2 = d1 + p1 -- The same date above at 1:30 PM.
assert(d2 - d1 == p1)

-- To / from strings, same functionality for periods:
local datestr = "2012-04-30T13:30:00.000000"
local d3 = 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

License

Stars

Watchers

Forks

Packages

No packages published

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.