473,382 Members | 1,302 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,382 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 2304
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.