Is there something wrong with this code? AMFReader vs AMFWriter
Posted
by Triynko
on Stack Overflow
See other posts from Stack Overflow
or by Triynko
Published on 2010-05-24T04:53:18Z
Indexed on
2010/05/24
5:01 UTC
Read the original article
Hit count: 325
Something doesn't seem right about the source code for Flash Remoting's Date(AS3) <-> DateTime(.NET) stream reader/writer methods, when it comes to handling UTC <-> Local times.
It seems to write the DateTime data fine, including a 64-bit representation as milliseconds elapsed since Jan 1, 1970, as well as a UTC offset.
public void WriteDateTime(DateTime d)
{
this.BaseStream.WriteByte(11);
DateTime time = new DateTime(0x7b2, 1, 1);
long totalMilliseconds = (long)d.Subtract(time).TotalMilliseconds;
long l = BitConverter.DoubleToInt64Bits((double)totalMilliseconds);
this.WriteLong(l);
int hours = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Today).Hours;
this.WriteShort(hours);
}
But when the data is read... it seems to be ignoring the short UTC offset value that was written, and appears to just discard it!
private DateTime ReadDateValue()
{
long num2 = (long)this.ReadDouble();
DateTime time2 = new DateTime(0x7b2, 1, 1).AddMilliseconds((double)num2);
int num3 = this.ReadInt16() / 60; //num3 is not used for anything!
return time2;
}
Can anyone make sense of this?
I also found some similar source code for AMFReader here, which has a ReadDateTime method, that seems to do something very similar... but goes on to use the UTC offset for something.
© Stack Overflow or respective owner