473,401 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 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 2306
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: SACHIN | last post by:
I have this class as part of a Consol application. using System; namespace Bugreport { /// <summary> /// This class tries to use the Class/Struct combination. /// </summary> class Class1 {
15
by: Fritz Switzer | last post by:
I'd like to have a string assigned the value of a DateTime.AddMinutes(amount) so that the string is formatted in "HH:MM" format. For example: DateTime.Now.AddMinutes(30) returns "00:30" ...
2
by: nic | last post by:
hey, I always struggle with the following: I have an object obj with a property paydate (type = DateTime) Now, after instantiating the object and do several things, I want too check if my...
44
by: Frank Rizzo | last post by:
Any ideas?
9
by: Phil B | last post by:
I am having a problem with a datetime from a web services provider The provider is sending the following SOAP response <?xml version="1.0" encoding="utf-8"?> <soap:Envelope...
0
by: David Pratt | last post by:
Hi. I am creating a couple of small methods to help me manage time from UTC as standard but I am getting strange results. If I start with a datetime of 2005-12-12 14:30:00 in timezone...
22
by: Merlin | last post by:
Hello everyone, I realize that I'm new to the group, but I'm hoping that someone might be able to help me out. What I'm doing is using the GNU 7zip command line utility to make a backup on my...
7
by: groups | last post by:
This is my first foray into writing a generic method and maybe I've bitten off more than I can chew. My intent is to have a generic method that accepts a value name and that value will be...
1
by: =?Utf-8?B?RGFwcGVyRGFuSEBub3NwYW0ubm9zcGFt?= | last post by:
Given the example below, can someone explain why TimeSpan.TotalDays gives a different result than subtracting 2 DateTime.ToOADates? I am completely stumped. Thanks in advance, Dan Example...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
jinu1996
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.