471,326 Members | 2,219 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,326 software developers and data experts.

DateTime equivalent struct with start/end properties

Hello!

As part of a refactoring iteration, I was looking at consolidating two
properties (Start and EndDate) to a single structure that would allow a
single access point for the "duration" (so to speak).

I considered using the TimeSpan, but that structure doesn't provide the
boundaries for the "duration", only the length of the "duration" itself.

The obvious step next would be creating my own structure that provided these
boundaries - except that I have a feeling this is already present in the
framework (or sounds like it should be). Am I looking for something that
doesn't exist? :)

Thanks in advance!

--
With regards
Anders Borum / SphereWorks
Microsoft Certified Professional (.NET MCP)
Dec 22 '05 #1
7 2227
Anders,

Why not something like this:

public struct Duration
{
public DateTime Start;
public DateTime End;
}

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Anders Borum" <an****@sphereworks.dk> wrote in message
news:ei**************@TK2MSFTNGP11.phx.gbl...
Hello!

As part of a refactoring iteration, I was looking at consolidating two
properties (Start and EndDate) to a single structure that would allow a
single access point for the "duration" (so to speak).

I considered using the TimeSpan, but that structure doesn't provide the
boundaries for the "duration", only the length of the "duration" itself.

The obvious step next would be creating my own structure that provided
these boundaries - except that I have a feeling this is already present in
the framework (or sounds like it should be). Am I looking for something
that doesn't exist? :)

Thanks in advance!

--
With regards
Anders Borum / SphereWorks
Microsoft Certified Professional (.NET MCP)

Dec 23 '05 #2
I put up a DateRange and SqlDateRange classes and DateFunction static class
helper lib at http://channel9.msdn.com/ShowPost.aspx?PostID=147390 that does
this. You can ignore all the sql stuff and just look at DateRange class for
example of doing this.
--
William Stacey [MVP]

"Anders Borum" <an****@sphereworks.dk> wrote in message
news:ei**************@TK2MSFTNGP11.phx.gbl...
Hello!

As part of a refactoring iteration, I was looking at consolidating two
properties (Start and EndDate) to a single structure that would allow a
single access point for the "duration" (so to speak).

I considered using the TimeSpan, but that structure doesn't provide the
boundaries for the "duration", only the length of the "duration" itself.

The obvious step next would be creating my own structure that provided
these boundaries - except that I have a feeling this is already present in
the framework (or sounds like it should be). Am I looking for something
that doesn't exist? :)

Thanks in advance!

--
With regards
Anders Borum / SphereWorks
Microsoft Certified Professional (.NET MCP)

Dec 23 '05 #3
In .Net 2.0 framework, try the System.Diagnostics.StopWatch Class

Dec 23 '05 #4
<La*****@gmail.com> wrote:
In .Net 2.0 framework, try the System.Diagnostics.StopWatch Class


That just gives an elapsed time as far as I can see - and not one that
you can change manually.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 23 '05 #5
Hello!

I already use the StopWatch class in another part of the application and I
don't think using this type as a public property on types that will be
instantiated really often (i.e. thousands).

The implementation used a start / end date, but businesslogic implied that
the starting date should be less than the ending date (obviously). This
caused a validation exception to be thrown if the programmer was assigning a
startdate greater than enddate and so on .. as part of setting i.e. a future
duration.

So I wrote some sample lines of C# to see, how the API would make the most
sense in client code (the Brad Abrams way), and decided to change the
interface.

A dedicated structure to handle this is probably the way to go. I was
looking for a native BCL class, but will probably have to wait until 3.0 to
see this :)

Thanks for the input!

--
Venlig hilsen
Anders Borum / SphereWorks
Microsoft Certified Professional (.NET MCP)
Dec 23 '05 #6
Great!

I'll get the code and see what you've been implemented. However, we've
already created a custom structure here that works quite well but it's
always interesting to see other solutions.

Thanks for all the input.

--
Venlig hilsen
Anders Borum / SphereWorks
Microsoft Certified Professional (.NET MCP)
Dec 23 '05 #7
Anders,
In addition to the other comments.

I have a Range(Of T), DateRange & TimeRange available at:

http://www.tsbradley.net/Cookbook/Ge...ericRange.aspx
http://www.tsbradley.net/Cookbook/Pa...dateRange.aspx
http://www.tsbradley.net/Cookbook/Pa...timeRange.aspx

One should be able to easily convert the above to C# if needed.

My DateRange will ignore the respective Time parts of the DateTime values,
while the TimeRange will ignore the respective Date parts, plus it handles
ranges spanning midnight.

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Anders Borum" <an****@sphereworks.dk> wrote in message
news:ei**************@TK2MSFTNGP11.phx.gbl...
| Hello!
|
| As part of a refactoring iteration, I was looking at consolidating two
| properties (Start and EndDate) to a single structure that would allow a
| single access point for the "duration" (so to speak).
|
| I considered using the TimeSpan, but that structure doesn't provide the
| boundaries for the "duration", only the length of the "duration" itself.
|
| The obvious step next would be creating my own structure that provided
these
| boundaries - except that I have a feeling this is already present in the
| framework (or sounds like it should be). Am I looking for something that
| doesn't exist? :)
|
| Thanks in advance!
|
| --
| With regards
| Anders Borum / SphereWorks
| Microsoft Certified Professional (.NET MCP)
|
|
Dec 25 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

15 posts views Thread by Fritz Switzer | last post: by
2 posts views Thread by nic | last post: by
44 posts views Thread by Frank Rizzo | last post: by
9 posts views Thread by Phil B | last post: by
reply views Thread by David Pratt | last post: by
1 post views Thread by =?Utf-8?B?RGFwcGVyRGFuSEBub3NwYW0ubm9zcGFt?= | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.