-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OOC, why this approach with wrapping DateTime.new? #4
Comments
This is actually the main reason for using my more complicated approach. Effectively, I wanted to do
which would ensure that enhanced timezone stuff was available globally. But sub day-start(DateTime $dt) {
DateTime.new: $dt.year, $dt.month, $dt.year, 0, 0, 0
}
use DateTime::Timezones:auth<lizmat>;
my $dt = DateTime.now; # enhanced DateTime
dd day-start $dt; # ends up with a CORE::DateTime This would be non-intuitive for someone who wanted to use timezones and also employ some fancy module that helps with time manipulation. Of course, while the above subroutine could have called, e.g., Down the line, I may make a
Sure, but at the loss of the global goal. I've got to play around a bit more with new-disp (aka 2021.10+) to check and see what code is still necessary and get things to play better around. If things will go as I'm hoping —and as my very early tests seemed to indicated before $day-job got crazy— the precomp issues with |
I'm not sure the global goal is a good one. Also, right now, using
Basically, forcing me to do something like fetching the current For reference, I'm trying to integrate |
Re your example: sub day-start(DateTime $dt) {
DateTime.new: $dt.year, $dt.month, $dt.year, 0, 0, 0
} If the author had written that as: sub day-start(DateTime $dt) {
$dt.WHAT.new: $dt.year, $dt.month, $dt.year, 0, 0, 0
} this would not be an issue. |
If `DateTime.new` is broken that's... not intended, and a bug. I will try
to look into this very quickly.
…On Thu, Dec 16, 2021, 18:21 Elizabeth Mattijsen ***@***.***> wrote:
I'm not sure the global goal is a good one. Also, right now, using
DateTime::Timezones actually breaks DateTime.new:
$ r 'dd "2021-04-22T07:36:50+0200".DateTime'
DateTime.new(2021,4,22,7,36,50,:timezone(7200))
$ r 'use DateTime::Timezones; dd "2021-04-22T07:36:50+0200".DateTime'
DateTime.new(2021,4,22,7,36,50)
Basically, forcing me to do something like fetching the current
DateTime.new at compile time, and refer to that to get the normal
behaviour.
For reference, I'm trying to integrate DateTime::Timezones into
IRC::Log::Textual. The problem is that older versions of the Textual IRC
client logged only [HH:MM:SS], whereas newer have a full
[YYYY-MM-DDTHH:MM:SS+TZTZ] DateTime compatible string. Textual logs in
daily logs, but separated at midnight *local* time. For IRC::Log, I would
like to have logs separated at midnight UTC. So the older logs with just
[HH:MM:SS] need some magic to convert to UTC, and I hoped that
DateTime::Timezones would be the ticket. So far, that didn't turn out to
be the case :-(
—
Reply to this email directly, view it on GitHub
<#4 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AFBLGIYVV4U2U46WE7VVF5TURJX53ANCNFSM5KHCJVJA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you commented.Message ID:
***@***.***>
|
Now wrt to unintentional downgrading: I've spent quite some time making class A is DateTime { method foo() { "foo" } }
dd A.now.later(:1hour).foo; # foo Even if that class is also called class DateTime is DateTime { method foo() { "foo" } }
dd DateTime.now.later(:1hour).foo; # foo |
I think the goal of making a better global |
isn't this just what you need? class DateTime is DateTime {
method new(:$timezone, |c) {
$timezone
?? $timezone ~~ Int
?? callwith(|c, :$timezone)
!! (callwith |c).in-timezone($timezone)
!! nextsame()
}
method in-timezone($timezone) {
$timezone ~~ Int
?? nextsame()
!! callwith(42) # magic happens here
}
}
dd DateTime.new(2021,12,17,15,1,3,:timezone<Europe/Amsterdam>);
# DateTime.new(2021,12,17,15,1,45,:timezone(42)) |
It's likely with `new-disp` an approach like this will work. On old-disp,
there were a lot of issues with `callsame` and `nextwith`, which is the
whole reason I was processing the arguments manually, rather than passing
to `CORE`. (This is on my docket for today, BTW)
…On Fri, Dec 17, 2021, 09:20 Elizabeth Mattijsen ***@***.***> wrote:
isn't this just what you need?
class DateTime is DateTime {
method new(:$timezone, |c) {
$timezone
?? $timezone ~~ Int
?? callwith(|c, :$timezone)
!! (callwith |c).in-timezone($timezone)
!! (nextwith |c)
}
method in-timezone($timezone) {
$timezone ~~ Int
?? nextsame()
!! callwith(42) # magic happens here
}
}
dd DateTime.new(2021,12,17,15,1,3,:timezone<Europe/Amsterdam>);# DateTime.new(2021,12,17,15,1,45,:timezone(42))
—
Reply to this email directly, view it on GitHub
<#4 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AFBLGI46R56F2UNZKWQXJCTURNBKVANCNFSM5KHCJVJA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you commented.Message ID:
***@***.***>
|
Putting this in
lib/Foo.rakumod
:And then using that module:
shows that the altered module is called. The
DateTime
class that is exported, is a subclass of the originalDateTime
class, so everything else just works.The advantage of this approach, is that you can localize the improved
DateTime
in a scope:But even inside the scope, you can refer to the original one with the
CORE::
prefix:Wouldn't this significantly simplify things?
The text was updated successfully, but these errors were encountered: