Host Engineering Forum

General Category => Do-more CPUs and Do-more Designer Software => Topic started by: Bolt on June 08, 2023, 05:07:19 PM

Title: Date Structure Explanation
Post by: Bolt on June 08, 2023, 05:07:19 PM
How does a .Date structure work? How could it be deciphered externally? I know that today is 132580872, and The help file says "a signed 32-bit value that contains the .Year, .Month,and .Day field values packed into a single location (YYYYMMDD)", but I'm having a hard time figuring out how to interpret it. I'm trying to use it in a report generated via REST API, and wondering how to best decode it. I know I could do a STRPRINT to format the date, but trying to keep it non-string for the moment.
Title: Re: Date Structure Explanation
Post by: BobO on June 08, 2023, 05:48:07 PM
How does a .Date structure work? How could it be deciphered externally? I know that today is 132580872, and The help file says "a signed 32-bit value that contains the .Year, .Month,and .Day field values packed into a single location (YYYYMMDD)", but I'm having a hard time figuring out how to interpret it. I'm trying to use it in a report generated via REST API, and wondering how to best decode it. I know I could do a STRPRINT to format the date, but trying to keep it non-string for the moment.

View it in hex. Low byte is day. Next byte up is month. Upper word is year.
Title: Re: Date Structure Explanation
Post by: Bolt on June 08, 2023, 06:08:14 PM
Well that was easy.

Now if I were to create a block containing dates, MyBlock0-99.Date, with MyBlock0.Date being today, MyBlock1.Date being yesterday, etc, how could I accomplish that? I know I could shift the whole block down 1 notch every new day and write $Now.Date to it, but looking to do it retroactively with a daily summary task, looping through records and tabulating them for each day when requested.
Title: Re: Date Structure Explanation
Post by: BobO on June 08, 2023, 06:15:00 PM
Well that was easy.

Now if I were to create a block containing dates, MyBlock0-99.Date, with MyBlock0.Date being today, MyBlock1.Date being yesterday, etc, how could I accomplish that? I know I could shift the whole block down 1 notch every new day and write $Now.Date to it, but looking to do it retroactively with a daily summary task, looping through records and tabulating them for each day when requested.

FIFO works great for that or you can roll your own with a ring ring buffer.
Title: Re: Date Structure Explanation
Post by: franji1 on June 09, 2023, 09:48:40 AM
It's a union of the 3 Date fields as a single DWORD.  The Date/Time structure memory layout is as follows.  So the DWORD offset 0 in memory of a Date/Time structure contains the 3 parts of the date field (.Year in WORD1, .Month in BYTE1, .Day in BYTE0), OR look at it as a single DWORD as .Date

Code: [Select]
"Date/Time Struct" Structure Memory Layout (2 total DWORDs in length, DWORD Offset 0..1)
+------++----------------------------------------------------------------------------------------------------------------------------------++
|      || Most Significant                                                                                               Least Significant ||
|      ++----------------------------------------------------------------------------------------------------------------------------------++
|      ||                                                              DWORD                                                               ||
|      ++----------------------------------------------------------------++----------------------------------------------------------------++
|      ||                             WORD 1                             ||                             WORD 0                             ||
|      ++-------------------------------++-------------------------------++-------------------------------++-------------------------------++
|      ||             BYTE 3            ||             BYTE 2            ||             BYTE 1            ||             BYTE 0            ||
|DWORD ++---+---+---+---+---+---+---+---++---+---+---+---+---+---+---+---++---+---+---+---+---+---+---+---++---+---+---+---+---+---+---+---++
|Offset||b31|b30|b29|b28|b27|b26|b25|b24||b23|b22|b21|b20|b19|b18|b17|b16||b15|b14|b13|b12|b11|b10| b9| b8|| b7| b6| b5| b4| b3| b2| b1| b0||
+------++---+---+---+---+---+---+---+---++---+---+---+---+---+---+---+---++---+---+---+---+---+---+---+---++---+---+---+---+---+---+---+---++
Note: Every Bit Field layout only shows the Field # (no name).  See the list of Bit Field Names listed by Field # at the end.

+------++----------------------------------------------------------------++-------------------------------++-------------------------------++
|    0 ||   2                         .Year                        UWORD ||   3         .Month      UBYTE ||   4          .Day       UBYTE ||
|      ||----------------------------------------------------------------++-------------------------------++-------------------------------++
|      ||   1                                                          .Date                                                        SDWORD ||
+------++-------------------------------++-------------------------------++-------------------------------++-------------------------------++
|    1 ||   6       .DayOfWeek    UBYTE ||   7         .Hour       UBYTE ||   8        .Minute      UBYTE ||   9        .Second      UBYTE ||
|      ||-------------------------------++-------------------------------++-------------------------------++-------------------------------++
|      ||   5                                                          .Time                                                        SDWORD ||
+------++----------------------------------------------------------------------------------------------------------------------------------++