Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
#14704: New function to wxDateTime to get wxDateSpan
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  12 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
wxTrac  
View profile  
 More options Sep 27 2012, 6:26 pm
From: "wxTrac" <nore...@wxsite.net>
Date: Thu, 27 Sep 2012 22:26:46 -0000
Local: Thurs, Sep 27 2012 6:26 pm
Subject: #14704: New function to wxDateTime to get wxDateSpan
Ticket URL: <http://trac.wxwidgets.org/ticket/14704>

#14704: New function to wxDateTime to get wxDateSpan
-------------------------+------------------------------------------------- -
 Reporter:  jonasr       |       Owner:    
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:    
Component:  base         |     Version:    
 Keywords:  wxDateTime   |   Blockedby:    
    Patch:  1            |    Blocking:    
-------------------------+------------------------------------------------- -
 Hi

 A new function to wxDateTime similar to
 {{{
 wxTimeSpan Subtract(const wxDateTime &dt)
 }}}
 which returns a wxDateSpan with all fields filled:
 {{{
 wxDateSpan SubtractDate(const wxDateTime &dt)
 }}}

--
Ticket URL: <http://trac.wxwidgets.org/ticket/14704>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "#14704: New function to get difference of two wxDateTime objects as a wxDateSpan (was: New function to wxDateTime to get wxDateSpan)" by wxTrac
wxTrac  
View profile  
 More options Sep 27 2012, 6:39 pm
From: "wxTrac" <nore...@wxsite.net>
Date: Thu, 27 Sep 2012 22:39:40 -0000
Local: Thurs, Sep 27 2012 6:39 pm
Subject: Re: #14704: New function to get difference of two wxDateTime objects as a wxDateSpan (was: New function to wxDateTime to get wxDateSpan)
Ticket URL: <http://trac.wxwidgets.org/ticket/14704#comment:1>

#14704: New function to get difference of two wxDateTime objects as a wxDateSpan
-------------------------+------------------------------------------------- -
 Reporter:  jonasr       |       Owner:          
     Type:  enhancement  |      Status:  confirmed
 Priority:  normal       |   Milestone:          
Component:  base         |     Version:          
 Keywords:  wxDateTime   |   Blockedby:          
    Patch:  1            |    Blocking:          
-------------------------+------------------------------------------------- -
Changes (by vadz):

  * status:  new => confirmed

Comment:

 Thanks for your patch, I agree that this could be useful.

 But I'm not sure if `SubtractDate()` is really a good name for it, I
 really would be hard pressed to explain how is it different from just
 `Subtract()`. I can propose `SubtractLogical()` but this is not ideal
 neither so what about a longer but perfectly clear `DiffAsDateSpan()`? It
 is inconsistent with `Subtract()`, of course, but OTOH it's really a
 different operation so I think clarity is more important than consistency
 here. But any other suggestions for the name would be welcome.

 Also, and this is really important, could you please add a few tests for
 the new function to
 [source:wxWidgets/trunk/tests/datetime/datetimetest.cpp
 tests/datetime/datetimetest.cpp]? If you have trouble with this, please
 see [source:wxWidgets/trunk/docs/tech/tn0017.txt the instructions].

 TIA!

--
Ticket URL: <http://trac.wxwidgets.org/ticket/14704#comment:1>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "#14704: New function to get difference of two wxDateTime objects as a wxDateSpan" by wxTrac
wxTrac  
View profile  
 More options Sep 27 2012, 6:56 pm
From: "wxTrac" <nore...@wxsite.net>
Date: Thu, 27 Sep 2012 22:56:11 -0000
Local: Thurs, Sep 27 2012 6:56 pm
Subject: Re: #14704: New function to get difference of two wxDateTime objects as a wxDateSpan
Ticket URL: <http://trac.wxwidgets.org/ticket/14704#comment:2>

#14704: New function to get difference of two wxDateTime objects as a wxDateSpan
-------------------------+------------------------------------------------- -
 Reporter:  jonasr       |       Owner:          
     Type:  enhancement  |      Status:  confirmed
 Priority:  normal       |   Milestone:          
Component:  base         |     Version:          
 Keywords:  wxDateTime   |   Blockedby:          
    Patch:  1            |    Blocking:          
-------------------------+------------------------------------------------- -

Comment(by jonasr):

 I'll think about the name. I wanted it to be as close to Subtract as
 possible, but perhaps i'ts too close.

 As for tests, I didn't find any tests for Subtract/Add in
 datetimetest.cpp, and the size of it, and its embedded python scripts,
 scared me.
 But now that i revisit it, I realize that operator- is an alias for
 subtract, so now i feel dumb. I'll try to cook up some tests.

--
Ticket URL: <http://trac.wxwidgets.org/ticket/14704#comment:2>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
wxTrac  
View profile  
 More options Sep 29 2012, 1:25 pm
From: "wxTrac" <nore...@wxsite.net>
Date: Sat, 29 Sep 2012 17:25:23 -0000
Local: Sat, Sep 29 2012 1:25 pm
Subject: Re: #14704: New function to get difference of two wxDateTime objects as a wxDateSpan
Ticket URL: <http://trac.wxwidgets.org/ticket/14704#comment:3>

#14704: New function to get difference of two wxDateTime objects as a wxDateSpan
-------------------------+------------------------------------------------- -
 Reporter:  jonasr       |       Owner:          
     Type:  enhancement  |      Status:  confirmed
 Priority:  normal       |   Milestone:          
Component:  base         |     Version:          
 Keywords:  wxDateTime   |   Blockedby:          
    Patch:  1            |    Blocking:          
-------------------------+------------------------------------------------- -

Comment(by jonasr):

 Writing the test I noted that arithmetics with the resulting wxDateSpan
 gives wrong results.

 Consider this:

 {{{
 wxDateTime dt1(11, wxDateTime::Jan, 1996);
 wxDateTime dt2(5, wxDateTime::Jun, 1998);
 wxDateSpan diff = dt2.DiffAsDateSpan(dt1);
 // now diff has years=1, months=28, weeks=125, days=0
 wxDateTime dt3 = dt1 + diff;
 // now dt3 = 2001-10-02, so dt3 != dt2
 }}}

 This is because DiffAsDateSpan fills all fields that it can, so calls to
 GetYears()/GetMonths()/GetDays() etc. returns correctly for the diff.
 But wxDateSpan::Add(const wxDateSpan&) uses all fields for adding, so it
 effectivly adds the span four times.
 This maybe is somewhat unexpected, so i make a not of it in the
 documentation.

 This means that writing a test that checks arithmetics is not possible, so
 the only thing I can think of is testing that the calculation of
 year/month/week/day is correct, hope that's ok.

--
Ticket URL: <http://trac.wxwidgets.org/ticket/14704#comment:3>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
wxTrac  
View profile  
 More options Sep 29 2012, 1:49 pm
From: "wxTrac" <nore...@wxsite.net>
Date: Sat, 29 Sep 2012 17:49:35 -0000
Local: Sat, Sep 29 2012 1:49 pm
Subject: Re: #14704: New function to get difference of two wxDateTime objects as a wxDateSpan
Ticket URL: <http://trac.wxwidgets.org/ticket/14704#comment:4>

#14704: New function to get difference of two wxDateTime objects as a wxDateSpan
-------------------------+------------------------------------------------- -
 Reporter:  jonasr       |       Owner:          
     Type:  enhancement  |      Status:  confirmed
 Priority:  normal       |   Milestone:          
Component:  base         |     Version:          
 Keywords:  wxDateTime   |   Blockedby:          
    Patch:  1            |    Blocking:          
-------------------------+------------------------------------------------- -

Comment(by vadz):

 Err, I think the implementation is wrong then (hence the usefulness of
 writing tests!). I'd expect the operation above to give "2 years, 4
 months, 25 days", i.e. the number of months should never be greater than
 12 in `wxDateSpan`. And if it worked like this, then addition would work,
 as expected.

--
Ticket URL: <http://trac.wxwidgets.org/ticket/14704#comment:4>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
wxTrac  
View profile   Translate to Translated (View Original)
 More options Sep 30 2012, 9:31 pm
From: "wxTrac" <nore...@wxsite.net>
Date: Mon, 01 Oct 2012 01:31:19 -0000
Local: Sun, Sep 30 2012 9:31 pm
Subject: Re: #14704: New function to get difference of two wxDateTime objects as a wxDateSpan
Ticket URL: <http://trac.wxwidgets.org/ticket/14704#comment:5>

#14704: New function to get difference of two wxDateTime objects as a wxDateSpan
-------------------------+------------------------------------------------- -
 Reporter:  jonasr       |       Owner:          
     Type:  enhancement  |      Status:  confirmed
 Priority:  normal       |   Milestone:          
Component:  base         |     Version:          
 Keywords:  wxDateTime   |   Blockedby:          
    Patch:  1            |    Blocking:          
-------------------------+------------------------------------------------- -

