Last active
July 29, 2023 18:16
-
-
Save librasteve/2063318fe8b44bd44f91c49b37586ff5 to your computer and use it in GitHub Desktop.
DateTimemilli
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DateTimemilli { ... } #<=== predeclare unfinished class | |
#| declare operator multi in outer scope since this is where you want to use it | |
multi sub infix:«>»(DateTimemilli:D $a, DateTimemilli:D $b --> Bool:D) #<=== use magic brackets | |
{ | |
say $a; | |
say $b; | |
return False; | |
} | |
#| I think delegation is a better model here https://docs.raku.org/language/objects#Delegation | |
#| Otherwise you have to catch millisec in 'new' constructor and redispatch to parent | |
class DateTimemilli { | |
has Int $.millisecond; | |
has DateTime $!dt handles *; #<== so yep this handles all the methods except your overrides | |
multi method TWEAK { | |
my $second = $!millisecond / 1000; | |
$!dt = DateTime.new(date => Date.new('2023-12-24'), #<== maybe an Instant would be better than DateTime | |
hour => 0, | |
minute => 0, | |
:$second, #<== pass it your value | |
timezone => 1); | |
} | |
method gist() | |
{ | |
self.Str~":"~$.millisecond.Str; | |
} | |
} | |
my $start = DateTimemilli.new( millisecond => 2000 ); | |
my $end = DateTimemilli.new( millisecond => 3000 ); | |
say $start > $end; | |
#------- | |
#DateTimemilli<5862950986640>:2000 | |
#DateTimemilli<5862950988032>:3000 | |
#False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment