A web application or a web service may be located in multiple geographical locations for redundancy or performance reasons. Irrespective of their physical location, the behavior should be consistent from the user’s perspective of view. Consider a situation where a bank customer located on the east coast is trying to open an online account using the bank’s website that is hosted on the west coast. There is a 3 hour time difference between the two locations. If the user is opening an account at 1 am August 2 EST, it is equivalent of 10 pm August 1 PST. If no time difference is considered, then the actual account date creation and recorded date creation would differ.
Web services use Universal Standard Time for Date representation. The UTC Date and time format is independent of time zones. Web services expect Date inputs to be represented in the UTC format. It is up to the developer to ensure that all Date inputs are converted to UTC format before making a web service request call. C# makes this operation trivial because of its rich DateTime data structure.
DateTime todayDate = DateTime.Now.ToUniversalTime(); client.CreateAccount(todayDate);
Opposite operation needs to be performed when web service response is received. The UTC date and time needs to be converted to a local date and time.
DateTime todayDate = client.GetAccountDate(); todayDate = todayDate.ToLocalTime();
The time zone difference is a prime example of challenges that we as developers need to be aware of when developing web application or web services.
Programu ya mtandao au huduma ya mtandao inaweza kuwa iko katika maeneo mbalimbali ya kijiografia kwa sababu ya redundancy au utendaji. Bila kujali eneo lao la kimwili, tabia inapaswa kuwa thabiti kutoka kwa mtazamo wa mtumiaji. Fikiria hali ambapo mteja wa benki iko katika pwani ya mashariki ni kujaribu kufungua akaunti online kutumia tovuti ya benki ambayo ni mwenyeji katika pwani ya magharibi. Kuna tofauti ya saa tatu kati ya maeneo hayo mawili. Ikiwa mtumiaji anafungua akaunti saa 1 asubuhi Agosti 2 EST, ni sawa na saa 10 jioni Agosti 1 PST. Kama hakuna tofauti ya muda ni kuchukuliwa, basi halisi akaunti tarehe uundaji na kumbukumbu tarehe uundaji ingekuwa tofauti. Huduma za mtandao kutumia Universal Standard Time kwa ajili ya tarehe uwakilishi. UTC tarehe na wakati muundo ni huru ya maeneo ya muda. Huduma za mtandao kutarajia Tarehe pembejeo kuwa kuwakilishwa katika muundo UTC. Ni juu ya msanidi programu kuhakikisha kwamba wote tarehe pembejeo ni kubadilishwa kwa format UTC kabla ya kufanya wito huduma ya mtandao ombi. C# hufanya operesheni hii trivial kwa sababu ya tajiri DateTime data muundo wake. DateTime leoDate = DateTime.Now.ToUniversalTime(); mteja.CreateAccount(todayDate); Operesheni kinyume inahitaji kufanyika wakati majibu ya huduma ya mtandao ni kupokea. Tarehe na wakati UTC inahitaji kubadilishwa kwa tarehe na wakati wa ndani. "Kama ""Msimu wa leo"" (DateTime) au ""Msimu wa leo"" (DateTime), tofauti ya eneo la wakati ni mfano bora wa changamoto ambazo sisi kama watengenezaji tunahitaji kuwa na ufahamu wakati wa kuendeleza programu ya wavuti au huduma za wavuti."