/// <summary> /// 得到日期 /// </summary> /// <param name="date"></param> /// <param name="dateTimeType"></param> /// <returns></returns> public static DateTime GetDateTime(string date, DateTimeType dateTimeType) { if (dateTimeType == DateTimeType.Start) return GetDateTimeByStrDateTime(date, "00:00:00"); else return GetDateTimeByStrDateTime(date, "23:59:59"); }
/// <summary> /// 得到日期 /// </summary> /// <param name="date"></param> /// <param name="dateTimeType"></param> /// <returns></returns> public static DateTime GetDateTime(DateTime datetime, DateTimeType dateTimeType) { if (dateTimeType == DateTimeType.Start) return GetDateTimeByStrDateTime(GetDateStr(datetime), "00:00:00"); else return GetDateTimeByStrDateTime(GetDateStr(datetime), "23:59:59"); }
public void WriteDateTime_WritesDatetimeInRFC339Spec() { // Arrange var o = new DateTimeType(); // Act var written = Toml.WriteString(o); // Assert written.Should().Be($"DT = {DateTimeType.Default}\r\n"); }
public byte[] GetDateTimeConfig(DateTimeType type, byte schedId) { if (type == DateTimeType.FromDate) { return(_dtFromPickerPanelList[schedId].GetDateBinary()); } else if (type == DateTimeType.ToDate) { return(_dtToPickerPanelList[schedId].GetDateBinary()); } else { return(new byte[0]); } }
public static ItemsBase[] BuildList(UInt16Swap swap, DateTimeType type, string[] strName) { if (strName == null || strName.Length <= 0) { return(null); } var lst = new List <ItemsBase>(strName.Length); for (int i = 0; i < strName.Length; i++) { lst.Add(new DateTimeItem(strName[i], type, swap)); } return(lst.ToArray()); }
public void ReferenceAndValueTest2() { //Arrange - adaugam toate resursele de care avem nevoie DateTimeType object1 = new DateTimeType(); // 1:pointer catre obiect 2: obiectul cu proprietatile DateTimeType object2 = new DateTimeType(); // 3:pointer catre obiect 4: obiectul cu proprietatile //Act - apelam metoda pe care vrem sa o testam //object2 = object1; //val 1 va merge in val de la 3 =>2 1=>2 object2 = object1.Clone(); // 3:pointer catre obiect 5 object2.datetime2 = DateTime.Today; //modificam obiectul din spatiul de memorie 2 3=>2 //Assert - verificam daca rezultatul este cel asteptat //Assert.IsTrue(result == DateTime.Now); //Assert.AreEqual(DateTime.Now, result); Assert.That(object2.datetime2, Is.EqualTo(DateTime.Today)); Assert.That(object1.datetime2, Is.EqualTo(DateTime.MinValue)); }
public void DateTimeToday() { //Arrange - adaugam toate resursele de care avem nevoie //var car = new Car(); var today = new DateTimeType(); //Act - apelam metoda pe care vrem sa o testam //car.AddService(); var result = today.GetToday(); //Assert - verificam daca rezultatul este cel asteptat //Assert.IsTrue(result == DateTime.Now); Assert.AreEqual(DateTime.Now, result); //Assert.That(result, Is.EqualTo(DateTime.Now)); }
public ExpressionOp(Expression e) : base(e.DataType.IsDateTimeTypeWithZone() ? 0x5b : 0x5c) { switch (e.DataType.TypeCode) { case 0x5c: base.nodes = new Expression[2]; base.nodes[0] = e; base.nodes[0].DataType = e.DataType; base.DataType = DateTimeType.GetDateTimeType(0x5e, e.DataType.Scale); break; case 0x5d: base.nodes = new Expression[2]; base.nodes[0] = e; base.nodes[0].DataType = e.DataType; base.DataType = DateTimeType.GetDateTimeType(0x5f, e.DataType.Scale); break; case 0x5e: { base.nodes = new Expression[1]; ExpressionOp op1 = new ExpressionOp(0x5c, e, null) { DataType = e.DataType }; base.nodes[0] = op1; base.DataType = DateTimeType.GetDateTimeType(0x5c, e.DataType.Scale); break; } case 0x5f: { base.nodes = new Expression[1]; ExpressionOp op2 = new ExpressionOp(0x5c, e, null) { DataType = e.DataType }; base.nodes[0] = op2; base.DataType = DateTimeType.GetDateTimeType(0x5d, e.DataType.Scale); break; } default: throw Error.RuntimeError(0xc9, "ExpressionOp"); } base.Alias = e.Alias; }
public static long FromDatetime(DateTime time, DateTimeType type) { switch (type) { case DateTimeType.Ticks: return(time.Ticks); case DateTimeType.UnixTimeSeconds: return((long)(time.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, time.Kind))).TotalSeconds); case DateTimeType.UnixTimeMilliseconds: return((long)(time.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, time.Kind))).TotalMilliseconds); default: throw new ArgumentOutOfRangeException(nameof(type), type, null); } }
public void Convert_Null_NullableDateTimeDefault() { // arrange DateTimeValueConverter converter = new DateTimeValueConverter(); DateTimeType type = new DateTimeType(); DateTime?expectedUtcOutput = default(DateTime?); // act bool result = converter.TryConvert( typeof(DateTimeOffset), typeof(DateTime?), null, out object convertedValue); // assert Assert.True(result); Assert.Equal(expectedUtcOutput, convertedValue); }
void convertToDateTime(int interval, string unit) { str_ = interval + unit; type_ = new DateTimeType(); Debug.Assert(unit.Contains("day") || unit.Contains("month") || unit.Contains("year")); int day = interval; if (unit.Contains("month")) { day *= 30; // FIXME } else if (unit.Contains("year")) { day *= 365; // FIXME } val_ = new TimeSpan(day, 0, 0, 0); }
public static DateTime ToDateTime(long value, DateTimeType type) { switch (type) { case DateTimeType.Ticks: return(new DateTime(value)); break; case DateTimeType.UnixTimeSeconds: return(unix.AddSeconds(value)); case DateTimeType.UnixTimeMilliseconds: return(unix.AddMilliseconds(value)); default: throw new ArgumentOutOfRangeException(nameof(type), type, null); } }
public void AssertEquals(ManyDataTypesPoco actualRow) { Assert.AreEqual(StringType, actualRow.StringType); Assert.AreEqual(GuidType, actualRow.GuidType); Assert.AreEqual(DateTimeType.ToString(), actualRow.DateTimeType.ToString()); // 'ToString' rounds to the nearest second Assert.AreEqual(DateTimeOffsetType.ToString(), actualRow.DateTimeOffsetType.ToString()); Assert.AreEqual(BooleanType, actualRow.BooleanType); Assert.AreEqual(DecimalType, actualRow.DecimalType); Assert.AreEqual(DoubleType, actualRow.DoubleType); Assert.AreEqual(FloatType, actualRow.FloatType); Assert.AreEqual(IntType, actualRow.IntType); Assert.AreEqual(Int64Type, actualRow.Int64Type); Assert.AreEqual(TimeUuidType, actualRow.TimeUuidType); Assert.AreEqual(NullableTimeUuidType, actualRow.NullableTimeUuidType); Assert.AreEqual(DictionaryStringLongType, actualRow.DictionaryStringLongType); Assert.AreEqual(DictionaryStringStringType, actualRow.DictionaryStringStringType); Assert.AreEqual(ListOfGuidsType, actualRow.ListOfGuidsType); Assert.AreEqual(ListOfStringsType, actualRow.ListOfStringsType); }
public void ReferenceAndValueTest9() { //Arrange - adaugam toate resursele de care avem nevoie DateTimeType object1 = null; string abc = null; Nullable <int> value = null; int? value2 = null; //Act - apelam metoda pe care vrem sa o testam if (value2.HasValue) { value2.Value.ToString(); } var result = value2?.ToString(); // result = null var result2 = value2 ?? 2; // daca value2 este null -> result2=2 if (value2 == null) { result2 = 2; } //Assert }
public void Convert_DateTimeOffset_LocalNullableDateTime() { // arrange DateTimeValueConverter converter = new DateTimeValueConverter(); DateTimeType type = new DateTimeType(); DateTimeOffset input = new DateTimeOffset( new DateTime(2018, 04, 05, 13, 15, 0), new TimeSpan(4, 0, 0)); DateTime?expectedUtcOutput = new DateTime( 2018, 04, 05, 09, 15, 0, DateTimeKind.Utc); // act bool result = converter.TryConvert( typeof(DateTimeOffset), typeof(DateTime?), input, out object convertedValue); // assert Assert.True(result); Assert.IsType <DateTime>(convertedValue); Assert.Equal(expectedUtcOutput, ((DateTime)convertedValue).ToUniversalTime()); }
public BufferType GetDataType() { if (bytes == null) { throw new InvalidOperationException("The DateTimeMarshaler is not set."); } DateTimeType type = (DateTimeType)(bytes[8] >> 5); if (type == DateTimeType.DT_TYPE_TIME) { return(BufferTypes.Time); } if (type == DateTimeType.DT_TYPE_DATE) { return(BufferTypes.Date); } if (type == DateTimeType.DT_TYPE_DATETIME) { return(BufferTypes.DateTime); } return(null); }
public void Update(ReferralData data) { firstName = data.FirstName.IsDefault ? firstName : data.FirstName; middleName = data.MiddleName.IsDefault ? middleName : data.MiddleName; lastName = data.LastName.IsDefault ? lastName : data.LastName; directSalesAgentId = data.DirectSalesAgentId.IsDefault ? directSalesAgentId : data.DirectSalesAgentId; streetAddress = data.StreetAddress.IsDefault ? streetAddress : data.StreetAddress; city = data.City.IsDefault ? city : data.City; state = data.State.IsDefault ? state : data.State; postalCode = data.PostalCode.IsDefault ? postalCode : data.PostalCode; latitude = data.Latitude.IsDefault ? latitude : data.Latitude; longitude = data.Longitude.IsDefault ? longitude : data.Longitude; email = data.Email.IsDefault ? email : data.Email; phoneNumber = data.PhoneNumber.IsDefault ? phoneNumber : data.PhoneNumber; messageBody = data.MessageBody.IsDefault ? messageBody : data.MessageBody; preferredContactMethod = data.PreferredContactMethod.IsDefault ? preferredContactMethod : data.PreferredContactMethod; distance = data.Distance.IsDefault ? distance : data.Distance; referralDate = data.ReferralDate.IsDefault ? referralDate : data.ReferralDate; demonstratorNotified = data.DemonstratorNotified.IsDefault ? demonstratorNotified : data.DemonstratorNotified; iPAddress = data.IPAddress.IsDefault ? iPAddress : data.IPAddress; referralSourceId = data.ReferralSourceId.IsDefault ? referralSourceId : data.ReferralSourceId; Store(); }
void convertToDateTime(int interval, string unit) { string[] validIntevals = { "years", "months", "days", "hours", "minutes", "seconds", "year", "month", "day", "hour", "minute", "second" }; str_ = interval + unit; type_ = new DateTimeType(); Debug.Assert(validIntevals.Contains(unit)); // convert year/month to day or hour/min to second int days = 0, seconds = 0; if (unit.Contains("day")) { days = interval; } else if (unit.Contains("month")) { days = interval * 30; // FIXME } else if (unit.Contains("year")) { days = interval * 365; // FIXME } else if (unit.Contains("second")) { seconds = interval; } else if (unit.Contains("minute")) { seconds = interval * 60; } else if (unit.Contains("hour")) { seconds = interval * 3600; } val_ = new TimeSpan(days, 0, 0, seconds); }
private void ObjectToBytes (Object value, DateTimeType type) { Debug.WriteLineIf (Marshaler.marshalSwitch.Enabled, "DateTimeMarshaler.ObjectToBytes(" + value + ", " + type + ")"); int days, hour, minute, second, fraction, tz_offset_minutes; if (value is DateTime) { DateTime dt = (DateTime) value; TimeZone tz = TimeZone.CurrentTimeZone; TimeSpan tz_offset = tz.GetUtcOffset (dt); tz_offset_minutes = (int) (tz_offset.Hours * 60) + tz_offset.Minutes; dt -= tz_offset; int year = dt.Year; int month = dt.Month; int day_of_month = dt.Day; days = GetDays (year, month, day_of_month); if (type == DateTimeType.DT_TYPE_DATETIME) { hour = dt.Hour; minute = dt.Minute; second = dt.Second; fraction = (int)(dt.Ticks % TimeSpan.TicksPerSecond / 10L);// dt.Millisecond * Values.MicrosPerMilliSec; } else if (type == DateTimeType.DT_TYPE_DATE) { hour = minute = second = fraction = 0; } else throw new InvalidCastException (); } else if (value is TimeSpan) { if (type != DateTimeType.DT_TYPE_TIME) throw new InvalidCastException (); days = Values.DAY_ZERO; tz_offset_minutes = 0; TimeSpan ts = (TimeSpan) value; hour = ts.Hours; minute = ts.Minutes; second = ts.Seconds; fraction = (int)(ts.Ticks % TimeSpan.TicksPerSecond / 10L); //ts.Milliseconds * Values.MicrosPerMilliSec; } else if (value is VirtuosoDateTime) { VirtuosoDateTime dt = (VirtuosoDateTime) value; TimeZone tz = TimeZone.CurrentTimeZone; TimeSpan tz_offset = tz.GetUtcOffset (dt.Value); tz_offset_minutes = (int) (tz_offset.Hours * 60) + tz_offset.Minutes; long ticks = dt.Ticks - tz_offset.Ticks; dt = new VirtuosoDateTime(ticks); int year = dt.Year; int month = dt.Month; int day_of_month = dt.Day; days = GetDays (year, month, day_of_month); if (type == DateTimeType.DT_TYPE_DATETIME) { hour = dt.Hour; minute = dt.Minute; second = dt.Second; fraction = (int)dt.Microsecond; } else if (type == DateTimeType.DT_TYPE_DATE) { hour = minute = second = fraction = 0; } else throw new InvalidCastException (); } #if ADONET3 else if (value is VirtuosoDateTimeOffset) { VirtuosoDateTimeOffset dt = (VirtuosoDateTimeOffset)value; TimeSpan tz_offset = dt.Offset; tz_offset_minutes = (int)(tz_offset.Hours * 60) + tz_offset.Minutes; long ticks = dt.Ticks - tz_offset.Ticks; dt = new VirtuosoDateTimeOffset(ticks, new TimeSpan(0)); int year = dt.Year; int month = dt.Month; int day_of_month = dt.Day; days = GetDays(year, month, day_of_month); if (type == DateTimeType.DT_TYPE_DATETIME) { hour = dt.Hour; minute = dt.Minute; second = dt.Second; fraction = (int)dt.Microsecond; } else if (type == DateTimeType.DT_TYPE_DATE) { hour = minute = second = fraction = 0; } else throw new InvalidCastException(); } #endif else if (value is VirtuosoTimeSpan) { if (type != DateTimeType.DT_TYPE_TIME) throw new InvalidCastException(); days = Values.DAY_ZERO; tz_offset_minutes = 0; VirtuosoTimeSpan ts = (VirtuosoTimeSpan)value; hour = ts.Hours; minute = ts.Minutes; second = ts.Seconds; fraction = (int)ts.Microseconds; } else throw new InvalidCastException (); if (bytes == null) bytes = new byte[10]; bytes[0] = (byte) (days >> 16); bytes[1] = (byte) (days >> 8); bytes[2] = (byte) days; bytes[3] = (byte) hour; bytes[4] = (byte) ((minute << 2) | (second >> 4)); bytes[5] = (byte) ((second << 4) | (fraction >> 16)); bytes[6] = (byte) (fraction >> 8); bytes[7] = (byte) fraction; bytes[8] = (byte) (((tz_offset_minutes >> 8) & 0x07) | ((int) type << 5)); bytes[9] = (byte) tz_offset_minutes; }
public TCCircleDateTimeSelector() { InitializeComponent(); colorRotaryProxy = new LabelColorRotaryProxy(SettingColorLabel); SettingColorLabel.GestureRecognizers.Add(new TapGestureRecognizer { Command = new Command(() => SettingPage.SetValue(CircleSurfaceEffectBehavior.RotaryFocusObjectProperty, colorRotaryProxy)) }); SettingScroller.GestureRecognizers.Add(new TapGestureRecognizer { Command = new Command(() => SettingPage.SetValue(CircleSurfaceEffectBehavior.RotaryFocusObjectProperty, SettingScroller)) }); type = DateTimeType.Date; SettingValueTypeLabel.Text = type.ToString(); SettingValueType.IsToggled = true; SettingValueType.Toggled += (s, e) => { type = SettingValueType.IsToggled ? DateTimeType.Date : DateTimeType.Time; SettingValueTypeLabel.Text = type.ToString(); }; TimeTextPage.Appearing += (s, e) => { StringBuilder sb = new StringBuilder(); if (TimeSelector.ValueType == DateTimeType.Date) { if (TimeSelector.IsVisibleOfYear) { sb.AppendLine($"{TimeSelector.DateTime.Year} Year"); } if (TimeSelector.IsVisibleOfMonth) { sb.AppendLine($"{TimeSelector.DateTime.Month} Month"); } if (TimeSelector.IsVisibleOfDate) { sb.AppendLine($"{TimeSelector.DateTime.Day} Day"); } } else { if (TimeSelector.IsVisibleOfHour) { sb.AppendLine($"{TimeSelector.DateTime.Hour} Hour"); } if (TimeSelector.IsVisibleOfMinute) { sb.AppendLine($"{TimeSelector.DateTime.Minute} Minute"); } if (TimeSelector.IsVisibleOfAmPm) { sb.AppendLine($"{(TimeSelector.DateTime.Hour < 12 ? "AM" : "PM")}"); } } sb.AppendLine(); sb.AppendLine($"Marker = {ColorHexConverter.ToHexString(TimeSelector.MarkerColor)}"); sb.AppendLine($"Max = {(TimeSelector.ValueType == DateTimeType.Date ? TimeSelector.MaximumDate.ToString("yyyy-MM-dd") : TimeSelector.MaximumDate.ToString("HH:mm"))}"); sb.AppendLine($"Min = {(TimeSelector.ValueType == DateTimeType.Date ? TimeSelector.MinimumDate.ToString("yyyy-MM-dd") : TimeSelector.MinimumDate.ToString("HH:mm"))}"); TimeText.Text = sb.ToString(); }; }
public void Visit(DateTimeType dt) { //DateTime resDateTime = dt.Value; Or similar }
/// <summary>Initializes a new instance of the <see cref="DateTimeFormatAttribute" /> class.</summary> /// <param name="kind"><see cref="DateTimeKind" />.</param> /// <param name="type"><see cref="DateTimeType" />.</param> public DateTimeFormatAttribute(DateTimeKind kind, DateTimeType type) { Kind = kind; Type = type; }
public static DateTime ToDateTime(byte[] data, int start, UInt16Swap int16Swap, DateTimeType dateTimeType) { ushort year, moth, day, hour, min, sec; year = ToUInt16(data, start, int16Swap); moth = ToUInt16(data, start + 2, int16Swap); day = ToUInt16(data, start + 4, int16Swap); hour = ToUInt16(data, start + 6, int16Swap); min = ToUInt16(data, start + 8, int16Swap); sec = ToUInt16(data, start + 10, int16Swap); if (year <= 99) { year += 2000; } try { return(new DateTime(year, moth, day, hour, min, sec)); } catch (Exception) { return(DateTime.MinValue); } }
public void TestDateObject() { ICollection<PortableTypeConfiguration> typeCfgs = new List<PortableTypeConfiguration>(); typeCfgs.Add(new PortableTypeConfiguration(typeof(DateTimeType))); PortableConfiguration cfg = new PortableConfiguration {TypeConfigurations = typeCfgs}; PortableMarshaller marsh = new PortableMarshaller(cfg); DateTime now = DateTime.Now; DateTimeType obj = new DateTimeType(now); DateTimeType otherObj = marsh.Unmarshal<DateTimeType>(marsh.Marshal(obj)); Assert.AreEqual(obj.Loc, otherObj.Loc); Assert.AreEqual(obj.Utc, otherObj.Utc); Assert.AreEqual(obj.LocNull, otherObj.LocNull); Assert.AreEqual(obj.UtcNull, otherObj.UtcNull); Assert.AreEqual(obj.LocArr, otherObj.LocArr); Assert.AreEqual(obj.UtcArr, otherObj.UtcArr); Assert.AreEqual(obj.LocRaw, otherObj.LocRaw); Assert.AreEqual(obj.UtcRaw, otherObj.UtcRaw); Assert.AreEqual(obj.LocNullRaw, otherObj.LocNullRaw); Assert.AreEqual(obj.UtcNullRaw, otherObj.UtcNullRaw); Assert.AreEqual(obj.LocArrRaw, otherObj.LocArrRaw); Assert.AreEqual(obj.UtcArrRaw, otherObj.UtcArrRaw); }
public JqGridSearch(JqGridRequest request, NameValueCollection form, DateTimeType dateTimeType) { _request = request; _form = form; _dateTimeType = dateTimeType; }
public InvoiceCreated(string invoiceNumber, DateTime invoiceDate) { InvoiceNumber = invoiceNumber; InvoiceDate = invoiceDate; }
public async Task <DataGridViewModel <ProductDataGridViewModel> > GetDataGridSource(string orderBy, JqGridRequest request, NameValueCollection form, DateTimeType dateTimeType, int page, int pageSize) { var usersQuery = _products.AsQueryable(); var query = new JqGridSearch(request, form, dateTimeType).ApplyFilter(usersQuery); var dataGridModel = new DataGridViewModel <ProductDataGridViewModel> { Records = await query.AsQueryable().OrderBy(orderBy) .Skip(page * pageSize) .Take(pageSize).ProjectTo <ProductDataGridViewModel>(null, _mappingEngine).ToListAsync(), TotalCount = await query.AsQueryable().OrderBy(orderBy).CountAsync() }; return(dataGridModel); }
private TypeScriptType GetTypeScriptType(Type type) { TypeScriptType tst; if (TypeHelper.Is(type, typeof(string))) { tst = new StringType(); } else if (TypeHelper.Is(type, typeof(bool))) { tst = new BooleanType(); } else if (TypeHelper.Is(type, typeof(int), typeof(decimal), typeof(double), typeof(long), typeof(float), typeof(short), typeof(byte), typeof(uint), typeof(ushort), typeof(ulong), typeof(sbyte) )) { tst = new NumberType(); } else if (TypeHelper.Is(type, typeof(DateTime))) { tst = new DateTimeType(); } else if (TypeHelper.Is(type, typeof(TimeSpan))) { tst = new TimeSpanType(); } else if (type.IsGenericParameter) { tst = new GenericTypeParameter(); } else if (TypeHelper.IsDictionary(type)) { tst = new DictionaryType(); } else if (TypeHelper.IsEnumerable(type)) { tst = new ArrayType(); } else if (TypeHelper.IsEnum(type)) { tst = new EnumType(); } else { var processType = _options.TypeFilter(type); if (processType) { if (type.IsInterface) { tst = new InterfaceType(type); } else { tst = new CustomType(type); } } else { tst = new AnyType(); } } if (TypeHelper.IsNullableValueType(type)) { ((ValueType)tst).IsNullable = true; type = Nullable.GetUnderlyingType(type); } tst.ClrType = type; return tst; }
/// <summary> /// Interrogates the expression instance populating the report column that is exposed to the Report API service. /// </summary> /// <param name="argument">The argument.</param> /// <param name="reportColumn">The report column.</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns> private static bool PopulateTypeFromArgument(ActivityArgument argument, out DatabaseType type, out EntityType resourceType) { resourceType = null; if (argument.Is <StringArgument>()) { type = new StringType(); } else if (argument.Is <IntegerArgument>()) { type = new Int32Type(); } else if (argument.Is <CurrencyArgument>()) { type = new CurrencyType(); } else if (argument.Is <DecimalArgument>()) { type = new DecimalType(); } else if (argument.Is <DateArgument>()) { type = new DateType(); } else if (argument.Is <TimeArgument>()) { type = new TimeType(); } else if (argument.Is <DateTimeArgument>()) { type = new DateTimeType(); } else if (argument.Is <GuidArgument>()) { type = new GuidType(); } else if (argument.Is <BoolArgument>()) { type = new BoolType(); } else if (argument.Is <TypedArgument>()) { TypedArgument rla = argument.As <TypedArgument>(); resourceType = Entity.Get <EntityType>(rla.ConformsToType); if (resourceType == null) { type = null; return(false); } if (resourceType.IsOfType.FirstOrDefault(t => t.Alias == "core:enumType") != null) { // A choice field type = new ChoiceRelationshipType(); } else { // Is a related resource type = new InlineRelationshipType(); } } else { type = null; return(false); } return(true); }
public string GetTypeName(DateTimeType tst) { return "string"; }
public static string ConvertDateTime(string src, DateTimeType dtt = DateTimeType.DateTime) { if (string.IsNullOrEmpty(src)) return ""; src = src.Trim(); switch (dtt) { default: case DateTimeType.DateTime: string[] srca = src.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); if (srca == null || srca.Length != 2) return src; string srca0 = srca[0]; while (srca0.IndexOf("-") >= 0) srca0 = srca0.Replace("-", "/"); string srca1 = srca[1]; while (srca1.IndexOf("-") >= 0) srca1 = srca1.Replace("-", ":"); return srca0 + " " + srca1; case DateTimeType.Date: while (src.IndexOf("-") >= 0) src = src.Replace("-", "/"); return src; case DateTimeType.Time: while (src.IndexOf("-") >= 0) src = src.Replace("-", ":"); return src; } }
public object Read(DateTimeType dateTimeType) => TypeConverter.DateTimeEpochStart.AddSeconds(reader.ReadUInt32());
internal static void MarshalDate (Stream stream, object value, DateTimeType type) { DateTimeMarshaler m = new DateTimeMarshaler (); m.ObjectToBytes (value, type); m.Marshal (stream); }
public DatetimeLiteral(DateTimeType DateTimeType) { this.DateTimeType = DateTimeType; }
public void Seed() { DateTimeType type = (DateTimeType)NHibernateUtil.DateTime; Assert.IsTrue(type.Seed(null) is DateTime, "seed should be DateTime"); }
/// <summary>Initializes a new instance of the <see cref="TimeSpanFormatAttribute" /> class.</summary> /// <param name="type"><see cref="DateTimeType" />.</param> public TimeSpanFormatAttribute(DateTimeType type) => Type = type;
/// <summary> /// 添加缓存 /// </summary> /// <param name="key">key</param> /// <param name="obj">对象</param> /// <param name="type">日期类型</param> /// <param name="num">长度</param> public static void Add(string key, object obj, DateTimeType type, int num) { Add <object>(key, obj, type, num); }
private void ObjectToBytes(Object value, DateTimeType type) { Debug.WriteLineIf(Marshaler.marshalSwitch.Enabled, "DateTimeMarshaler.ObjectToBytes(" + value + ", " + type + ")"); int days, hour, minute, second, fraction, tz_offset_minutes; if (value is DateTime) { DateTime dt = (DateTime)value; TimeZone tz = TimeZone.CurrentTimeZone; TimeSpan tz_offset = tz.GetUtcOffset(dt); tz_offset_minutes = (int)(tz_offset.Hours * 60) + tz_offset.Minutes; dt -= tz_offset; int year = dt.Year; int month = dt.Month; int day_of_month = dt.Day; days = GetDays(year, month, day_of_month); if (type == DateTimeType.DT_TYPE_DATETIME) { hour = dt.Hour; minute = dt.Minute; second = dt.Second; fraction = (int)(dt.Ticks % TimeSpan.TicksPerSecond / 10L); // dt.Millisecond * Values.MicrosPerMilliSec; } else if (type == DateTimeType.DT_TYPE_DATE) { hour = minute = second = fraction = 0; } else { throw new InvalidCastException(); } } else if (value is TimeSpan) { if (type != DateTimeType.DT_TYPE_TIME) { throw new InvalidCastException(); } days = Values.DAY_ZERO; tz_offset_minutes = 0; TimeSpan ts = (TimeSpan)value; hour = ts.Hours; minute = ts.Minutes; second = ts.Seconds; fraction = (int)(ts.Ticks % TimeSpan.TicksPerSecond / 10L); //ts.Milliseconds * Values.MicrosPerMilliSec; } else if (value is VirtuosoDateTime) { VirtuosoDateTime dt = (VirtuosoDateTime)value; TimeZone tz = TimeZone.CurrentTimeZone; TimeSpan tz_offset = tz.GetUtcOffset(dt.Value); tz_offset_minutes = (int)(tz_offset.Hours * 60) + tz_offset.Minutes; long ticks = dt.Ticks - tz_offset.Ticks; dt = new VirtuosoDateTime(ticks); int year = dt.Year; int month = dt.Month; int day_of_month = dt.Day; days = GetDays(year, month, day_of_month); if (type == DateTimeType.DT_TYPE_DATETIME) { hour = dt.Hour; minute = dt.Minute; second = dt.Second; fraction = (int)dt.Microsecond; } else if (type == DateTimeType.DT_TYPE_DATE) { hour = minute = second = fraction = 0; } else { throw new InvalidCastException(); } } #if ADONET3 else if (value is VirtuosoDateTimeOffset) { VirtuosoDateTimeOffset dt = (VirtuosoDateTimeOffset)value; TimeSpan tz_offset = dt.Offset; tz_offset_minutes = (int)(tz_offset.Hours * 60) + tz_offset.Minutes; long ticks = dt.Ticks - tz_offset.Ticks; dt = new VirtuosoDateTimeOffset(ticks, new TimeSpan(0)); int year = dt.Year; int month = dt.Month; int day_of_month = dt.Day; days = GetDays(year, month, day_of_month); if (type == DateTimeType.DT_TYPE_DATETIME) { hour = dt.Hour; minute = dt.Minute; second = dt.Second; fraction = (int)dt.Microsecond; } else if (type == DateTimeType.DT_TYPE_DATE) { hour = minute = second = fraction = 0; } else { throw new InvalidCastException(); } } #endif else if (value is VirtuosoTimeSpan) { if (type != DateTimeType.DT_TYPE_TIME) { throw new InvalidCastException(); } days = Values.DAY_ZERO; tz_offset_minutes = 0; VirtuosoTimeSpan ts = (VirtuosoTimeSpan)value; hour = ts.Hours; minute = ts.Minutes; second = ts.Seconds; fraction = (int)ts.Microseconds; } else { throw new InvalidCastException(); } if (bytes == null) { bytes = new byte[10]; } bytes[0] = (byte)(days >> 16); bytes[1] = (byte)(days >> 8); bytes[2] = (byte)days; bytes[3] = (byte)hour; bytes[4] = (byte)((minute << 2) | (second >> 4)); bytes[5] = (byte)((second << 4) | (fraction >> 16)); bytes[6] = (byte)(fraction >> 8); bytes[7] = (byte)fraction; bytes[8] = (byte)(((tz_offset_minutes >> 8) & 0x07) | ((int)type << 5)); bytes[9] = (byte)tz_offset_minutes; }
/// <summary> /// 获得DateTime /// </summary> /// <param name="type"></param> /// <param name="num"></param> /// <returns></returns> public static DateTime GetDateTime(DateTimeType type, double num) { DateTime dt = DateTime.Now; return(GetDateTime(dt, type, num)); }
private object BytesToObject() { Debug.WriteLineIf(Marshaler.marshalSwitch.Enabled, "DateTimeMarshaler.BytesToObject()"); int days = (bytes[0] << 16) | (bytes[1] << 8) | bytes[2]; int hour = bytes[3]; int minute = bytes[4] >> 2; int second = ((bytes[4] & 0x03) << 4) | (bytes[5] >> 4); long fraction = ((bytes[5] & 0x0f) << 16) | (bytes[6] << 8) | bytes[7]; DateTimeType type = (DateTimeType)(bytes[8] >> 5); int tz_offset_minutes = ((bytes[8] & 0x03) << 8) | bytes[9]; if ((bytes[8] & 0x04) != 0) { tz_offset_minutes |= (-1 & ~0x03ff); } Debug.WriteLineIf(Marshaler.marshalSwitch.Enabled, "type: " + type); if (type == DateTimeType.DT_TYPE_TIME) { VirtuosoTimeSpan ts = new VirtuosoTimeSpan(0, hour, minute, second, fraction); Debug.WriteLineIf(Marshaler.marshalSwitch.Enabled, "TimeSpan: " + ts); return(ts); } #if ADONET3 else if (type == DateTimeType.DT_TYPE_DATETIME) { int year, month, day_of_month; GetDate(days, out year, out month, out day_of_month); TimeSpan tz_offset = new TimeSpan(0, tz_offset_minutes, 0); VirtuosoDateTimeOffset dt = new VirtuosoDateTimeOffset(year, month, day_of_month, hour, minute, second, fraction, tz_offset); dt = dt.AddMinutes(tz_offset_minutes); Debug.WriteLineIf(Marshaler.marshalSwitch.Enabled, "DateTime: " + dt); return(dt); } else if (type == DateTimeType.DT_TYPE_DATE) { int year, month, day_of_month; GetDate(days, out year, out month, out day_of_month); VirtuosoDateTime dt = new VirtuosoDateTime(year, month, day_of_month, hour, minute, second, fraction); Debug.WriteLineIf(Marshaler.marshalSwitch.Enabled, "DateTime: " + dt); return(dt); } #else else if (type == DateTimeType.DT_TYPE_DATETIME || type == DateTimeType.DT_TYPE_DATE) { int year, month, day_of_month; GetDate(days, out year, out month, out day_of_month); VirtuosoDateTime dt = new VirtuosoDateTime(year, month, day_of_month, hour, minute, second, fraction); dt = dt.AddMinutes(tz_offset_minutes); Debug.WriteLineIf(Marshaler.marshalSwitch.Enabled, "DateTime: " + dt); return(dt); } #endif else { throw new InvalidCastException(); } }
public void DateTimeTypeNames() { var expected = new[] { "System.DateTime", "System.TimeSpan" }; var actual = new DateTimeType().TypeNames; TestHelper.AreEqual(expected, actual); }
public DatetimeLiteral(DateTimeType DateTimeType, DateTime Value) { this.DateTimeType = DateTimeType; this.Value = Value; }