Skip to content
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

DateTime.hour (and similar methods) should return an Int in Rakudo #2174

Closed
p6rt opened this issue Sep 17, 2010 · 5 comments
Closed

DateTime.hour (and similar methods) should return an Int in Rakudo #2174

p6rt opened this issue Sep 17, 2010 · 5 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Sep 17, 2010

Migrated from rt.perl.org#77910 (status was 'resolved')

Searchable as RT77910$

@p6rt
Copy link
Author

p6rt commented Sep 17, 2010

From @masak

<flussence> rakudo​: say "good {<morning day
evening>[DateTime.now.hour.Int div 8]}, #perl6"
<p6eval> rakudo 2c8bb8​: OUTPUT«good day, #perl6␤»
<masak> flussence++
<moritz_> "hello my friend, how are you, good evening, day or
morning\n I'm as happy to see you as the last time I was here 'cause
this is a recording"
<moritz_> (Rob Paravonian)++
<LoRe> why is .Int required in [DateTime.now.hour.Int div 8] ?
<masak> LoRe​: because `div` isn't specific to Ints.
<flussence> rakudo​: say DateTime.now.hour.WHAT
<p6eval> rakudo 2c8bb8​: OUTPUT«Num()␤»
<masak> oh, and that.
<masak> maybe .hour should return an Int already.
<flussence> seems like the sensible thing to do
<masak> aye.
* masak submits rakudobug

@p6rt
Copy link
Author

p6rt commented Sep 18, 2010

From @kyleha

This is an automatically generated mail to inform you that tests are now available in S32-temporal/DateTime.t

commit a32217d59ab879347a7f6773faa8a39b7249ec03
Author​: Kodi Arfer <hippo@​Thoth.(none)>
Date​: Sat Sep 18 17​:02​:02 2010 -0400

  [DateTime.t] Added tests for RT #​77910.

Inline Patch
diff --git a/S32-temporal/DateTime.t b/S32-temporal/DateTime.t
index d4019bf..a8f4179 100644
--- a/S32-temporal/DateTime.t
+++ b/S32-temporal/DateTime.t
@@ -1,7 +1,7 @@
 use v6;
 use Test;
 
-plan 149;
+plan 167;
 
 my $orwell = DateTime.new(year => 1984);
 
@@ -437,6 +437,34 @@ is dt(timezone => 3661).offset, 3661, 'DateTime.offset (1 hour, 1 minute, 1 seco
     is ~$dt, '2007-03-11T03:02:00-0700', 'DateTime.in-timezone (NYC to LAX, just after LAX DST)';
 }
 
+# --------------------------------------------------------------------
+# Miscellany
+# --------------------------------------------------------------------
+
+# RT #77910
+# Ensure that any method of producing a DateTime keeps attributes
+# that should be Ints Ints.
+{
+    isa_ok dt(second => 1/3).year, Int, 'DateTime.new(...).year isa Int';
+    isa_ok dt(second => 1/3).hour, Int, 'DateTime.new(...).hour isa Int';
+    isa_ok dt(hour => 13, second => 1/3).hour, Int, 'DateTime.new(..., hour => 13).hour isa Int';
+    isa_ok dtc(second => 1/3).year, Int, '$dt.clone(...).year isa Int';
+    isa_ok dtc(second => 1/3).hour, Int, '$dt.clone(...).hour isa Int';
+    isa_ok dtc(hour => 13, second => 1/3).hour, Int, '$dt.clone(..., hour => 13).hour isa Int';
+    isa_ok DateTime.new(5).year, Int, 'DateTime.new(Int).year isa Int';
+    isa_ok DateTime.new(5).hour, Int, 'DateTime.new(Int).hour isa Int';
+    isa_ok DateTime.new(now).year, Int, 'DateTime.new(Instant).year isa Int';
+    isa_ok DateTime.new(now).hour, Int, 'DateTime.new(Instant).hour isa Int';
+    isa_ok ds('2005-02-04T15:25:00Z').year, Int, 'ds(Str).year isa Int';
+    isa_ok ds('2005-02-04T15:25:00Z').hour, Int, 'ds(Str).hour isa Int';
+    isa_ok dt.in-timezone(60*60).year, Int, 'dt.in-timezone(Int).year isa Int';
+    isa_ok dt.in-timezone(60*60).hour, Int, 'dt.in-timezone(Int).hour isa Int';
+    isa_ok dt.truncated-to(:week).year, Int, 'dt.truncated-to(:week).year isa Int';
+    isa_ok dt.truncated-to(:week).hour, Int, 'dt.truncated-to(:week).hour isa Int';
+    isa_ok DateTime.now.year, Int, 'DateTime.now.year isa Int';
+    isa_ok DateTime.now.hour, Int, 'DateTime.now.hour isa Int';
+}
+
 done_testing;
 
 # vim: ft=perl6

@p6rt
Copy link
Author

p6rt commented Sep 18, 2010

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Sep 18, 2010

From @Kodiologist

Fixed in 12088a851a737; thanks!

@p6rt
Copy link
Author

p6rt commented Sep 18, 2010

@Kodiologist - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Sep 18, 2010
@p6rt p6rt added the Bug label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant