Skip to content

Improve the os.difftime type definition#2337

Open
tapple wants to merge 1 commit intoluau-lang:masterfrom
tapple:os.difftime-definition
Open

Improve the os.difftime type definition#2337
tapple wants to merge 1 commit intoluau-lang:masterfrom
tapple:os.difftime-definition

Conversation

@tapple
Copy link
Copy Markdown

@tapple tapple commented Apr 7, 2026

os.difftime cannot accept DateTypeResults:

--!strict
local t1 = os.date("!*t")
local t2 = os.date("!*t")
print(os.difftime(t1, t2))
print(t1 - t2)
$ ./luau osbug.luau 
./osbug.luau:4: invalid argument #2 to 'difftime' (number expected, got table)
stacktrace:
[C] function difftime
./osbug.luau:4

But luau-analyze thought it could:

$ ./luau-analyze osbug.luau 
./osbug.luau(5,7): TypeError: Binary operator '-' not supported by types 'DateTypeResult' and 'DateTypeResult'

Fixed:

$ ./luau-analyze osbug.luau 
./osbug.luau(4,19): TypeError: Expected this to be 'number', but got 'DateTypeResult'
./osbug.luau(4,23): TypeError: Expected this to be 'number', but got 'DateTypeResult'
./osbug.luau(5,7): TypeError: Binary operator '-' not supported by types 'DateTypeResult' and 'DateTypeResult'

@tapple tapple changed the title Fix the type definition of os.difftime Improve the os.difftime type definition Apr 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant