IS there a reason Timespan doesn't have an operator for divide? Being that
it's an amount of time I would have thought it should. Really it's just a
wrapper around a double variable?
Thanks,
Michael 11 6096
Michael,
It's not really a wrapper around a double variable. More like a 64 bit
integer.
You can always get the value of the Ticks property, divide it by two,
and create a new TimeSpan instance from that.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Michael C" <no****@nospam. comwrote in message
news:eg******** ******@TK2MSFTN GP04.phx.gbl...
IS there a reason Timespan doesn't have an operator for divide? Being that
it's an amount of time I would have thought it should. Really it's just a
wrapper around a double variable?
Thanks,
Michael
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c omwrote in
message news:B9******** *************** ***********@mic rosoft.com...
Michael,
It's not really a wrapper around a double variable. More like a 64 bit
integer.
Good point.
You can always get the value of the Ticks property, divide it by two,
and create a new TimeSpan instance from that.
Yes, in my case I just got total seconds and divided by 2 but I'm still
curious as to why there is no operator for divide. I guess seeing no one
came up with a reason that means the reason is MS simply forgot.
Michael
On Thu, 24 Jan 2008 16:55:16 -0800, Michael C <mi**@nospam.co mwrote:
[...] I guess seeing no one
came up with a reason that means the reason is MS simply forgot.
At best, it means that no one reading your post knows the answer.
You can't infer anything about the actual reason from a lack of responses.
Pete
"Peter Duniho" <Np*********@nn owslpianmk.comw rote in message
news:op******** *******@petes-computer.local. ..
At best, it means that no one reading your post knows the answer.
Got a reason then?
On Thu, 24 Jan 2008 18:25:46 -0800, Michael C <mi**@nospam.co mwrote:
"Peter Duniho" <Np*********@nn owslpianmk.comw rote in message
news:op******** *******@petes-computer.local. ..
>At best, it means that no one reading your post knows the answer.
Got a reason then?
Why do I need an answer to the question just to point out that there's no
way (at present) to know the answer to the question? What would the point
be in pointing out that we don't know the reason if I actually knew the
reason?
"Peter Duniho" <Np*********@nn owslpianmk.comw rote in message
news:op******** *******@petes-computer.local. ..
>Got a reason then?
Why do I need an answer to the question just to point out that there's no
way (at present) to know the answer to the question? What would the point
be in pointing out that we don't know the reason if I actually knew the
reason?
Well, I'm sure if there was a reason a smart guy like you would know it.
Michael C wrote:
Yes, in my case I just got total seconds and divided by 2 but I'm still
curious as to why there is no operator for divide. I guess seeing no one
came up with a reason that means the reason is MS simply forgot.
I am with Peter on this, just because it wasn't done doesn't mean they forgot.
The possibility which makes the most sense to me relates to code clarity. Making
you use a property of the TimeSpan makes it perfectly clear what property you
are doing the math on, and what your expected result would be.
I'm not saying it's a perfect reason to not do it, I'm just guessing and don't
know any more than the people who have already spoken up.
Chris.
"Chris Shepherd" <ch**@nospam.ch sh.cawrote in message
news:ug******** ******@TK2MSFTN GP04.phx.gbl...
I am with Peter on this, just because it wasn't done doesn't mean they
forgot.
The possibility which makes the most sense to me relates to code clarity.
Making you use a property of the TimeSpan makes it perfectly clear what
property you are doing the math on, and what your expected result would
be.
I'm not saying it's a perfect reason to not do it, I'm just guessing and
don't know any more than the people who have already spoken up.
To me it made such perfect sense that I went and coded it fully expecting it
to work. I was quite suprised some time later to get a compile error. The
alternative:
TimeSpan ts2 = new TimeSpan(ts1.Ti cks / 2)
appears much more complicated and although I presume that is the correct way
to do it I'm still not certain. Should I convert it to Milliseconds and back
or maybe seconds? Should I be using a double variable or an integer or long?
The only thing I can think of is that doing "ts1 / 2" it's not clear how it
will round but I don't think that's much of an issue. Obviously programmers
will expect it to have a certain level of resolution and that dividing by 2
could cause some minor loss of information.
Michael
Michael C wrote:
To me it made such perfect sense that I went and coded it fully expecting it
to work. I was quite suprised some time later to get a compile error. The
alternative:
TimeSpan ts2 = new TimeSpan(ts1.Ti cks / 2)
appears much more complicated and although I presume that is the correct way
to do it I'm still not certain. Should I convert it to Milliseconds and back
or maybe seconds? Should I be using a double variable or an integer or long?
The only thing I can think of is that doing "ts1 / 2" it's not clear how it
will round but I don't think that's much of an issue. Obviously programmers
will expect it to have a certain level of resolution and that dividing by 2
could cause some minor loss of information.
If you divide one int by another, the result is not rounded, it is truncated. If
you divide 99 by 100 the integer result is 0. This is likely why a TimeSpan,
which is purported by others to be just a wrapper for Int64, wouldn't have a
divisor or multiplier implementation.
If you need to ensure rounding occurs, you'll need to store it in a more precise
type and then round it back to an integer.
Chris. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Jeff Shantz |
last post by:
Hello,
I'm developing a large statistics application for a call center. It often needs to calculate time spanning over months. For example, an agent's total talk time within 30 days. Since an agent talks about 5 hours per day, this comes out to about 150 hours of talk time per month. Fine.
But, the DateTime and TimeSpan format strings will only output hours from 0-23. I need something that will output time as such:
150:0:0
to...
|
by: Ivan A. |
last post by:
Hi!
Why I can't serialize TimeSpan structure with XmlSerializer? This is what I
do:
using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
|
by: Russ Green |
last post by:
How does this:
public TimeSpan Timeout
{
get { return timeout; }
set
{
timeout = value;
if(timeout < licenseTimeout)
licenseTimeout = timeout;
}
|
by: DWalker |
last post by:
In Visual Studio (Visual Basic) .NET 2002, I noticed that this:
Dim Elapsed as DateTime = Now - Now
gives a "compile time" error (error in the IDE), saying that the '-'
operator is not defined for the Date datatype. On the other hand,
Dim Elapsed as DateTime = Now + Now
does not give a compile time error but it thinks you're trying to
|
by: Charles Law |
last post by:
If I display a TimeSpan I get something like
00:05:17.6217891
when what I would like to see is
00:05:18
Is there an easy way to get this output? Try as I might I just can't find
it.
| |
by: ucasesoftware |
last post by:
i translate a C# funtion to VB.NET and i have this :
Shared Function isAllDay(ByVal ap As Appointment) As Boolean
Return ap.DateBegin.TimeOfDay = TimeSpan.Zero AndAlso
ap.DateEnd.TimeOfDay = TimeSpan.Zero
End Function
Error :
= is not corret
|
by: Dennis D. |
last post by:
Hello:
I want to subtract a timespan from the selectionrange.start of a month
calendar.
The selectionrange.start of a month calendar is a date, and it is possible
to subtract a timespan from a date and get a date, from which I will extract
the day.
How do I assign an integer to represent an 'n' day timespan, especially
without using ticks?
|
by: sd00 |
last post by:
Hi all, can someone give me some coding help with a problem that
*should* be really simple, yet I'm struggling with.
I need the difference between 2 times (Target / Actual)
However, these times will fall somewhere between a Start & End time
Further more, there will be Break & Lunch times between Start & End.
Example...
Start 08:00
Break start 10:30
|
by: style |
last post by:
Hello
In my custom configuration section, I'd like to specify an interval
attribute which specifies an interval in milliseconds. I think it would be
very comfortable to get this value directly as a TimeSpan. That's what I
tryied:
public TimeSpan Interval
{
|
by: Massimo |
last post by:
Hi to All,
i'm using C# in .NET 2.0 and i have a DataTable A with a column of
type TimeSpan used to store HOUR info.
I'm trying to filter my DataTable A selecting only rows that have the
column HOUR ....
if i try to Call A.Select( " HOUR '10:30:00' " ) i receive an error
( cannot compare TimeSpan with String ...)
if i try to call A.Select ( " HOUR 10:30:00 " ) i receive an error
( invalid token : )
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |