A variant of the DateTime data type needed in VB.NET

A

Alan M Dunsmuir

I need to specify a new data type, almost entirely a 'clone' of the
existing DateTime type, with the following specific difference, and all
the consequent differences in properties and methods which this one
change implies.

The day immediately before Thursday September 14, 1752 should be
reported as Wednesday September 2, 1752, and so on, for all earlier
dates. Note that this change not only disrupts the steady sequence of
'one day at a time', but also breaks the mapping of Date on to
DayoftheWeek for all earlier dates, and Date on to DayoftheMonth and
DayoftheYear for earlier dates in 1752.

This is what actually occurred historically in the UK (and, I believe,
in North America) when the Gregorian calendar was finally adopted here.

I note that, since DateTime is a Value Type rather than a Reference
Type, I can neither inherit from it nor build a Class based on it. So it
would seem that a Structure has got to be the way to go. But I am not at
all sure of the detailed steps in building this, and getting it to work
as required.

Should this structure contain one or more (hidden) DateTime elements, to
facilitate use and adaptation of the existing properties and methods of
the underlying data type?

Would my structure be able to use the existing DateTime formatting
options once it has been built?
 
C

Cor Ligthert

Alan,

A datetime is actual a value that contains ticks from a certain start date
(which differs by instance when it is from a server or is internally).

You use methods to show that and to manipulate.

One of them is

DateTime.AddDays(-x), what is maybe the most properiate for you to use in a
routine.

Cor
 
A

Alan M Dunsmuir

Cor Ligthert said:
A datetime is actual a value that contains ticks from a certain start
date (which differs by instance when it is from a server or is
internally).

This would not solve the problem of the correct determination of the day
of the week, for dates prior to September 14, 1752. Nor would it
calculate correctly the number of days between two supplied dates.
 
J

Jay B. Harlow [MVP - Outlook]

Cor,
A datetime is actual a value that contains ticks from a certain start date
(which differs by instance when it is from a server or is internally).
A datetime is actually a value that contains "100-nanosecond units called
ticks, and a particular date is the number of ticks since 12:00 midnight,
January 1, 1 A.D. (C.E.) in the GregorianCalendar calendar."

http://msdn.microsoft.com/library/d.../cpref/html/frlrfSystemDateTimeClassTopic.asp

Notice it explicitly states that it is an instace from a specific point of
time.

This should not be confused with Local Time & Universal Time. Universal Time
is based on GMT, while Local Time is based your current local. In both cases
the value is represented by "the number of ticks since 12:00 midnight,
January 1, 1 A.D. (C.E.)"

Hope this helps
Jay
 
J

Jay B. Harlow [MVP - Outlook]

Alan,
Unfortunately because DateTime is a Structure you cannot extend (inherit
from) it.

Depending on the actual requirements for a different DateTime, I would:
- Introduce a Foreign Method
http://www.refactoring.com/catalog/introduceForeignMethod.html
- Define a "MyDateTime" Type that behaved correctly (more then likely a
Structure, but might be a Class)
- Introduce Local Extension
http://www.refactoring.com/catalog/introduceLocalExtension.html
- Create a custom System.Globalization.Calendar (attempting to understand
the limitations of doing so).
- Create a custom ICustomFormatter or IFormatProvider to adjust formatting
as needed...

Hope this helps
Jay
 
J

Jay B. Harlow [MVP - Outlook]

Cor,
The topic you give discusses Transact SQL, as hopefully you realize Transact
SQL datetime is *not* the same as System.DateTime.

Even in locals that use a different System.Globalization.Calendar object
(such as the HebrewCalendar or KoreanCalendar) the DateTime the value is
*still* represented by "the number of ticks since 12:00 midnight, January 1,
1 A.D. (C.E.)".

Universal Time & Local Time, as well as Globalization.Calendar simply change
the presentation/display/parsing of the DateTime value, not its internal
representation.

Hope this helps
Jay
 
C

Cor Ligthert

Jay,
The topic you give discusses Transact SQL, as hopefully you realize
Transact SQL datetime is *not* the same as System.DateTime.

Exactly therefore I answered in the way I did, trying to show that there are
more DateTime values.

Although the OP did not speak about that, it is for me as well obvious that
the OP is talking about the system.DateTime. However I did not explicitly
directly wanted react on that what I expected.

And the rest is exactly as you wrote, therefore I answered the OP in the way
I did and showed the calendar property page on which is a lot of information
about that. I hope you did not miss that.

Cor
 
J

Jay B. Harlow [MVP - Outlook]

Cor,
(shakes head). Again these comments don't really warrant a response either.

The OP stated in the subject "a variant of the DateTime data type needed in
VB.NET". Notice he specifically stated "in VB.NET"!

Hope this helps
Jay
 
C

Cor Ligthert

Jay,
(shakes head). Again these comments don't really warrant a response
either.

The OP stated in the subject "a variant of the DateTime data type needed
in VB.NET". Notice he specifically stated "in VB.NET"!

Hope this helps

No not in anyway.

I did not ask for your comments and those did not add anything to my
knowledge.

I leave it by this, because it does not help in anyway.

Cor
 
A

Alan M Dunsmuir

Cor Ligthert said:
I leave it by this, because it does not help in anyway.

Cor. Thank you for your attempts to help.

But your misunderstandings about what I was looking for, your
misdirections towards unhelpful issues, and your less-than-candid
attempts to post-justify your mistakes, in the event made your
contributions much less than useful.
 
M

Michael Proctor

Could I just add that at least Cor attempted to answer the question, and
even though it may not have been helpful, it is all we ask for in these
newsgroups, is it not?

I would think it pety to critisise other comments when all they were
attempting to do is assist (keyword, assist) they are not here to come up
with your solution. They are here to assist you in getting a solution.

This is not an attack on Jay or yourself Alan, I just feel that Cor did
attempt to help and in the end only got critisism in return.

Kind Regards,

Michael Proctor
 
C

Cor Ligthert

Michael,

Thanks, in fact did I give him direct in my first answer a solution, to show
you that in the day of week part, than it looks as this one in code instead
of words.

\\\
Dim dold As DateTime = New DateTime(1752, 9, 2)
MessageBox.Show(dold.AddDays(+11).DayOfWeek.ToString _
& " " & dold.ToString("MMMM dd, yyyy"))
////

In this way all can in my opinion be places in a shared class, which give
the corrected date to use for calculations or showing things as the day of
the week.

Someone who wants to inherit the datetime structure (what I answered as well
in my first message which is impossible) should in my opinion be able to do
this easy part himself.

I assume we probably think about this the same as we do about your message.

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top