예제 #1
0
        public static MutableString /*!*/ Dump(RubyContext /*!*/ context, RubyTime /*!*/ self, [Optional] int depth)
        {
            if (self.DateTime.Year < 1900 || self.DateTime.Year > 2038)
            {
                throw RubyExceptions.CreateTypeError("unable to marshal time");
            }

            DateTime value = RubyTime.ToUniversalTime(self.DateTime);

            // Little Endian
            //            32            |                32                  |
            // minute:6|second:6|usec:20|1|utc:1|year:16|month:4|day:5|hour:5|
            uint dword1 = self.Kind == DateTimeKind.Utc ? 0xC0000000 : 0x80000000;

            dword1 |= (unchecked ((uint)(value.Year - 1900)) << 14);
            dword1 |= (unchecked ((uint)(value.Month - 1)) << 10);
            dword1 |= ((uint)value.Day << 5);
            dword1 |= ((uint)value.Hour);

            uint dword2 = 0;

            dword2 |= ((uint)value.Minute << 26);
            dword2 |= ((uint)value.Second << 20);
            dword2 |= ((uint)((value.Ticks % 10000000) / 10));

            MemoryStream buf = new MemoryStream(8);

            RubyEncoder.Write(buf, dword1, !BitConverter.IsLittleEndian);
            RubyEncoder.Write(buf, dword2, !BitConverter.IsLittleEndian);
            return(MutableString.CreateBinary(buf.ToArray()));
        }
예제 #2
0
 public static MutableString /*!*/ Pack(
     ConversionStorage <IntegerValue> /*!*/ integerConversion,
     ConversionStorage <double> /*!*/ floatConversion,
     ConversionStorage <MutableString> /*!*/ stringCast,
     ConversionStorage <MutableString> /*!*/ tosConversion,
     RubyArray /*!*/ self, [DefaultProtocol, NotNull] MutableString /*!*/ format)
 {
     return(RubyEncoder.Pack(integerConversion, floatConversion, stringCast, tosConversion, self, format));
 }