What is the format of this hex timestamp from the Amazon SES message ID? - parsing

Amazon SES message IDs are in the following format:
01020170c41acd6e-89acae55-6245-4d89-86ca-0a177e59e737-000000
This seems to consist of 3 distinct parts
01020170c41acd6e appears to be some sort of hex timestamp. The difference between two timestamps is the time elapsed in milliseconds but it doesn't seem to begin at epoch
c2daf94a-f258-4d59-8fdb-a5512d4c7638 is clearly a standard version 4 UUID
000000 remains the same for first sending and I assume is incremented for redelivery attempts
I have a need to generate a 'fake' message ID in some scenarios. It is trivial to fake 2 and 3 above however I cannot seem to deduce what the format of the timestamp above is. Here are some further examples with corresponding approximate times:
01020170c450e280 - Mar 10, 2020 at 12:00:00.190
01020170c44c2e6a - Mar 10, 2020 at 11:54:51.987
01020170c0e30119 - Mar 09, 2020 at 20:01:07.407
What format is this timestamp?

Taking your first example of 01020170c450e280, the string can be split into 01020 and 170c450e280.
170c450e280 hex == 1583841600128 dec == 2020-03-10T12:00:00.128Z.
However, I'm afraid that the 01020 prefix remains a mystery to me.

Related

Find the start of a given week and year with Delphi

I'm looking for a Delphi (10+) function that returns a TDate with a given year and a week number:
function StartDate(2021, 53): TDate should return 2021-01-01.
While WeekOfTheYear(EncodeDate(2021,1,1)) returns 53 (correct), I can't do the other way round with StartOfAWeek(2021,53, 1) nor StartOfAWeek(2021,53, 5) (5=it's a friday) - it's not recognized as a valid date (=exception). Any suggestions?
Edited:
I'm looking for a ISO 8601 compliant function (like the internal Delphi routines), with Monday=1 and special week consideration (like 2021-01-01), or to be more precise: the "vice versa" routine of WeekOfTheYear
The function you need is:
StartOfAWeek(Year, Week, 1)
You observe that StartOfAWeek(2021, 53, 1) raises an exception. That is correct because 2021 does not have 53 weeks. It only has 52. Week 52 ends on the last day of 2021.
You are getting confused by the result of
WeekOfTheYear(EncodeDate(2021,1,1))
This returns 53, but because the date is at the start of the year, this is week 53 of 2020.

Decoding the expiry date of a JavaScript Web Token (JWT)?

I am unable to understand the expiry date format of the JWT embedded in my application.
For example: 1473912000
What does this translate to? 1473912000 ms, some x date? Any help will be appreciated!
Like James has pointed out:
The number is the number of seconds since Jan 1 1970.
This is converted into the Date object in a quite straight-forward way (the *1000 part is here because in JS main time unit is millisecond):
const expiryDate = new Date(1473912000*1000);
Then you can use any Date method you please.
Likewise, in Ruby you can use Time.at(1473912000) to create a new Time instance like Maxim has shown.
The number is the number of seconds since Jan 1 1970. It is commonly used on unix systems to represent time. Your time is 2016-09-15 04:00 (UTC)
To convert you can try a web based system http://www.unixtimestamp.com/index.php
This is UNIX time in seconds:
➜ ~ irb
2.2.0 :001 > Time.at(1473912000)
=> 2016-09-15 07:00:00 +0300

why pytz.country_timezones('cn') in centos system have different result?

Two computer install centos 6.5, kernel is 3.10.44, have different result.
one result is [u'Asia/Shanghai', u'Asia/Urumqi'], and the other is ['Asia/Shanghai', 'Asia/Harbin', 'Asia/Chongqing', 'Asia/Urumqi', 'Asia/Kashgar'].
Is there any config that make the first result same as the second result?
I have following python code:
def get_date():
date = datetime.utcnow()
from_zone = pytz.timezone("UTC")
to_zone = pytz.timezone("Asia/Urumqi")
date = from_zone.localize(date)
date = date.astimezone(to_zone)
return date
def get_curr_time_stamp():
date = get_date()
stamp = time.mktime(date.timetuple())
return stamp
cur_time = get_curr_time_stamp()
print "1", time.strftime("%Y %m %d %H:%M:%S", time.localtime(time.time()))
print "2", time.strftime("%Y %m %d %H:%M:%S", time.localtime(cur_time))
When use this code to get time, the result of one computer(have 2 results) is:
1 2016 04 20 08:53:18
2 2016 04 20 06:53:18
and the other(have 5 results) is:
1 2016 04 20 08:53:18
2 2016 04 20 08:53:18
I don't know why?
You probably just have an outdated version of pytz on the system returning five time zones (or perhaps on both systems). You can find the latest releases here. It's important to stay on top of time zone updates, as the various governments of the world change their time zones often.
Like most systems, pytz gets its data from the tz database. The five time zones for China were reduced to two in version 2014f (corresponding to pytz 2014.6). From the release notes:
China's five zones have been simplified to two, since the post-1970
differences in the other three seem to have been imaginary. The
zones Asia/Harbin, Asia/Chongqing, and Asia/Kashgar have been
removed; backwards-compatibility links still work, albeit with
different behaviors for time stamps before May 1980. Asia/Urumqi's
1980 transition to UTC+8 has been removed, so that it is now at
UTC+6 and not UTC+8. (Thanks to Luther Ma and to Alois Treindl;
Treindl sent helpful translations of two papers by Guo Qingsheng.)
Also, you may wish to read Wikipedia's Time in China article, which explains that the Asia/Urumqui entry is for "Ürümqi Time", which is used unofficially in some parts of the Xinjiang region. This zone is not recognized by the Chinese government, and is considered a politically charged issue. As such, many systems choose to omit the Urumqi time zone, despite it being in listed in the tz database.

