public void YMDConstructorWorks() { var dt = new DateTime(2011, 7, 12); Assert.AreEqual(dt.GetFullYear(), 2011); Assert.AreEqual(dt.GetMonth(), 7); Assert.AreEqual(dt.GetDate(), 12); }
public void StringConstructorWorks() { var dt = new DateTime("Aug 12, 2012"); Assert.AreEqual(dt.GetFullYear(), 2012); Assert.AreEqual(dt.GetMonth(), 8); Assert.AreEqual(dt.GetDate(), 12); }
public void YMDHNConstructorWorks() { var dt = new DateTime(2011, 7, 12, 13, 42); Assert.AreEqual(dt.GetFullYear(), 2011); Assert.AreEqual(dt.GetMonth(), 7); Assert.AreEqual(dt.GetDate(), 12); Assert.AreEqual(dt.GetHours(), 13); Assert.AreEqual(dt.GetMinutes(), 42); }
private int DayOfYear(DateTime arg) { int result; switch (arg.Month) { case 0: result = 0; break; case 1: result = 31; break; case 2: result = 59; break; case 3: result = 90; break; case 4: result = 120; break; case 5: result = 151; break; case 6: result = 181; break; case 7: result = 212; break; case 8: result = 243; break; case 9: result = 273; break; case 10: result = 304; break; case 11: result = 334; break; default: throw new ArgumentException(); } result += arg.GetDate(); //check leap year if ((arg.Year%4 == 0) && ((arg.Year%100 != 0) || ((arg.Year + 1900)%400 == 0))) { result++; } return result; }
public void GetDateWorks() { var dt = new DateTime(2011, 7, 12, 13, 42, 56, 345); Assert.AreEqual(dt.GetDate(), 12); }
public void ToLocalWorks() { var UTC = new DateTime(2011, 7, 12, 13, 42, 56, 345); var dt = UTC.ToLocalTime(); Assert.AreEqual(dt.GetUtcFullYear(), UTC.GetFullYear()); Assert.AreEqual(dt.GetUtcMonth(), UTC.GetMonth()); Assert.AreEqual(dt.GetUtcDate(), UTC.GetDate()); Assert.AreEqual(dt.GetUtcHours(), UTC.GetHours()); Assert.AreEqual(dt.GetUtcMinutes(), UTC.GetMinutes()); Assert.AreEqual(dt.GetUtcSeconds(), UTC.GetSeconds()); Assert.AreEqual(dt.GetUtcMilliseconds(), UTC.GetMilliseconds()); }
void noFacebookSignup2SaveClick(DomEvent e) { e.PreventDefault(); if (AsyncInProgress) return; View.Connect_LoggedOut_NoFacebook_SignUp2_ErrorLabel.InnerHTML = ""; #region Check name if (View.Connect_LoggedOut_NoFacebook_SignUp2_FirstNameTextbox.Value.Length == 0) { View.Connect_LoggedOut_NoFacebook_SignUp2_ErrorLabel.InnerHTML = "Enter your first name"; return; } if (View.Connect_LoggedOut_NoFacebook_SignUp2_LastNameTextbox.Value.Length == 0) { View.Connect_LoggedOut_NoFacebook_SignUp2_ErrorLabel.InnerHTML = "Enter your last name"; return; } if (View.Connect_LoggedOut_NoFacebook_SignUp2_FirstNameTextbox.Value.Length > 20) { View.Connect_LoggedOut_NoFacebook_SignUp2_ErrorLabel.InnerHTML = "First name is too long"; return; } if (View.Connect_LoggedOut_NoFacebook_SignUp2_LastNameTextbox.Value.Length > 20) { View.Connect_LoggedOut_NoFacebook_SignUp2_ErrorLabel.InnerHTML = "Last name is too long"; return; } #endregion #region Check nickname if (View.Connect_LoggedOut_NoFacebook_SignUp2_NicknameTextbox.Value.Length == 0) { View.Connect_LoggedOut_NoFacebook_SignUp2_ErrorLabel.InnerHTML = "Enter a nickname"; return; } if (View.Connect_LoggedOut_NoFacebook_SignUp2_NicknameTextbox.Value.Length < 2) { View.Connect_LoggedOut_NoFacebook_SignUp2_ErrorLabel.InnerHTML = "Nickname must be longer"; return; } if (View.Connect_LoggedOut_NoFacebook_SignUp2_NicknameTextbox.Value.Length > 20) { View.Connect_LoggedOut_NoFacebook_SignUp2_ErrorLabel.InnerHTML = "Nickname is too long"; return; } #endregion #region Check date of birth if (int.ParseInvariant(View.Connect_LoggedOut_NoFacebook_SignUp2_DateOfBirthYearDropDown.Value) < 0 || int.ParseInvariant(View.Connect_LoggedOut_NoFacebook_SignUp2_DateOfBirthMonthDropDown.Value) < 0 || int.ParseInvariant(View.Connect_LoggedOut_NoFacebook_SignUp2_DateOfBirthDayDropDown.Value) < 0) { View.Connect_LoggedOut_NoFacebook_SignUp2_ErrorLabel.InnerHTML = "Enter your date of birth"; return; } DateTime d = new DateTime(); d.SetFullYear(int.ParseInvariant(View.Connect_LoggedOut_NoFacebook_SignUp2_DateOfBirthYearDropDown.Value)); d.SetMonth(int.ParseInvariant(View.Connect_LoggedOut_NoFacebook_SignUp2_DateOfBirthMonthDropDown.Value)); d.SetDate(int.ParseInvariant(View.Connect_LoggedOut_NoFacebook_SignUp2_DateOfBirthDayDropDown.Value)); if (d.GetFullYear() != int.ParseInvariant(View.Connect_LoggedOut_NoFacebook_SignUp2_DateOfBirthYearDropDown.Value) || d.GetMonth() != int.ParseInvariant(View.Connect_LoggedOut_NoFacebook_SignUp2_DateOfBirthMonthDropDown.Value) || d.GetDate() != int.ParseInvariant(View.Connect_LoggedOut_NoFacebook_SignUp2_DateOfBirthDayDropDown.Value)) { View.Connect_LoggedOut_NoFacebook_SignUp2_ErrorLabel.InnerHTML = "Check your date of birth"; return; } #endregion #region Check sex if (!View.Connect_LoggedOut_NoFacebook_SignUp2_SexMaleRadio.Checked && !View.Connect_LoggedOut_NoFacebook_SignUp2_SexFemaleRadio.Checked) { View.Connect_LoggedOut_NoFacebook_SignUp2_ErrorLabel.InnerHTML = "Enter your sex"; return; } #endregion #region Check nickname int thisAsyncOperation = RegisterStartAsync("Checking nickname..."); Server.GetUniqueNickName( View.Connect_LoggedOut_NoFacebook_SignUp2_NicknameTextbox.Value, NoFacebookSignUp2PanelLoginUsrK, new Response( delegate(Dictionary response) { if (RegisterEndAsync(thisAsyncOperation)) return; if (U.isTrue(response, "Exception")) { showError(7, "Internal server error"); } else { string newNickname = U.get(response, "Nickname").ToString(); if (View.Connect_LoggedOut_NoFacebook_SignUp2_NicknameTextbox.Value != newNickname) { View.Connect_LoggedOut_NoFacebook_SignUp2_NicknameTextbox.Value = newNickname; View.Connect_LoggedOut_NoFacebook_SignUp2_ErrorLabel.InnerHTML = "We changed your nickname. Is this OK?"; return; } else { noFacebookSignup2SaveDone(); } } } ) ); #endregion }