Instant Reference
Specific moment in time
What it is #
Routines #
Signatures are reproduced from the documentation, including their declared return types. A routine listed here is part of the type's published interface; whether Raku++ implements it is a separate question, answered by the examples below.
method from-posix #
method from-posix($posix, Bool $prefer-leap-second = False)
Converts the POSIX timestamp $posix to an Instant. If $prefer-leap-second is True, the return value will be the first of the two possible seconds in the case of a leap second.
method to-posix #
method to-posix()
Converts the invocant to a POSIX timestamp and returns a two element list containing the POSIX timestamp and a Bool. It is the inverse of method from-posix, except that the second return value is True if and only if this Instant is in a leap second.
method Date #
method Date(Instant:D: --> Date:D)
Returns Date:D.
Coerces the invocant to Date.
method DateTime #
method DateTime(Instant:D: --> DateTime:D)
Returns DateTime:D.
Coerces the invocant to DateTime. POSIX time (commonly called "Unix time") does not address leap seconds; in other words, it assumes that the period of rotation of the Earth is a fixed constant. Since in fact the amount of time that passes between one noon and the next varies from day to day, we must occasionally have a 61st second in the 60th minute of some hour; this is called a leap second, and happens at the
Examples, run three ways #
Every example below comes from the official documentation, together with the output that documentation asserts. Each was then executed by Rakudo and by Raku++ when this page was built. Where the three agree, one result is shown; where they do not, all three are — because which of them is wrong is exactly the information worth having.
2 all-differ · 3 no-output · 4 rakupp-differs
class Instant is Cool does Real { }Not executed: the documentation states no expected output for this example.
say DateTime.new(Instant.from-posix(1483228800, True)); # OUTPUT: «2016-12-31T23:59:60Z» say DateTime.new(Instant.from-posix(1483228800)); # OUTPUT: «2017-01-01T00:00:00Z»
2016-12-31T23:59:60Z
2017-01-01T00:00:00Z
2016-12-31T23:59:60Z
2017-01-01T00:00:00Z
2017-01-01T00:00:10Z
2017-01-01T00:00:10Z
Raku++ disagrees with both the documentation and Rakudo — a defect.
say DateTime.new('2017-01-01T00:00:00Z').Instant.to-posix; # OUTPUT: «(1483228800 False)»
say DateTime.new('2016-12-31T23:59:60Z').Instant.to-posix; # OUTPUT: «(1483228800 True)»(1483228800 False)
(1483228800 True)
(1483228800 False)
(1483228800 True)
(1483228790 False)
(1483228790 False)
Raku++ disagrees with both the documentation and Rakudo — a defect.
my $i = "/etc/passwd".IO.modified; say $i; # OUTPUT: «Instant:1771879757.95139447» say $i.Date; # OUTPUT: «2026-02-23»
Instant:1771879757.95139447
2026-02-23
Instant:1769925782
2026-02-01
1769925782
All three differ. Needs a human.
Not yet examined. Which of these is correct has not been established — do not treat either engine as settled here.
say now.DateTime; # OUTPUT: «2026-03-07T13:56:42.930951Z»
2026-03-07T13:56:42.930951Z
2026-07-28T15:18:30.736945Z
2026-07-28T15:18:30.586713Z
All three differ. Needs a human.
Not yet examined. Which of these is correct has not been established — do not treat either engine as settled here.
my Instant $i .= from-posix(1483228799);
my Duration $s = DateTime.new(1) - DateTime.new(0);
sub demo { say [$_, .posix] with DateTime.new($i + $^n * $s) }
demo(0); # OUTPUT: «[2016-12-31T23:59:59Z 1483228799]»
demo(1); # OUTPUT: «[2016-12-31T23:59:60Z 1483228800]»
demo(2); # OUTPUT: «[2017-01-01T00:00:00Z 1483228800]»
demo(3); # OUTPUT: «[2017-01-01T00:00:01Z 1483228801]»[2016-12-31T23:59:59Z 1483228799]
[2016-12-31T23:59:60Z 1483228800]
[2017-01-01T00:00:00Z 1483228800]
[2017-01-01T00:00:01Z 1483228801]
[2016-12-31T23:59:59Z 1483228799]
[2016-12-31T23:59:60Z 1483228800]
[2017-01-01T00:00:00Z 1483228800]
[2017-01-01T00:00:01Z 1483228801]
[2017-01-01T00:00:09Z 1483228809]
[2017-01-01T00:00:09Z 1483228809]
[2017-01-01T00:00:09Z 1483228809]
[2017-01-01T00:00:09Z 1483228809]
Raku++ disagrees with both the documentation and Rakudo — a defect.
with now { say .Int - DateTime.new($_).posix } # OUTPUT: «37»37
37
0
Raku++ disagrees with both the documentation and Rakudo — a defect.
$ perl6-2016.06 -e 'say Instant.from-posix: 1485726595' Instant:1485726631 $ perl6-2016.07 -e 'say Instant.from-posix: 1485726595' Instant:1485726632
Not executed: the documentation states no expected output for this example.
$ perl6-2016.06 -e 'say ($*VM.version before v2016.07 ?? 1 !! 0) + Instant.from-posix: 1485726595' Instant:1485726632 $ perl6-2016.07 -e 'say ($*VM.version before v2016.07 ?? 1 !! 0) + Instant.from-posix: 1485726595' Instant:1485726632
Not executed: the documentation states no expected output for this example.