By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,237 Members | 1,842 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,237 IT Pros & Developers. It's quick & easy.

System.DateTime without range check

P: n/a
Is there any way to construct a System.DateTime which doesn't check
year, month and day to be in correct range== no validation?

Thanks
A.V.Ebrahimi
Nov 15 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Are you talking about allowing dates such as February 31?

"Abdolhosein Vakilzadeh Ebrahimi" <va********@kzlabs.com> wrote in message
news:b9**************************@posting.google.c om...
Is there any way to construct a System.DateTime which doesn't check
year, month and day to be in correct range== no validation?

Thanks
A.V.Ebrahimi

Nov 15 '05 #2

P: n/a
Hi,

Why would you need that for?

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

"Abdolhosein Vakilzadeh Ebrahimi" <va********@kzlabs.com> wrote in message
news:b9**************************@posting.google.c om...
Is there any way to construct a System.DateTime which doesn't check
year, month and day to be in correct range== no validation?

Thanks
A.V.Ebrahimi

Nov 15 '05 #3

P: n/a
I need it to store persian ( farsi ) dates, which days per month are
different from georgians.

Also would you please let me know how to install farsi calendar on
Windows?

Thanks
Nov 15 '05 #4

P: n/a
Hi Abdolhosein,

"Abdolhosein Vakilzadeh Ebrahimi" <va********@kzlabs.com> wrote in message
news:b9**************************@posting.google.c om...
I need it to store persian ( farsi ) dates, which days per month are
different from georgians.
System.DateTime can optionally take a System.Globalization.Calendar object
as an argument to its constructor. Calendar objects contain information
about such things as (a) how many months there are; (b) how long each month
is; (c) when leap years occur, etc.

The default calendar is System.Globalization.GregorianCalendar, and as you
noticed, System.DateTime will throw an exception if you try to set it to,
e.g., month 2, day 31 ("Ordibehesht 31st" in the Farsi/Jalaali calendar,
which a legal date). This is because System.Globalization.GregorianCalendar
tells System.DateTime that month 2 has only 28 (sometimes 29) days.

Unfortunately the versions of the .NET Framework that have shipped so far do
not include a definition for the Jalaali calendar. (Although there will be
a System.Globalization.JalaaliCalendar class in the next version.) So you
basically have two choices, neither of which is very appealing:

1. You create your own JalaaliCalendar class (deriving from
System.Globalization.Calendar) and pass this to System.DateTime.

2. You avoid using the System.DateTime.AddDays(), AddMonths(), etc., methods
(as well as the System.DateTime constructors that take year, month or day
parameters) and operate exclusively over ticks (100-nanosecond intervals).
You can construct System.DateTime objects by passing a tick value and you
can use the AddTicks() method to modify existing ones. Internally
System.DateTime represents points in time as the number of ticks that have
elapsed since 12:00:00 midnight, January 1, 0001 A.D. You could create your
own logic for converting Jalaali dates into ticks and operate through that
"translation layer".

The first solution is definitely better if you can manage it.
Also would you please let me know how to install farsi calendar on
Windows?


I'm not sure exactly what you mean by this, but if you install support for
Farsi through the Control Panel | Regional and Language Settings |
Supplemental Language Support | Install files for complex script and
right-to-left languages you should also get the Farsi standards and formats
installed (numbers, currency, time, date formats). You can select your
preference for these formats through Control Panel | Regional and Language
Settings | Standards and Formats. (All of this information applies to
Windows XP.)

Good luck,
Nick

-------------------------------------------------------------------------
This posting is provided "AS IS" with no warranties, and confers no rights.
Nov 15 '05 #5

P: n/a
I meant how to install Jalaali calendar in windows, if there is any.

Thanks for quick reply.
Nov 15 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.