public static RubyTime /*!*/ Load(RubyContext /*!*/ context, RubyClass /*!*/ self, [NotNull] MutableString /*!*/ time) { byte[] data = time.ConvertToBytes(); if (data.Length != 8) { throw RubyExceptions.CreateTypeError("marshaled time format differ"); } uint dword1 = GetUint(data, 0); uint dword2 = GetUint(data, 4); if ((data[3] & 0x80) == 0) { int secondsSinceEpoch = (int)dword1; uint microseconds = dword2; return(new RubyTime(RubyTime.ToLocalTime(RubyTime.Epoch.AddTicks(RubyTime.ToTicks(secondsSinceEpoch, microseconds))))); } else { bool isUtc = (data[3] & 0x40) != 0; int year = 1900 + (int)((dword1 >> 14) & 0xffff); int month = 1 + (int)((dword1 >> 10) & 0x0f); int day = (int)((dword1 >> 5) & 0x01f); int hour = (int)(dword1 & 0x01f); int minute = (int)((dword2 >> 26) & 0x2f); int second = (int)((dword2 >> 20) & 0x2f); int usec = (int)(dword2 & 0xfffff); DateTime result; try { result = new DateTime(year, month, day, hour, minute, second, DateTimeKind.Utc).AddTicks(usec * 10); } catch (ArgumentOutOfRangeException) { throw RubyExceptions.CreateTypeError("marshaled time format differ"); } return(new RubyTime(isUtc ? result : RubyTime.ToLocalTime(result))); } }
public static RubyTime /*!*/ Create(RubyClass /*!*/ self, int seconds, int microseconds) { return(new RubyTime(RubyTime.ToLocalTime(RubyTime.Epoch.AddTicks(RubyTime.ToTicks(seconds, microseconds))))); }