private EditExamCommand(ExamId examId, Capacity capacity, UtcDate registrationStartDate, UtcDate registrationEndDate) { ExamId = examId; Capacity = capacity; RegistrationStartDate = registrationStartDate; RegistrationEndDate = registrationEndDate; }
public Task BindModelAsync(ModelBindingContext bindingContext) { if (bindingContext == null) { throw new ArgumentNullException(nameof(bindingContext)); } var valueProviderResult = bindingContext.ValueProvider.GetValue(bindingContext.ModelName); if (valueProviderResult == ValueProviderResult.None) { _logger.FoundNoValueInRequest(bindingContext); // no entry _logger.DoneAttemptingToBindModel(bindingContext); return(Task.CompletedTask); } _logger.AttemptingToBindModel(bindingContext); bindingContext.ModelState.SetModelValue(bindingContext.ModelName, valueProviderResult); try { var value = valueProviderResult.FirstValue; object model = null; if (!string.IsNullOrEmpty(value)) { var dateTime = DateTime.Parse(value); model = new UtcDate(dateTime); } CheckModel(bindingContext, valueProviderResult, model); _logger.DoneAttemptingToBindModel(bindingContext); return(Task.CompletedTask); } catch (Exception exception) { var isFormatException = exception is FormatException; if (!isFormatException && exception.InnerException != null) { // TypeConverter throws System.Exception wrapping the FormatException, // so we capture the inner exception. exception = ExceptionDispatchInfo.Capture(exception.InnerException).SourceException; } bindingContext.ModelState.TryAddModelError( bindingContext.ModelName, exception, bindingContext.ModelMetadata); // Were able to find a converter for the type but conversion failed. return(Task.CompletedTask); } }
public void FromUnixTimestampAndOverloads() { var unix1 = (UtcDate - new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds.TryParseLong(); var unix2 = (LocalDate.ToUtc(LocalTimeZoneInfo) - new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds.TryParseLong(); Assert.AreEqual(UtcDate.ToString("g"), unix1.FromUnixTimestamp().ToTimezoneDate(LocalTimeZoneInfo, UtcTimeZoneInfo).ToString("g")); Assert.AreEqual(LocalDate.ToString("g"), unix2.FromUnixTimestamp().ToTimezoneDate(UtcTimeZoneInfo, LocalTimeZoneInfo).ToString("g")); }
public void ToTimezoneDateAndOverloads() { Assert.AreEqual(LocalDate.ToString("g"), UtcDate.ToTimezoneDate(LocalTimeZoneName).ToString("g")); Assert.AreEqual(LocalDate.ToString("g"), UtcDate.ToTimezoneDate(LocalTimeZoneInfo).ToString("g")); Assert.AreEqual(LocalDate.ToString("g"), UtcDate.ToTimezoneDate(UtcTimeZoneName, LocalTimeZoneName).ToString("g")); Assert.AreEqual(LocalDate.ToString("g"), UtcDate.ToTimezoneDate(UtcTimeZoneInfo, LocalTimeZoneName).ToString("g")); Assert.AreEqual(LocalDate.ToString("g"), UtcDate.ToTimezoneDate(UtcTimeZoneName, LocalTimeZoneInfo).ToString("g")); Assert.AreEqual(LocalDate.ToString("g"), UtcDate.ToTimezoneDate(UtcTimeZoneInfo, LocalTimeZoneInfo).ToString("g")); }
private CreateExamCommand(SubjectId subjectId, LocationId locationId, UtcDateTime examDateTime, Capacity capacity, UtcDate registrationStartDate, UtcDate registrationEndDate) { SubjectId = subjectId; LocationId = locationId; ExamDateTime = examDateTime; Capacity = capacity; RegistrationStartDate = registrationStartDate; RegistrationEndDate = registrationEndDate; }
public Result <Exam> ChangeRegistrationDates(UtcDate registrationStartDate, UtcDate registrationEndDate) { if (registrationStartDate.Value >= registrationEndDate.Value) { return(Result.Fail <Exam>(ExamErrors.RegistrationStartDate.HasToBeSetBeforeRegistrationEndDate.Build())); } return(ChangeRegistrationStartDate(registrationStartDate) .OnSuccess(() => ChangeRegistrationEndDate(registrationEndDate))); }
public async Task ShouldNotCreateExamWithRegistrationEndDateAfterExamDate() { var examDateTime = UtcDateTime.Create(new DateTime(2020, 03, 10, 12, 00, 00, DateTimeKind.Utc)).Value; var registrationStartDate = UtcDate.Create(new DateTime(2020, 02, 08, 00, 00, 00, DateTimeKind.Utc)).Value; var registrationEndDate = UtcDate.Create(new DateTime(2020, 03, 12, 00, 00, 00, DateTimeKind.Utc)).Value; var examResult = await Exam.CreateAsync(_subjectId, _locationId, examDateTime, _capacity, registrationStartDate, registrationEndDate, _systemTimeProvider.Object, _examRepository.Object); examResult.IsSuccess.Should().BeFalse(); }
private Exam(SubjectId subjectId, LocationId locationId, UtcDateTime examDateTime, Capacity capacity, UtcDate registrationStartDate, UtcDate registrationEndDate, ISystemTimeProvider systemTimeProvider) : this(systemTimeProvider) { LocationId = locationId; Capacity = capacity; Booked = Booked.Zero; SubjectId = subjectId; RegistrationStartDate = registrationStartDate; RegistrationEndDate = registrationEndDate; ExamDateTime = examDateTime; Status = ExamStatus.Planned; }
public static Result <EditExamCommand> Create(long examId, EditExamRequest request, IExamExistenceValidator examExistenceValidator) { var id = ExamId.Create(examId, examExistenceValidator); var capacity = Capacity.Create(request.Capacity) .BindErrorsTo(nameof(request.Capacity)); var registrationStartDate = UtcDate.Create(request.RegistrationStartDate) .BindErrorsTo(nameof(request.RegistrationStartDate)); var registrationEndDate = UtcDate.Create(request.RegistrationEndDate) .BindErrorsTo(nameof(request.RegistrationEndDate)); return(Result.Combine(id, capacity, registrationStartDate, registrationEndDate) .OnSuccess(() => new EditExamCommand(id.Value, capacity.Value, registrationStartDate.Value, registrationEndDate.Value))); }
public void ToUnixTimestampAndOverloads() { var unix1 = (UtcDate - new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds.TryParseLong(); var unix2 = (LocalDate.ToUtc(LocalTimeZoneInfo) - new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds.TryParseLong(); Assert.AreEqual(unix1, UtcDate.ToUnixTimestamp()); Assert.AreEqual(unix1, UtcDate.ToUnixTimestamp(UtcTimeZoneInfo)); Assert.AreEqual(unix1, UtcDate.ToUnixTimestamp(UtcTimeZoneName)); Assert.AreEqual(unix2, LocalDate.ToUnixTimestamp()); Assert.AreEqual(unix2, LocalDate.ToUnixTimestamp(UtcTimeZoneInfo)); Assert.AreEqual(unix2, LocalDate.ToUnixTimestamp(UtcTimeZoneName)); }
public static Task <Result <Exam> > CreateAsync(SubjectId subjectId, LocationId locationId, UtcDateTime examDateTime, Capacity capacity, UtcDate registrationStartDate, UtcDate registrationEndDate, ISystemTimeProvider systemTimeProvider, IExamRepository examRepository) { return(Result.Create(() => systemTimeProvider.UtcNow < registrationStartDate.Value, ExamCreationErrors.RegistrationStartDateHasToBeInTheFuture.Build()) .AndEnsure(() => registrationStartDate.Value < registrationEndDate.Value, ExamCreationErrors.RegistrationEndDateHasToBeAfterRegistrationStartDate.Build()) .AndEnsure(() => registrationEndDate.Value < examDateTime.Value.Date, ExamCreationErrors.RegistrationEndDateHasToBeBeforeExamDate.Build()) .OnSuccess(() => new Exam(subjectId, locationId, examDateTime, capacity, registrationStartDate, registrationEndDate, systemTimeProvider)) .OnSuccess(examRepository.SaveAsync) .OnSuccess(exam => exam.RaiseEvent(new ExamPlanned(exam.Id, systemTimeProvider.UtcNow)))); }
public Dictionary <string, string> GenerateProperties() { var answer = new Dictionary <string, string>() { { "Date", UtcDate.ToString("yyyy-MM-dd") }, // ISO8601 format { "AccountId", UserId } // We have to add AccountId, since if it changed, the AccountId automatically logged would be different }; // Entries0 - Entries17 for (int i = 0; i < _pageProperties.Count; i++) { answer.Add($"Entries{i}", _pageProperties[i]); } return(answer); }
private Result <Exam> ChangeRegistrationStartDate(UtcDate registrationStartDate) { if (RegistrationStartDate == registrationStartDate) { return(Result.Ok(this)); } return(CheckIfPossible(ExamActions.ChangeRegistrationStartDate, ExamErrors.RegistrationStartDate.UnableToChange.Build()) .AndEnsure(() => SystemTimeProvider.UtcNow.Date < registrationStartDate.Value, ExamErrors.RegistrationStartDate.HasToBeSetInTheFuture.Build()) .OnSuccess(() => { RegistrationStartDate = registrationStartDate; RaiseEvent(new ExamRegistrationStartDateChanged(Id, RegistrationStartDate.Value, SystemTimeProvider.UtcNow)); return this; })); }
public static Result <CreateExamCommand> Create(CreateExamRequest request, ISubjectExistenceValidator subjectExistenceValidator, ILocationExistenceValidator locationExistenceValidator) { var subjectId = SubjectId.Create(request.SubjectId, subjectExistenceValidator) .BindErrorsTo(nameof(request.SubjectId)); var locationId = LocationId.Create(request.LocationId, locationExistenceValidator) .BindErrorsTo(nameof(request.LocationId)); var examDateTime = UtcDateTime.Create(request.ExamDateTime) .BindErrorsTo(nameof(request.ExamDateTime)); var capacity = Capacity.Create(request.Capacity) .BindErrorsTo(nameof(request.Capacity)); var registrationStartDate = UtcDate.Create(request.RegistrationStartDate) .BindErrorsTo(nameof(request.RegistrationStartDate)); var registrationEndDate = UtcDate.Create(request.RegistrationEndDate) .BindErrorsTo(nameof(request.RegistrationEndDate)); return(Result.Combine(subjectId, locationId, examDateTime, capacity, registrationStartDate, registrationEndDate) .OnSuccess(() => new CreateExamCommand(subjectId.Value, locationId.Value, examDateTime.Value, capacity.Value, registrationStartDate.Value, registrationEndDate.Value))); }
public void TryParseDate_nullableDate() { var date1 = UtcDate; var date2 = UtcDate.AddDays(DateInterval); var date3 = UtcDate.AddMonths(DateInterval); DateTime?date1Nullable = UtcDate; DateTime?date2Nullable = UtcDate.AddDays(DateInterval); DateTime?date3Nullable = UtcDate.AddMonths(DateInterval); Assert.AreEqual(date1.ToString("g"), date1Nullable.TryParseDate().ToUtc().ToString("g")); Assert.AreEqual(date2.ToString("g"), date2Nullable.TryParseDate().ToUtc().ToString("g")); Assert.AreEqual(date3.ToString("g"), date3Nullable.TryParseDate().ToUtc().ToString("g")); Assert.AreEqual(date1.ToString("g"), ((DateTime?)null).TryParseDate().ToUtc().ToString("g")); Assert.AreEqual(date1.ToString("g"), date1Nullable.TryParseDate(date1).ToUtc().ToString("g")); Assert.AreEqual(date2.ToString("g"), date2Nullable.TryParseDate(date2).ToUtc().ToString("g")); Assert.AreEqual(date3.ToString("g"), date3Nullable.TryParseDate(date3).ToUtc().ToString("g")); Assert.AreEqual(date1.ToString("g"), ((DateTime?)null).TryParseDate(date1).ToUtc().ToString("g")); Assert.AreEqual(date2.ToString("g"), ((DateTime?)null).TryParseDate(date2).ToUtc().ToString("g")); Assert.AreEqual(date3.ToString("g"), ((DateTime?)null).TryParseDate(date3).ToUtc().ToString("g")); }
public MySqlFunctionManager(bool allowFuncDefChange) { this.allowFuncDefChange = allowFuncDefChange; parsingStrateg["CAST"] = FunctionParsingStrategy.Cast; parsingStrateg["POSITION"] = FunctionParsingStrategy.Position; parsingStrateg["SUBSTR"] = FunctionParsingStrategy.Substring; parsingStrateg["SUBSTRING"] = FunctionParsingStrategy.Substring; parsingStrateg["TRIM"] = FunctionParsingStrategy.Trim; parsingStrateg["AVG"] = FunctionParsingStrategy.Avg; parsingStrateg["COUNT"] = FunctionParsingStrategy.Count; parsingStrateg["GROUP_CONCAT"] = FunctionParsingStrategy.GroupConcat; parsingStrateg["MAX"] = FunctionParsingStrategy.Max; parsingStrateg["MIN"] = FunctionParsingStrategy.Min; parsingStrateg["SUM"] = FunctionParsingStrategy.Sum; parsingStrateg["ROW"] = FunctionParsingStrategy.Row; parsingStrateg["CHAR"] = FunctionParsingStrategy.Char; parsingStrateg["CONVERT"] = FunctionParsingStrategy.Convert; parsingStrateg["EXTRACT"] = FunctionParsingStrategy.Extract; parsingStrateg["TIMESTAMPADD"] = FunctionParsingStrategy.Timestampadd; parsingStrateg["TIMESTAMPDIFF"] = FunctionParsingStrategy.Timestampdiff; parsingStrateg["GET_FORMAT"] = FunctionParsingStrategy.GetFormat; functionPrototype["ABS"] = new Abs(null); functionPrototype["ACOS"] = new Acos(null); functionPrototype["ADDDATE"] = new Adddate(null); functionPrototype["ADDTIME"] = new Addtime(null); functionPrototype["AES_DECRYPT"] = new AesDecrypt(null); functionPrototype["AES_ENCRYPT"] = new AesEncrypt(null); functionPrototype["ANALYSE"] = new Analyse(null); functionPrototype["ASCII"] = new Ascii(null); functionPrototype["ASIN"] = new Asin(null); functionPrototype["ATAN2"] = new Atan2(null); functionPrototype["ATAN"] = new Atan(null); functionPrototype["BENCHMARK"] = new Benchmark(null); functionPrototype["BIN"] = new Bin(null); functionPrototype["BIT_AND"] = new BitAnd(null); functionPrototype["BIT_COUNT"] = new BitCount(null); functionPrototype["BIT_LENGTH"] = new BitLength(null); functionPrototype["BIT_OR"] = new BitOR(null); functionPrototype["BIT_XOR"] = new BitXor(null); functionPrototype["CEIL"] = new Ceiling(null); functionPrototype["CEILING"] = new Ceiling(null); functionPrototype["CHAR_LENGTH"] = new CharLength(null); functionPrototype["CHARACTER_LENGTH"] = new CharLength(null); functionPrototype["CHARSET"] = new Charset(null); functionPrototype["COALESCE"] = new Coalesce(null); functionPrototype["COERCIBILITY"] = new Coercibility(null); functionPrototype["COLLATION"] = new Collation(null); functionPrototype["COMPRESS"] = new Compress(null); functionPrototype["CONCAT_WS"] = new ConcatWs(null); functionPrototype["CONCAT"] = new Concat(null); functionPrototype["CONNECTION_ID"] = new ConnectionId(null); functionPrototype["CONV"] = new Conv(null); functionPrototype["CONVERT_TZ"] = new ConvertTz(null); functionPrototype["COS"] = new Cos(null); functionPrototype["COT"] = new Cot(null); functionPrototype["CRC32"] = new Crc32(null); functionPrototype["CURDATE"] = new Curdate(); functionPrototype["CURRENT_DATE"] = new Curdate(); functionPrototype["CURRENT_TIME"] = new Curtime(); functionPrototype["CURTIME"] = new Curtime(); functionPrototype["CURRENT_TIMESTAMP"] = new Now(); functionPrototype["CURRENT_USER"] = new CurrentUser(); functionPrototype["CURTIME"] = new Curtime(); functionPrototype["DATABASE"] = new Database(null); functionPrototype["DATE_ADD"] = new DateAdd(null); functionPrototype["DATE_FORMAT"] = new DateFormat(null); functionPrototype["DATE_SUB"] = new DateSub(null); functionPrototype["DATE"] = new Date(null); functionPrototype["DATEDIFF"] = new Datediff(null); functionPrototype["DAY"] = new Dayofmonth(null); functionPrototype["DAYOFMONTH"] = new Dayofmonth(null); functionPrototype["DAYNAME"] = new Dayname(null); functionPrototype["DAYOFWEEK"] = new Dayofweek(null); functionPrototype["DAYOFYEAR"] = new Dayofyear(null); functionPrototype["DECODE"] = new Decode(null); functionPrototype["DEFAULT"] = new Default(null); functionPrototype["DEGREES"] = new Degrees(null); functionPrototype["DES_DECRYPT"] = new DesDecrypt(null); functionPrototype["DES_ENCRYPT"] = new DesEncrypt(null); functionPrototype["ELT"] = new Elt(null); functionPrototype["ENCODE"] = new Encode(null); functionPrototype["ENCRYPT"] = new Encrypt(null); functionPrototype["EXP"] = new Exp(null); functionPrototype["EXPORT_SET"] = new ExportSet(null); // functionPrototype.put("EXTRACT", new Extract(null)); functionPrototype["EXTRACTVALUE"] = new ExtractValue(null); functionPrototype["FIELD"] = new Field(null); functionPrototype["FIND_IN_SET"] = new FindInSet(null); functionPrototype["FLOOR"] = new Floor(null); functionPrototype["FORMAT"] = new Format(null); functionPrototype["FOUND_ROWS"] = new FoundRows(null); functionPrototype["FROM_DAYS"] = new FromDays(null); functionPrototype["FROM_UNIXTIME"] = new FromUnixtime(null); // functionPrototype.put("GET_FORMAT", new GetFormat(null)); functionPrototype["GET_LOCK"] = new GetLock(null); functionPrototype["GREATEST"] = new Greatest(null); functionPrototype["HEX"] = new Hex(null); functionPrototype["HOUR"] = new Hour(null); functionPrototype["IF"] = new IF(null); functionPrototype["IFNULL"] = new IFNull(null); functionPrototype["INET_ATON"] = new InetAton(null); functionPrototype["INET_NTOA"] = new InetNtoa(null); functionPrototype["INSERT"] = new Insert(null); functionPrototype["INSTR"] = new Instr(null); functionPrototype["INTERVAL"] = new Interval(null); functionPrototype["IS_FREE_LOCK"] = new IsFreeLock(null); functionPrototype["IS_USED_LOCK"] = new IsUsedLock(null); functionPrototype["ISNULL"] = new IsNull(null); functionPrototype["LAST_DAY"] = new LastDay(null); functionPrototype["LAST_INSERT_ID"] = new LastInsertId(null); functionPrototype["LCASE"] = new Lower(null); functionPrototype["LEAST"] = new Least(null); functionPrototype["LEFT"] = new Left(null); functionPrototype["LENGTH"] = new Length(null); functionPrototype["LN"] = new Log(null); // Ln(X) equals Log(X) functionPrototype["LOAD_FILE"] = new LoadFile(null); functionPrototype["LOCALTIME"] = new Now(); functionPrototype["LOCALTIMESTAMP"] = new Now(); functionPrototype["LOCATE"] = new Locate(null); functionPrototype["LOG10"] = new Log10(null); functionPrototype["LOG2"] = new Log2(null); functionPrototype["LOG"] = new Log(null); functionPrototype["LOWER"] = new Lower(null); functionPrototype["LPAD"] = new Lpad(null); functionPrototype["LTRIM"] = new Ltrim(null); functionPrototype["MAKE_SET"] = new MakeSet(null); functionPrototype["MAKEDATE"] = new Makedate(null); functionPrototype["MAKETIME"] = new Maketime(null); functionPrototype["MASTER_POS_WAIT"] = new MasterPosWait(null); functionPrototype["MD5"] = new Md5(null); functionPrototype["MICROSECOND"] = new Microsecond(null); functionPrototype["MID"] = new Substring(null); functionPrototype["MINUTE"] = new Minute(null); functionPrototype["MONTH"] = new Month(null); functionPrototype["MONTHNAME"] = new Monthname(null); functionPrototype["NAME_CONST"] = new NameConst(null); functionPrototype["NOW"] = new Now(); functionPrototype["NULLIF"] = new NullIF(null); functionPrototype["OCT"] = new Oct(null); functionPrototype["OCTET_LENGTH"] = new Length(null); functionPrototype["OLD_PASSWORD"] = new OldPassword(null); functionPrototype["ORD"] = new Ord(null); functionPrototype["PASSWORD"] = new Password(null); functionPrototype["PERIOD_ADD"] = new PeriodAdd(null); functionPrototype["PERIOD_DIFF"] = new PeriodDiff(null); functionPrototype["PI"] = new PI(null); functionPrototype["POW"] = new Pow(null); functionPrototype["POWER"] = new Pow(null); functionPrototype["QUARTER"] = new Quarter(null); functionPrototype["QUOTE"] = new Quote(null); functionPrototype["RADIANS"] = new Radians(null); functionPrototype["RAND"] = new Rand(null); functionPrototype["RELEASE_LOCK"] = new ReleaseLock(null); functionPrototype["REPEAT"] = new Repeat(null); functionPrototype["REPLACE"] = new Replace(null); functionPrototype["REVERSE"] = new Reverse(null); functionPrototype["RIGHT"] = new Right(null); functionPrototype["ROUND"] = new Round(null); functionPrototype["ROW_COUNT"] = new RowCount(null); functionPrototype["RPAD"] = new Rpad(null); functionPrototype["RTRIM"] = new Rtrim(null); functionPrototype["SCHEMA"] = new Database(null); functionPrototype["SEC_TO_TIME"] = new SecToTime(null); functionPrototype["SECOND"] = new Second(null); functionPrototype["SESSION_USER"] = new User(null); functionPrototype["SHA1"] = new Sha1(null); functionPrototype["SHA"] = new Sha1(null); functionPrototype["SHA2"] = new Sha2(null); functionPrototype["SIGN"] = new Sign(null); functionPrototype["SIN"] = new Sin(null); functionPrototype["SLEEP"] = new Sleep(null); functionPrototype["SOUNDEX"] = new Soundex(null); functionPrototype["SPACE"] = new Space(null); functionPrototype["SQRT"] = new Sqrt(null); functionPrototype["STD"] = new Std(null); functionPrototype["STDDEV_POP"] = new StdDevPop(null); functionPrototype["STDDEV_SAMP"] = new StdDevSamp(null); functionPrototype["STDDEV"] = new StdDev(null); functionPrototype["STR_TO_DATE"] = new StrToDate(null); functionPrototype["STRCMP"] = new Strcmp(null); functionPrototype["SUBDATE"] = new Subdate(null); functionPrototype["SUBSTRING_INDEX"] = new SubstringIndex(null); functionPrototype["SUBTIME"] = new Subtime(null); functionPrototype["SYSDATE"] = new Sysdate(null); functionPrototype["SYSTEM_USER"] = new User(null); functionPrototype["TAN"] = new Tan(null); functionPrototype["TIME_FORMAT"] = new TimeFormat(null); functionPrototype["TIME_TO_SEC"] = new TimeToSec(null); functionPrototype["TIME"] = new Time(null); functionPrototype["TIMEDIFF"] = new Timediff(null); functionPrototype["TIMESTAMP"] = new Timestamp(null); // functionPrototype.put("TIMESTAMPADD", new Timestampadd(null)); // functionPrototype.put("TIMESTAMPDIFF", new Timestampdiff(null)); functionPrototype["TO_DAYS"] = new ToDays(null); functionPrototype["TO_SECONDS"] = new ToSeconds(null); functionPrototype["TRUNCATE"] = new Truncate(null); functionPrototype["UCASE"] = new Upper(null); functionPrototype["UNCOMPRESS"] = new Uncompress(null); functionPrototype["UNCOMPRESSED_LENGTH"] = new UncompressedLength(null); functionPrototype["UNHEX"] = new Unhex(null); functionPrototype["UNIX_TIMESTAMP"] = new UnixTimestamp(null); functionPrototype["UPDATEXML"] = new UpdateXml(null); functionPrototype["UPPER"] = new Upper(null); functionPrototype["USER"] = new User(null); functionPrototype["UTC_DATE"] = new UtcDate(null); functionPrototype["UTC_TIME"] = new UtcTime(null); functionPrototype["UTC_TIMESTAMP"] = new UtcTimestamp(null); functionPrototype["UUID_SHORT"] = new UuidShort(null); functionPrototype["UUID"] = new Uuid(null); functionPrototype["VALUES"] = new Values(null); functionPrototype["VAR_POP"] = new VarPop(null); functionPrototype["VAR_SAMP"] = new VarSamp(null); functionPrototype["VARIANCE"] = new Variance(null); functionPrototype["VERSION"] = new Version(null); functionPrototype["WEEK"] = new Week(null); functionPrototype["WEEKDAY"] = new Weekday(null); functionPrototype["WEEKOFYEAR"] = new Weekofyear(null); functionPrototype["YEAR"] = new Year(null); functionPrototype["YEARWEEK"] = new Yearweek(null); }
public void TryParseDate_string() { var date1 = UtcDate; var date2 = UtcDate.AddDays(DateInterval); var date3 = UtcDate.AddMonths(DateInterval); var date4 = LocalDate; var date1Str = date1.ToString("g"); var date2Str = date2.ToString("g"); var date3Str = date3.ToString("g"); var date4Str = date4.ToString("O"); #region string date Assert.AreEqual(date1.ToString("g"), date1Str.TryParseDate().ToUtc().ToString("g")); Assert.AreEqual(date2.ToString("g"), date2Str.TryParseDate().ToUtc().ToString("g")); Assert.AreEqual(date3.ToString("g"), date3Str.TryParseDate().ToUtc().ToString("g")); Assert.AreEqual(date4.ToString("g"), date4Str.TryParseDate().ToString("g")); Assert.AreEqual(date4.ToUtc().ToString("g"), date4Str.TryParseDate().ToUtc().ToString("g")); Assert.AreEqual(date4.ToString("g"), date4Str.TryParseDate().ToTimezoneDate(LocalTimeZoneName).ToString("g")); Assert.AreEqual(date1.ToString("g"), "".TryParseDate().ToUtc().ToString("g")); Assert.AreEqual(date1.ToString("g"), date1Str.TryParseDate(date1).ToUtc().ToString("g")); Assert.AreEqual(date2.ToString("g"), date2Str.TryParseDate(date2).ToUtc().ToString("g")); Assert.AreEqual(date3.ToString("g"), date3Str.TryParseDate(date3).ToUtc().ToString("g")); Assert.AreEqual(date4.ToUtc().ToString("g"), date4Str.TryParseDate(date4).ToUtc().ToString("g")); Assert.AreEqual(date1.ToString("g"), "".TryParseDate(date1).ToUtc().ToString("g")); Assert.AreEqual(date2.ToString("g"), "".TryParseDate(date2).ToUtc().ToString("g")); Assert.AreEqual(date3.ToString("g"), "".TryParseDate(date3).ToUtc().ToString("g")); Assert.AreEqual(date1.ToString("g"), date1Str.TryParseDate(Culture, DateTimeStyles).ToUtc().ToString("g")); Assert.AreEqual(date2.ToString("g"), date2Str.TryParseDate(Culture, DateTimeStyles).ToUtc().ToString("g")); Assert.AreEqual(date3.ToString("g"), date3Str.TryParseDate(Culture, DateTimeStyles).ToUtc().ToString("g")); Assert.AreEqual(date4.ToUtc().ToString("g"), date4Str.TryParseDate(Culture, DateTimeStyles).ToUtc().ToString("g")); Assert.AreEqual(date1.ToString("g"), "".TryParseDate(Culture, DateTimeStyles).ToUtc().ToString("g")); Assert.AreEqual(date1.ToString("g"), date1Str.TryParseDate(date1, Culture, DateTimeStyles).ToUtc().ToString("g")); Assert.AreEqual(date2.ToString("g"), date2Str.TryParseDate(date2, Culture, DateTimeStyles).ToUtc().ToString("g")); Assert.AreEqual(date3.ToString("g"), date3Str.TryParseDate(date3, Culture, DateTimeStyles).ToUtc().ToString("g")); Assert.AreEqual(date4.ToUtc().ToString("g"), date4Str.TryParseDate(date4, Culture, DateTimeStyles).ToUtc().ToString("g")); Assert.AreEqual(date1.ToString("g"), "".TryParseDate(date1, Culture, DateTimeStyles).ToUtc().ToString("g")); Assert.AreEqual(date2.ToString("g"), "".TryParseDate(date2, Culture, DateTimeStyles).ToUtc().ToString("g")); Assert.AreEqual(date3.ToString("g"), "".TryParseDate(date3, Culture, DateTimeStyles).ToUtc().ToString("g")); Assert.AreEqual(date4.ToUtc().ToString("g"), "".TryParseDate(date4, Culture, DateTimeStyles).ToUtc().ToString("g")); #endregion #region OADate Assert.AreEqual(date1.ToString("g"), date1.ToOADate().ToString(Culture).TryParseDate().ToString("g")); Assert.AreEqual(date2.ToString("g"), date2.ToOADate().ToString(Culture).TryParseDate().ToString("g")); Assert.AreEqual(date3.ToString("g"), date3.ToOADate().ToString(Culture).TryParseDate().ToString("g")); Assert.AreEqual(date1.ToString("g"), date1.ToOADate().ToString(Culture).TryParseDate(date1).ToString("g")); Assert.AreEqual(date2.ToString("g"), date2.ToOADate().ToString(Culture).TryParseDate(date2).ToString("g")); Assert.AreEqual(date3.ToString("g"), date3.ToOADate().ToString(Culture).TryParseDate(date3).ToString("g")); Assert.AreEqual(date1.ToString("g"), date1.ToOADate().ToString(Culture).TryParseDate(Culture, DateTimeStyles).ToString("g")); Assert.AreEqual(date2.ToString("g"), date2.ToOADate().ToString(Culture).TryParseDate(Culture, DateTimeStyles).ToString("g")); Assert.AreEqual(date3.ToString("g"), date3.ToOADate().ToString(Culture).TryParseDate(Culture, DateTimeStyles).ToString("g")); Assert.AreEqual(date1.ToString("g"), date1.ToOADate().ToString(Culture).TryParseDate(date1, Culture, DateTimeStyles).ToString("g")); Assert.AreEqual(date2.ToString("g"), date2.ToOADate().ToString(Culture).TryParseDate(date2, Culture, DateTimeStyles).ToString("g")); Assert.AreEqual(date3.ToString("g"), date3.ToOADate().ToString(Culture).TryParseDate(date3, Culture, DateTimeStyles).ToString("g")); #endregion }
public void ToUtcAndOverloads() { Assert.AreEqual(UtcDate.ToString("g"), LocalDate.ToUtc().ToString("g")); Assert.AreEqual(UtcDate.ToString("g"), LocalDate.ToUtc(UtcTimeZoneInfo).ToString("g")); Assert.AreEqual(UtcDate.ToString("g"), LocalDate.ToUtc(UtcTimeZoneName).ToString("g")); }
public void ShouldReturnExpectedResult(DateTime dateTime, bool isSuccess) { var utcDateResult = UtcDate.Create(dateTime); utcDateResult.IsSuccess.Should().Be(isSuccess); }