Comment(by jonasr):

 For my purpose, I needed to get a span that returns the actual diff
 between two dates for each part of
 GetYears()/GetMonths()/GetWeeks()/GetDays(), so I wanted GetMonths() to
 return 28 in example above. (btw, i see it's a typo in the example, year
 in diff is ofcourse 2, not 1)

 But I guess that this is a misunderstanding/misuse of wxDateSpan, and I
 agree that arithmetics should work as expected.
 Now this function is of no use to me, but if someone else finds it useful
 I made a new patch.

 Note that for the tests to pass, and to keep with how I understand
 wxDateSpan, weeks are set, so it's not exactly like your example, but
 rather "2 years, 4 months, 3 weeks, 4 days"

--
Ticket URL: <http://trac.wxwidgets.org/ticket/14704#comment:5>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
wxTrac  
View profile  
 More options Oct 1 2012, 5:44 am
From: "wxTrac" <nore...@wxsite.net>
Date: Mon, 01 Oct 2012 09:44:23 -0000
Local: Mon, Oct 1 2012 5:44 am
Subject: Re: #14704: New function to get difference of two wxDateTime objects as a wxDateSpan
Ticket URL: <http://trac.wxwidgets.org/ticket/14704#comment:6>

#14704: New function to get difference of two wxDateTime objects as a wxDateSpan
-------------------------+------------------------------------------------- -
 Reporter:  jonasr       |       Owner:          
     Type:  enhancement  |      Status:  confirmed
 Priority:  normal       |   Milestone:          
Component:  base         |     Version:          
 Keywords:  wxDateTime   |   Blockedby:          
    Patch:  1            |    Blocking:          
-------------------------+------------------------------------------------- -

Comment(by vadz):

 I think you may want to add `wxDateSpan::GetTotalMonths()` method, just as
 already have `GetTotalDays()`. Then you should be able to get the values
 that you need. Of course, it's not exactly difficult to write
 `12*GetYears()+GetMonths()` directly neither but I wouldn't be against
 adding such method if people think it can be useful.

 In the meanwhile I'll apply this patch, thanks!

--
Ticket URL: <http://trac.wxwidgets.org/ticket/14704#comment:6>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
wxTrac  
View profile  
 More options Oct 1 2012, 5:55 am
From: "wxTrac" <nore...@wxsite.net>
Date: Mon, 01 Oct 2012 09:55:07 -0000
Local: Mon, Oct 1 2012 5:55 am
Subject: Re: #14704: New function to get difference of two wxDateTime objects as a wxDateSpan
Ticket URL: <http://trac.wxwidgets.org/ticket/14704#comment:7>

#14704: New function to get difference of two wxDateTime objects as a wxDateSpan
--------------------------+------------------------------------------------ -
  Reporter:  jonasr       |       Owner:            
      Type:  enhancement  |      Status:  closed    
  Priority:  normal       |   Milestone:            
 Component:  base         |     Version:            
Resolution:  fixed        |    Keywords:  wxDateTime
 Blockedby:               |       Patch:  1        
  Blocking:               |  
--------------------------+------------------------------------------------ -
Changes (by VZ):

  * status:  confirmed => closed
  * resolution:  => fixed

Comment:

 (In [72600]) Add wxDateTime::DiffAsDateSpan().

 This method returns the difference between the dates as wxDateSpan, unlike
 the
 existing Subtract() and overloaded operator-() that return wxTimeSpan.

 Closes #14704.

--
Ticket URL: <http://trac.wxwidgets.org/ticket/14704#comment:7>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
wxTrac  
View profile  
 More options Oct 4 2012, 5:39 pm
From: "wxTrac" <nore...@wxsite.net>
Date: Thu, 04 Oct 2012 21:39:22 -0000
Local: Thurs, Oct 4 2012 5:39 pm
Subject: Re: #14704: New function to get difference of two wxDateTime objects as a wxDateSpan
Ticket URL: <http://trac.wxwidgets.org/ticket/14704#comment:8>

#14704: New function to get difference of two wxDateTime objects as a wxDateSpan
--------------------------+------------------------------------------------ -
  Reporter:  jonasr       |       Owner:            
      Type:  enhancement  |      Status:  reopened  
  Priority:  normal       |   Milestone:            
 Component:  base         |     Version:            
Resolution:               |    Keywords:  wxDateTime
 Blockedby:               |       Patch:  1        
  Blocking:               |  
--------------------------+------------------------------------------------ -
Changes (by jonasr):

  * status:  closed => reopened
  * resolution:  fixed =>

