Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Format of SAVE TO field 1

Status
Not open for further replies.

foxmuldr2

Programmer
May 22, 2012
91
US
Does anybody know the format of the SAVE TO filename.ext fields which are datetime or date?

For example, if you examine the file for numeric, character, logical, they're pretty clear. But it seems the datetime and date fields are encoded.

Best regards,
Rick C. Hodgin
 
Well, good enough and easiliy transferred to c++ for usage in your module. In fox we have Sys(10).

Bye, Olaf.
 
Code to append from above to have a fully functioning parser:

Code:
} else if (stv->type == 'd' || stv->type == 'D') {
    // Date
    stvd = (SSaveToVarDate*)start;
    // The value at stvd->dVal is a julian day number representing the date
    iComputeDateFromJulianDayNumber((u32)stvd->dVal, buffer);
    iAppendToTemplate(builder, buffer, strlen(buffer), NULL, NULL);
    // Indicate where the next one will go after this entry
    stv = (SSaveToVar*)(start + sizeof(SSaveToVarDate));

} else if (stv->type == 't' || stv->type == 'T') {
    // Datetime
    stvt = (SSaveToVarDatetime*)start;
    // The integer portion at stvt->dVal is a julian day number representing the date
    iComputeDateFromJulianDayNumber((u32)stvt->dVal, buffer);
    iAppendToTemplate(builder, buffer, strlen(buffer), NULL, NULL);
    // The fractional number portion at stvt->dVal relates to the seconds, which backs into the time.
    iAppendToTemplate(builder, " ", 1, NULL, NULL);
    // Compute the time from the fractional part
    iComputeTimeFromFraction((stvt->dVal - (u32)stvt->dVal) * 24.0 * 60.0 * 60.0, buffer);
    iAppendToTemplate(builder, buffer, strlen(buffer), NULL, NULL);
    // Indicate where the next one will go after this entry
    stv = (SSaveToVar*)(start + sizeof(SSaveToVarDatetime));

....


// Taken from [URL unfurl="true"]http://stason.org/TULARC/society/calendars/2-15-1-Is-there-a-formula-for-calculating-the-Julian-day-nu.html[/URL]
// Stores: mm/dd/yyyy
void iComputeDateFromJulianDayNumber(u32 tnJulianDayNumber, s8* tcDate11)
{
    u32 a, b, c, d, e, m, day, month, year;

    a       = tnJulianDayNumber + 32044;
    b       = ((4 * a) + 3) / 146097;
    c       = a - ((b * 146097) / 4);
    d       = ((4 * c) + 3) / 1461;
    e       = c - ((1461 * d) / 4);
    m       = ((5 * e) + 2) / 153;
    day     = e - (((153 * m) + 2) / 5) + 1;
    month   = m + 3 - (12 * (m / 10));
    year    = (b * 100) + d - 4800 + (m / 10);
    sprintf(tcDate11, "%02u/%02u/%04u\000", month, day, year);
}

// Takes the number of seconds elapsed since midnight and computes time
// hh:mm:ss.mls
void iComputeTimeFromFraction(f32 tfSeconds, s8* tcTime13)
{
    u32 lnHour, lnMinute, lnSecond, lnMillisecond;

    // Compute hour
    lnHour      = (u32)tfSeconds / (60 * 60);
    tfSeconds   = tfSeconds - (f32)(lnHour * 60 * 60);

    // Compute minute
    lnMinute    = (u32)tfSeconds / 60;
    tfSeconds   = tfSeconds - (f32)(lnMinute * 60);

    // Compute seconds
    lnSecond    = (u32)tfSeconds;
    tfSeconds   = tfSeconds - (f32)lnSecond;

    // Note:  Does not seem to be any value other than zero, though it could be as
    //        64-bit floating point values have about 15 significant digits.
    //        Julian date numbers are only 7, leaving 7 or so significant digits
    //        for the milliseconds position.  And even if it wasn't 100% accurate
    //        for milliseconds, having a partial would still be nice.
    // Compute milliseconds
    lnMillisecond = (u32)(tfSeconds * 999.0);

    // Build the time
    sprintf(tcTime13, "%02u:%02u:%02u.%03u\000", lnHour, lnMinute, lnSecond, lnMillisecond);
}

Best regards,
Rick C. Hodgin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top