Gray's Matter
Justice Gray - North America's favorite metrosexual software consultant
E-mail Justice
Subscribe to this feed
Subscribe to comments
Perennially Popular Posts
How to write a presentation abstract
My grandmother, globalization, and what's wrong with DateTime.Parse
A letter to my Worldvision sponsor child
Development Methodologies for the 21st Century
My grandmother & the difference between strong typing and weak typing
How I am becoming a better developer, part 1 of infinity
Facebook RSS Feeds: How to Write Your Own With C#
The Ten Keys To Happiness
My grandmother and the Global Assembly Cache (And Star Wars)
My grandmother and the difference between processes and threads
How to make a meeting request
Why you should never be an independent consultant
The DasBlog 1.9 AJAX Autosave True Story, Part 2
Other "metro" developers
Ben Scheirman
Bil Simser
D'Arcy Lussier
David Woods
Donald Belcham
Donald Jessop
George Clingerman
James Kovacs
Jason Hunt
Jason Row
Jean-Paul Boodhoo
Jeffrey Palermo
Joey deVilla
John Bristowe
Jonas Avellana
Kyle Baley
Mack Male
Martin Hinselwood
Michael McClenaghan
Mike Duncan
Mike Friesen
Mo Khan
Otyce
RoboSapient
Russell Ball
Scott Hanselman
Scott Reynolds
Steven Rockarts
Tech Embassy
Terry Thibodeau
Tom Opgenorth
Vladimir Levin
The Justice Gray Fan Club
Amazing Mrs. Loquacious
Dr. Teeth
Facedown
Janey Lynne
Maxime Lamy
Ridley Thunder
Stan Woo
Vanilla Con
Wobbly*Bits
I Wish These People Updated More Than Once a Year
Anand Narayan
Jeff Perrin
<< Donald Belcham, internet legend
Donald Belcham is now a MICROSOFT MVP~~~!!!!!! >>
My grandmother, globalization, and what's wrong with DateTime.Parse
I thought I would continue my seeming tradition of hitting these questions once every 6 months. Actually, I had given up on Granny getting into
Corillian
but that's okay; she's seen the light and is now an independent consultant! Nonetheless, I have still felt the need to answer some of
Scott Hanselman's
old
interview
questions
in an attempt to help get her up to speed.
So, without further adieu, let's tell two stories about marriages:
Story #1:
My sister-in-law
is getting married this coming May. I had a chance to meet her
future husband's
parents this past Christmas, both of whom are from Quebec and primarily speak French. As is my custom when I am meeting new people, I tried to amp up the patented
Justice Gray charm
™ and impress them with the French I vaguely remembered from about a decade and a half ago. I introduced myself ("
Je m'appelle Justice
") and then decided to follow up with the coup de grace:
terrifically witty banter
.
"The French I am speaking now is the only French I know!"
I paused for laughter - but instead was met with nervous silence!! In this moment, I finally learned what
Donald
goes through at the beginning of every
EDMUG
meeting.
I was definitely a little confused; after all that sentence should have been a
guaranteed laugh riot
. My future brother-in-law came up to me and quietly whispered,
"I think I understood what you were saying, but my parents actually think you have some sort of handicap now"
It seems instead of my intended phrase, I had stated something closer to
"I speak French. French speak!! Only French!! I know speak!!!"
Fortunately, I solved the awkwardness that night like anyone would:
by getting *completely hammered*
.
Speaking of solving all of the world's problems through excessive alcohol consumption , let's go onto story #2.
As most of you know, I was married a year and a half ago. What many of you don't know is that one of my groomsmen, flush with alcohol and ready to try and impress the ladies, decided to go to one of the bridesmaids and show off his *fluent* knowledge of Cantonese. Whatever his planned come-on line was will forever remain a mystery. I wish I could say the same for the translation of what he *did* say, which was,
"Boy, I'd really like to sleep with your mother."
So, what's the problem here?
Lost or unclear intent through translation
, or lack thereof. This is also the difficulty Scott Hanselman was referring to when he asked
"What’s wrong with a line like this? DateTime.Parse(myString);"
This line on its own seems pretty simple - after all, you're just asking for the runtime to take a standard string and convert it into a DateTime object.
DateTime myDate = DateTime.Parse("10/06/2006");
What's the value for myDate.Month and myDate.Day?
And therein lies the problem:
there is no way for you to tell me this without knowing additional information
.
For example, if I am running this with an English culture, the DateTime object represents October 6, 2006. However, if I ran this same line on a computer with its culture set to French (or if the application's culture was set to French), then the DateTime object now represents a completely different date (June 10, 2006, to be precise). This happens because French dates reverse the position of the month and the day.
To get around this, always pass Culture information as the second argument to DateTime.Parse, as in the following:
DateTime myDate = DateTime.Parse("10/06/2006", System.Globalization.CultureInfo.GetCulture("fr-FR"));
Now, obviously you wouldn't want to do a culture retrieval every single time you call DAteTime.Parse! Your application should probably be setting the culture itself, somewhat like the following
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.GetCultureInfo("fr-FR");
DateTime myDate = DateTime.Parse("10/06/2006", System.Globalization.CultureInfo.CurrentCulture)
This sets the culture for the particular thread of execution that your current user is experiencing.
You might not think that globalization errors are as embarassing as the two stories I talked about earlier. Trust me, in the context of a globalized application, they are even worse. Take this tip and use it to save yourself humiliation in code reviews everywhere!
Previous entries in this series:
My grandmother and the Global Assembly Cache (and Star Wars)
My grandmother and the difference between processes and threads
My grandmother and the difference between HTTP GET and HTTP POST
Monday, March 26, 2007
Comments [16]
HanselmanQuestions
|
Technical
|
Tracked by:
"We're through, Jason Haley" (Gray's Matter)
[Trackback]
"My grandmother and the difference between strong-typing and weak-typing" (Gray'...
[Trackback]
3/26/2007 10:09:39 AM (Mountain Daylight Time, UTC-06:00)
Good post, honey! I actually laughed out loud this time! ;)
And wasn't our groomsman saying that about *my* mother, no less? Proof that alcohol can rot even the smartest brain!
MrsLoquacious
3/26/2007 10:13:08 AM (Mountain Daylight Time, UTC-06:00)
I thought you laugh out loud at every post I make?!?!
MY LIFE IS A LIE
Justice
3/26/2007 10:17:15 AM (Mountain Daylight Time, UTC-06:00)
Dude, what's up? A technical post? I was expecting to read something about Transformers or Macs.
Tom Opgenorth
|
tomAT NOSPAMopgenorth dot net
3/26/2007 10:19:28 AM (Mountain Daylight Time, UTC-06:00)
Well, every so often I need to take a break from the Mac/Transformer thing, though I love it a lot. Don't worry, I'll try not to post anything technical for another 6 months ;)
Justice
3/26/2007 1:43:45 PM (Mountain Daylight Time, UTC-06:00)
Thanks for this post Justice! Today I used this to illustrate to a developer why just having something like the XmlSerializer deserialize a DateTime without declaring the culture was a bad idea (especially since the agreed upon date format was NOT the same as the default culture of the machine we were testing on).
JH
3/27/2007 8:37:19 AM (Mountain Daylight Time, UTC-06:00)
when you said "Je m'appelle Justice"
How did you pronounce Justice?
In its English way, or French sexy way?
anonymous
3/27/2007 10:03:40 AM (Mountain Daylight Time, UTC-06:00)
I wonder if it wouldn't be better to actually specify the format of the date along with the date itself...
Vladimir Levin
|
aphelionxAT NOSPAMhotmail dot com
3/27/2007 10:48:30 AM (Mountain Daylight Time, UTC-06:00)
Hahaha! nice ;)
Keith Rull
|
keith dot rullAT NOSPAMgmail dot com
3/27/2007 12:03:00 PM (Mountain Daylight Time, UTC-06:00)
WHO CARES WHAT YOU THINK VLAD
*ahem* ;)
Actually, you are quite correct depending on the situation. =) I will have to edit the post after to add that in.
Justice
3/27/2007 12:03:49 PM (Mountain Daylight Time, UTC-06:00)
Anonymous - no matter what method or language in which I say "Justice", it's *always* a sexy way. ;)
Justice
3/28/2007 11:39:11 AM (Mountain Daylight Time, UTC-06:00)
lol.
I think I know what that guy said.
Ok, I better go back and finish this tech article.
Haiyan
|
bahaiyanAT NOSPAMhotmail dot com
4/1/2007 6:05:26 PM (Mountain Daylight Time, UTC-06:00)
Absolutely brilliant. This is a great way to make your point.
Brent
|
brentAT NOSPAMbrentanderica dot net
12/7/2007 5:26:25 AM (Mountain Standard Time, UTC-07:00)
I believe that finding a good husband is a tedious task but not an impossible one.
Marriage Counselor
|
sergiuAT NOSPAMyahoo dot com
3/22/2008 9:39:37 AM (Mountain Daylight Time, UTC-06:00)
discount lowest cost butalbital
ordering original butalbital
|
healthcoveAT NOSPAMlawley dot org
3/22/2008 9:45:46 AM (Mountain Daylight Time, UTC-06:00)
Tramadol Us
Generic tramadol information
|
carshowAT NOSPAMrelaedracwen dot com
6/9/2008 7:34:55 AM (Mountain Daylight Time, UTC-06:00)
Your stories are very funny. I had a good laugh reading them and I have to tell you that you could always be hired for a comedy show so get ready because you never know what life has prepared for you...
Alcohol Treatment
|
soarele_negruAT NOSPAMyahoo dot com
Name
E-mail
Home page
Remember Me
Comment (HTML not allowed)
Enter the code shown (prevents robots):
Justice Gray
: a seething cauldron of rampaging masculinity. A fighter! A brother! Your
secret lover
! He's also a software development consultant and the Vice President of the
Edmonton .NET user group
. He also greatly enjoys speaking about himself in the 3rd person.
Gray's Matter Archives
Recent Posts
Controversy clarifications!
The most controversial interview of ALL TIME
Finally! The *winner* of the "What Justice Gray Means to Me" contest
The mystery of D'Arcy Lussier's ASP.NET MVP is solved...
Well, now that's pretty horrifying
MVPs on MVC: "No, we don't have any idea either"
Why I am happy to not be at the MVP Summit
Donald Belcham's cry for help: MS MVPs, your attention is needed
ALT.NET Pursefighting revealed
Test, please ignore!
Change yourself, change the world: a great week 4
Post Categories
BookReviews
Conferences
DasBlog
EDMUG
Goals
HanselmanQuestions
HotDeveloperCorner
ILiveToInform
Leadership
Mac
OtherGrayAreas
Personal
Productivity
Ruby
Suresh
Technical
Transformers
Vancouver
Wii
<
July 2008
>
Sun
Mon
Tue
Wed
Thu
Fri
Sat
29
30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
Sign In