lua math.randomseed returns nothing

I have the following code:
APP.logevent('ostime:'..os.time())
APP.logevent('random:'..math.random())
APP.logevent(math.randomseed(os.time()))
When i check my logs, this is what I get:
Tue Feb 5 11:49:53 2013: ostime:1360082993
Tue Feb 5 11:49:53 2013: random:0.84018771715471
Tue Feb 5 11:49:53 2013:
machinename:/usr/share/ajj#
I'm not getting any error messages....
Can you tell me why the call to randomeseed() is failing?
I've also tried replacing the call to "os.time()" in the randomseed with a number... and that doesn't seem to work either.
Thanks.
lua math.randomseed returns nothing
It's not supposed to. Lua functions are not required to return a values, and there's no real reason for randomseed to return anything.
Can you tell me why the call to randomeseed() is failing?
It's not.
EDIT:
I thought it would create a random number for me.
That's what math.random does. randomseed seeds the random number generator, which is to say it sets an initial value that the pseudorandom number generator uses to find the next pseudorandom value. For a given seed (including the default seed, i.e. you never call randomseed), you'll get the same list of pseudorandom values back every time.

Decode GPS Data - No idea what the format is

I have a GPS tracker that a friend lent me. It's a chinese model, with sparse documentation.
It's got a built in gps and a gprs module (sim) and it's sending me my data to a particular IP address.
I can't figure out what all the numbers mean. I got latitude and long thanks to the N and E. but the rest I'm not sure about.
Here's an extract from my log:
4/28/2011 6:48:01 PM (001__450BP00BP05000001__450BP00110428A2451.6491N06700.6385E000.013474342.72000000000L0001ADFE)
4/28/2011 6:48:18 PM (001__450BP00BP05000001__450BP00110428A2451.6491N06700.6385E000.013480942.72000000000L0001ADFE)
4/28/2011 6:49:23 PM (001__450BP00BP05000001__450BP00110428A2451.6491N06700.6385E000.013490942.72000000000L0001ADFE)
4/28/2011 6:50:33 PM (001__450BP00BP05000001__450BP00110428A2451.6362N06700.6297E000.0135016198.8300000000L0001ADFE)
4/28/2011 6:51:39 PM (001__450BP00BP05000001__450BP00110428A2451.5203N06700.5738E000.0135114135.3800000000L0001AEFF)
4/28/2011 6:51:42 PM (001__450BP00BR02110428V2451.4962N06700.5942E000.0135133143.7700000000L0001AF23)
Note: the exact string from the tracker is stored within the round brackets (...)
I gave the dates and times because they may help decode the data if the tracker reports UTC time or something. Didn't see anything matching the time signature though
It would help if you post some more information (any serial numbers or other text on the device).
However, the messages look like GPS518.
I'm mostly guessing, but if I deconstruct the first line, I think this is the meaning:
Request
001 : ?
450 : deviceid
BP00 : handshake
BP05 : command
000001 : ?
Response
450 : device id
BP00 : command
110428 : date (format yymmdd)
A
2451.6491N : Latitude
06700.6385E : Longitude
000.0 : Speed (format nnn.n)
134743 : Time (format hhmmssas UTC) You probably live in GMT-7
42.720 : Heading/Bearing (?)
00000000L : Elevation
0001ADFE : ?
There's a discussion here that might be of interest:
http://sourceforge.net/projects/opengts/forums/forum/579834/topic/3871481
After some googling, I found this. It seems to generate message in roughly the same format as the ones that you are receiving:
http://kmmk.googlecode.com/svn/trunk/kmmk/src/com/gps/testmock/CommAdapterYD518.java
You can listen to the GPS data and parse it.
Please check the following link for more information:
https://github.com/anupama513/Tk102-gps-data-parser-nodejs-server
This is node js server:
listens continuously to the gps data
parse the GPRMC data
can store the data into database
Can also post the data to another webserver/socket.
The parse logic might be slightly different. But, most of the data matches.

Resources