cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
lala
Level VII

How does this binary file restore the correct time of year, month and day?

This file has four lines of data, and the first eight bytes of each line are the year, month, and day data
How to make a table correctly with JSL?

2023-01-29_21-49-08.png

1 ACCEPTED SOLUTION

Accepted Solutions
Craige_Hales
Super User

回复: How does this binary file restore the correct time of year, month and day?

You've got two big hints in the work you've already done: an actual date, and the code time_t. Time_t is a Unix thing. Lets try a tool like epoch converter, and push the date you know into it:

the red number is what we wantthe red number is what we want

Hey! that number also appears in your data inspector! It is an int 32! That means we can load your data like this:

za = Open( "z:/123.zip", zip );
blob = za << read( "123.dat", Format( blob ) );
dates = Blob To Matrix( blob, "int", 4, "little", 14 )[0, 1];

dates += 1jan1970;
For( i = 1, i <= 4, i += 1,
	Show( i, As Date( dates[i] ) )
);

i = 1;
As Date(dates[i]) = 20Jan2023:06:56:00;
i = 2;
As Date(dates[i]) = 20Jan2023:06:57:00;
i = 3;
As Date(dates[i]) = 20Jan2023:06:58:00;
i = 4;
As Date(dates[i]) = 20Jan2023:07:00:00;

 

The Unix epoch begins on 1Jan1970, which is 0. The JMP epoch begins on 1Jan1904, which is 0. Adding JMP's 1Jan1970 value to a Unix date converts the Unix date to a JMP date.

 

The blob to matrix call makes 14 4-byte numbers per row; the subscript [0,1] means 0: keep all 4 rows and 1: keep the first element on each row.

 

While you are playing with the epoch converter, try some dates in 2038. 2038 is the year of the next two Y2K-like events. Yes, there are two issues in one year. The first one is the Epochalypse at 03:14:07 UTC on 19 January 2038. The second one is the third GPS week roll over, which will probably go unnoticed. The third rollover will occur between November 20 and 21, 2038.

Craige

View solution in original post

2 REPLIES 2
lala
Level VII

回复: How does this binary file restore the correct time of year, month and day?

The date and time at the beginning of line 4 should be :

20230120 15:00

Thanks!

bb = Load Text File( "123.DAT", blob() );

z = Length( bb ) / 56;
For( k = 1, k <= z, k++,
	a = Blob Peek( bb, (k - 1) * 56, 56 );
	y = Blob To Matrix( a, "uint", 2, "little", 28 );
	s = Blob To Matrix( a, "uint", 4, "little", 28 );
	b = Blob To Matrix( a, "uint", 4, "little", 28 );
);

 

Craige_Hales
Super User

回复: How does this binary file restore the correct time of year, month and day?

You've got two big hints in the work you've already done: an actual date, and the code time_t. Time_t is a Unix thing. Lets try a tool like epoch converter, and push the date you know into it:

the red number is what we wantthe red number is what we want

Hey! that number also appears in your data inspector! It is an int 32! That means we can load your data like this:

za = Open( "z:/123.zip", zip );
blob = za << read( "123.dat", Format( blob ) );
dates = Blob To Matrix( blob, "int", 4, "little", 14 )[0, 1];

dates += 1jan1970;
For( i = 1, i <= 4, i += 1,
	Show( i, As Date( dates[i] ) )
);

i = 1;
As Date(dates[i]) = 20Jan2023:06:56:00;
i = 2;
As Date(dates[i]) = 20Jan2023:06:57:00;
i = 3;
As Date(dates[i]) = 20Jan2023:06:58:00;
i = 4;
As Date(dates[i]) = 20Jan2023:07:00:00;

 

The Unix epoch begins on 1Jan1970, which is 0. The JMP epoch begins on 1Jan1904, which is 0. Adding JMP's 1Jan1970 value to a Unix date converts the Unix date to a JMP date.

 

The blob to matrix call makes 14 4-byte numbers per row; the subscript [0,1] means 0: keep all 4 rows and 1: keep the first element on each row.

 

While you are playing with the epoch converter, try some dates in 2038. 2038 is the year of the next two Y2K-like events. Yes, there are two issues in one year. The first one is the Epochalypse at 03:14:07 UTC on 19 January 2038. The second one is the third GPS week roll over, which will probably go unnoticed. The third rollover will occur between November 20 and 21, 2038.

Craige