Closed sysnux closed 5 years ago
Hi, thank you a lot for the pull request!
There seems to be an issue, indeed.
While I'm reviewing the code, could you please tell me what I did wrong, exactly?
It doesn't seem obvious at first glance.
Thanks!
Hi, Well, you're right, this is not obvious! But it seems that negative values have to be decoded as decimal. eg. for GMT-10, time zone characters are 0C, unswap and convert to int 0xC0, remove sign bit -> 0x40, should be considered as decimal 40. -15 * 40 -> -600 minutes or -10 hours. I also checked other implementations of SMS PDU: they do similar thing.
From https://en.wikipedia.org/wiki/GSM_03.40: "Time zone is given in quarters of an hour. If the time zone offset is negative (in Western hemisphere) bit 3 of the last octet is set to 1.
23:01:56 Mar 25th 2013 PST (GMT-7) would be encoded as 31 30 52 32 10 65 8A.
In this example, the time zone, 8A is binary 1000 1010. Bit 3 is 1, therefore the time zone is negative. The remaining number (bit-wise 'and' with 1111 0111) is 1000 0010, hexadecimal 82. Treat this as any previous element in the sequence, (hex 82 represents number 28). Finally the timezone offset is given by 28 × 15 minutes = 420 minutes (7 hours)."
Hi @sysnux
Sorry for the long waiting time, I believe I have fixed the issue with negative timestamps. I didn't merge this pull request however, because it didn't seem to be correct.
For instance, I believe that 111011315214C0
is not a possible encoding for a date.
I believe that datetime(2011, 1, 11, 13, 25, 41, tzinfo=timezone(timedelta(hours=3)))
should rather be encoded as 11101131521421
.
I am not 100% sure, so an additional review from you would be welcome!
I'm closing this PR for now.
Again, thanks for pointing out the issue and your explanation.
Hi,
I'm at GMT-10, and I observed that date decoded by smspdu was wrong, so I made a small correction. I have also added tests for dates.