Are all instances comparable or machine dependent in Perl 6?

This is a case where I can find a definition, but I do not quite understand it. From the official documentation:

Instantaneous action is a specific point in time measured in atomic seconds using fractions. He is not attached to any era or does not know about it.

I don’t understand how you can indicate a specific moment in time without having an era? Doesn't he have a landmark? On two different Linux machines, both instances seemed to refer to seconds from the POSIX era. I assume Instants really have a start time, but this start time is implementation / device dependent.

# machine1
say(now * (1/3600) * (1/24) * (1/365.25)); # years from zero point
46.0748226200715

# machine2
say(now * (1/3600) * (1/24) * (1/365.25)); # years from zero point
46.0748712024946

In any case, so my question is, can we rely on the fact that for this it would be possible to coordinate different processes or use them only for the "internal"?

+4
source share
2 answers

All Instant objects that are currently on a particular machine are comparable; instances from different machines may not be available.

POSIX 1 1970 (TAI), 36 (UTC).
( , , POSIX)

, , .
.

, .


,

# runtime constant-like term
my \init = INIT now;

say init.to-posix.perl;
# (1454172565.36938, Bool::False)

say init.DateTime.Str;     # now.DateTime =~= DateTime.now
# 2016-01-30T16:49:25.369380Z

say init.Date.Str;         # now.Date =~= Date.today
# 2016-01-30

say init.DateTime.yyyy-mm-dd eq init.Date.Str;
# True

DateTime, , , .

my $now = DateTime.now;
say $now.Str;
# 2016-01-30T11:29:14.928520-06:00

say $now.truncated-to('day').utc.Str;
# 2016-01-30T06:00:00Z
#             ^

say $now.utc.truncated-to('day').Str;
# 2016-01-30T00:00:00Z
#             ^

Date.today DateTime.now , now.Date now.DateTime .


POSIX , time, now.to-posix[0].Int.

+3
say (now).WHAT; # «(Instant)␤»
say (now * 1).WHAT # «(Num)␤»

Num s. , .perl.

say (now).perl # «Instant.from-posix((<1211194481492/833>, 0))␤»

, , Instant.from-posix Unix.

see https://github.com/rakudo/rakudo/blob/nom/src/core/Instant.pm#L15

+5
source

Source: https://habr.com/ru/post/1626435/


All Articles