Skip Menu |

This queue is for tickets about the MooseX-Types-DateTime CPAN distribution.

Report information
The Basics
Id: 130498
Status: rejected
Priority: 0/
Queue: MooseX-Types-DateTime

People
Owner: Nobody in particular
Requestors: GHENRY [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.13
Fixed in: (no value)



Subject: Milliseconds in builder
Hi, I have: has event_datetime => ( is => 'rw', isa => 'DateTime', lazy => 1, default => sub { DateTime->from_epoch( epoch => time() )->set_time_zone('Europe/London') ->format_cldr(q{yyyy-MM-dd'T'HH:mm:ss.SSSSSS}); } ); but because I want milliseconds which standard time that DateTime->now uses from_epoch with doesn't, I use Time::HiRes; This blows up with: Attribute (event_datetime) does not pass the type constraint because: Validation failed for 'DateTime' with value "2019-09-12T10:24:26.423671" at accessor SureVoIP::API::AuditLog::event_datetime (defined at /home/suretec/surevoip-api/SureVoIP-API/t/../lib/SureVoIP/API/AuditLog.pm line 25) line 11 SureVoIP::API::AuditLog::event_datetime('SureVoIP::API::AuditLog=HASH(0xe7bde38)') called at /home/suretec/surevoip-api/SureVoIP-API/t/../lib/SureVoIP/API/Model/AuditLog.pm line 71 SureVoIP::API::Model::AuditLog::record('SureVoIP::API::Model::AuditLog', 'SureVoIP::API=HASH(0xe620fa0)', 'SureVoIP::API::Event=HASH(0x11f8f58)') called at t/45-auditlogs.t line 35 # Looks like your test exited with 255 just after 4 I've had to switch isa to a Str, but I lose a lot. Thanks.
Hi, The reason it's blowing up is that your `default` sub is returning a formatted string, not a `DateTime` object. Remove the `->format_cldr()` call, and it all works as expected. - ilmari
Subject: Re: [rt.cpan.org #130498] Milliseconds in builder
Date: Thu, 12 Sep 2019 12:37:14 +0100
To: bug-MooseX-Types-DateTime [...] rt.cpan.org
From: Gavin Henry <ghenry [...] suretecsystems.com>
Thanks. That's working.