Comment:

 Here's a patch for {{{wxDateSpan::GetTotalMonths()}}}.

 But starting to use this function in my app, I'm embarrased to say that my
 previous patch had a couple of bugs in it. Turns out that the test I added
 were to trivial. Dates are tricky.
 Attached is a patch that fixes {{{wxDateTime::DiffAsDateSpan}}}, plus more
 extensive tests.

 Hope it's ok to add 2 patches to an old ticket like this.

 Regards
 //Jonas

--
Ticket URL: <http://trac.wxwidgets.org/ticket/14704#comment:8>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
wxTrac  
View profile  
 More options Oct 4 2012, 6:46 pm
From: "wxTrac" <nore...@wxsite.net>
Date: Thu, 04 Oct 2012 22:46:17 -0000
Local: Thurs, Oct 4 2012 6:46 pm
Subject: Re: #14704: New function to get difference of two wxDateTime objects as a wxDateSpan
Ticket URL: <http://trac.wxwidgets.org/ticket/14704#comment:9>

#14704: New function to get difference of two wxDateTime objects as a wxDateSpan
--------------------------+------------------------------------------------ -
  Reporter:  jonasr       |       Owner:            
      Type:  enhancement  |      Status:  reopened  
  Priority:  normal       |   Milestone:            
 Component:  base         |     Version:            
Resolution:               |    Keywords:  wxDateTime
 Blockedby:               |       Patch:  1        
  Blocking:               |  
--------------------------+------------------------------------------------ -

Comment(by vadz):

 If it helps, it's rare for me to write any non trivial code working with
 dates without bugs too. The best is to generate a lot of random data
 (there are small Python scripts embedded into the test, e.g. see
 source:wxWidgets/trunk/tests/datetime/datetimetest.cpp#L383) and check
 that everything works correctly with it.

 Will apply the fixes soon, thanks again!

--
Ticket URL: <http://trac.wxwidgets.org/ticket/14704#comment:9>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
wxTrac  
View profile  
 More options Oct 4 2012, 6:48 pm
From: "wxTrac" <nore...@wxsite.net>
Date: Thu, 04 Oct 2012 22:48:09 -0000
Local: Thurs, Oct 4 2012 6:48 pm
Subject: Re: #14704: New function to get difference of two wxDateTime objects as a wxDateSpan
Ticket URL: <http://trac.wxwidgets.org/ticket/14704#comment:10>

#14704: New function to get difference of two wxDateTime objects as a wxDateSpan
--------------------------+------------------------------------------------ -
  Reporter:  jonasr       |       Owner:            
      Type:  enhancement  |      Status:  reopened  
  Priority:  normal       |   Milestone:            
 Component:  base         |     Version:            
Resolution:               |    Keywords:  wxDateTime
 Blockedby:               |       Patch:  1        
  Blocking:               |  
--------------------------+------------------------------------------------ -

Comment(by VZ):

 (In [72615]) Add wxDateSpan::GetTotalMonths() method.

 This is similar to the existing GetTotalDays() and counts both months and
 years.

 See #14704.

--
Ticket URL: <http://trac.wxwidgets.org/ticket/14704#comment:10>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
wxTrac  
View profile  
 More options Oct 4 2012, 6:48 pm
From: "wxTrac" <nore...@wxsite.net>
Date: Thu, 04 Oct 2012 22:48:32 -0000
Local: Thurs, Oct 4 2012 6:48 pm
Subject: Re: #14704: New function to get difference of two wxDateTime objects as a wxDateSpan
Ticket URL: <http://trac.wxwidgets.org/ticket/14704#comment:11>

#14704: New function to get difference of two wxDateTime objects as a wxDateSpan
--------------------------+------------------------------------------------ -
  Reporter:  jonasr       |       Owner:            
      Type:  enhancement  |      Status:  closed    
  Priority:  normal       |   Milestone:            
 Component:  base         |     Version:            
Resolution:  fixed        |    Keywords:  wxDateTime
 Blockedby:               |       Patch:  1        
  Blocking:               |  
--------------------------+------------------------------------------------ -
Changes (by VZ):

  * status:  reopened => closed
  * resolution:  => fixed

Comment:

 (In [72616]) Fix bugs in the recently added wxDateTime::DiffAsDateSpan().

 Correct the test for negative spans less than a month and use the correct
 month for computing the number of days in it.

 Also add unit tests for problematic cases.

 Closes #14704.

--
Ticket URL: <http://trac.wxwidgets.org/ticket/14704#comment:11>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »