static struct tm *time2tm(const time_t *timer) { DateTimeRec dtr; MachineLocation loc; time_t macLocal = *timer; static struct tm statictime; static const short monthday[12] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}; UNIX_TO_MACOS(macLocal); SecondsToDate(macLocal, &dtr); statictime.tm_sec = dtr.second; /* second, from 0 to 59 */ statictime.tm_min = dtr.minute; /* minute, from 0 to 59 */ statictime.tm_hour = dtr.hour; /* hour, from 0 to 23 */ statictime.tm_mday = dtr.day; /* day of the month, from 1 to 31 */ statictime.tm_mon = dtr.month - 1; /* month, 1= January and 12 = December */ statictime.tm_year = dtr.year - 1900; /* year, ranging from 1904 to 2040 */ statictime.tm_wday = dtr.dayOfWeek - 1; /* day of the week, 1 = Sun, 7 = Sat */ statictime.tm_yday = monthday[statictime.tm_mon] + statictime.tm_mday - 1; if (2 < statictime.tm_mon && !(statictime.tm_year & 3)) { ++statictime.tm_yday; } myReadLocation(&loc); statictime.tm_isdst = DaylightSaving(); return(&statictime); }
struct tm * TclpGetDate( TclpTime_t time, /* Time struct to fill. */ int useGMT) /* True if date should reflect GNT time. */ { const time_t *tp = (const time_t *)time; DateTimeRec dtr; MachineLocation loc; long int offset; static struct tm statictime; static const short monthday[12] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}; ReadLocation(&loc); if (useGMT) { SecondsToDate(*tp, &dtr); } else { offset = loc.u.gmtDelta & 0x00ffffff; if (offset & 0x00700000) { offset |= 0xff000000; } SecondsToDate(*tp + offset, &dtr); } statictime.tm_sec = dtr.second; statictime.tm_min = dtr.minute; statictime.tm_hour = dtr.hour; statictime.tm_mday = dtr.day; statictime.tm_mon = dtr.month - 1; statictime.tm_year = dtr.year - 1900; statictime.tm_wday = dtr.dayOfWeek - 1; statictime.tm_yday = monthday[statictime.tm_mon] + statictime.tm_mday - 1; if (1 < statictime.tm_mon && !(statictime.tm_year & 3)) { ++statictime.tm_yday; } statictime.tm_isdst = loc.u.dlsDelta; return(&statictime); }
void DisplayTime(DialogPtr dialog, short monthItem, Seconds seconds) { char num[20]; DateTimeRec time; SecondsToDate (seconds, &time); Float2EditText(dialog, monthItem, time.month, 0); Float2EditText(dialog, monthItem + 1, time.day, 0); Float2EditText(dialog, monthItem + 2, time.year, 0); Float2EditText(dialog, monthItem + 3, time.hour, 0); sprintf(num, "%02hd", time.minute); mysetitext(dialog, monthItem + 4, num); }
void gpp_get_realtime (long *pdt) { UnsignedWide microTickCount, nMicroTickCount; long idate; static const int mstart[12] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }; long secs; DateTimeRec dateRec; static DateTimeRec baseDateRec = {1980, 1, 1, 0, 0, 0, 1}; void do_get_clock (DateTimeRec *dateRec, long *pdt); if ((beginMicroTickCount.lo == 0)&&(beginMicroTickCount.hi == 0) ) { Microseconds(&beginMicroTickCount); } Microseconds(µTickCount); nMicroTickCount.lo = microTickCount.lo - beginMicroTickCount.lo; nMicroTickCount.hi = microTickCount.hi - beginMicroTickCount.hi; GetDateTime ((unsigned long *) &secs); SecondsToDate (secs, &dateRec); /* If the date is reasonable, subtract the days since Jan. 1, 1980 */ idate = ((long) dateRec.year - 1980) * 365 + /* days per year */ (((long) dateRec.year - 1)/4 - 1979/4) + /* intervening leap days */ (1979/100 - ((long) dateRec.year - 1)/100) + (((long) dateRec.month - 1)/400 - 1979/400) + mstart[dateRec.month - 1] + /* month is 1-origin */ dateRec.day - 1; /* day of month is 1-origin */ idate += (2 < dateRec.month && (dateRec.year % 4 == 0 && (dateRec.year % 100 != 0 || dateRec.year % 400 == 0))); pdt[0] = ((idate*24 + dateRec.hour) * 60 + dateRec.minute) * 60 + dateRec.second; pdt[1] = nMicroTickCount.lo * 100; //#define DEBUG_CLOCK 1 #ifdef DEBUG_CLOCK fprintf(stderr,"pdt[0] = %ld pdt[1] = %ld\n", pdt[0], pdt[1]); fprintf(stderr,"b hi[0] = %ld lo[1] = %ld\n", beginMicroTickCount.hi, beginMicroTickCount.lo); fprintf(stderr,"m hi[0] = %ld lo[1] = %ld\n", microTickCount.hi, microTickCount.lo); #endif }
//---------------------------------------------------------------------- // Retrieves the Real-Time Clock Alarm (RTCA) "trigger" time from the // 1-Wire device in the form of a timedate structure: // // typedef struct // { // ushort second; // ushort minute; // ushort hour; // ushort day; // ushort month; // ushort year; // } timedate; // // Parameters: // portnum the port number of the port being used for the // 1-Wire network. // SNum The 1-Wire address of the device to communicate. // * td Pointer to a timedate struct to return the time/date. // // Returns: TRUE if the write worked // FALSE if there was an error in reading // // * td Returns the alarm time/date in a timedate struct. // SMALLINT getRTCA(int portnum, uchar * SNum, timedate * td) { uchar timebuffer[4]; ulong timelong = 0; // read 4 bytes for alarm trigger from 1-Wire clock device (memory bank 2) // starting at address 0x11. if (!readNV(2, portnum, SNum, 0x11, FALSE, &timebuffer[0], 4)) { return FALSE; } timelong = uchar_to_bin(&timebuffer[0],4); SecondsToDate(td,timelong); return TRUE; }
static void cnvdatetime(unsigned long s, DOSDATE *dosdate, DOSTIME *dostime) { DateTimeRec dtr; ZeroMemory(&dtr, sizeof(dtr)); SecondsToDate(s, &dtr); if (dosdate) { dosdate->year = dtr.year; dosdate->month = (UINT8)dtr.month; dosdate->day = (UINT8)dtr.day; } if (dostime) { dostime->hour = (UINT8)dtr.hour; dostime->minute = (UINT8)dtr.minute; dostime->second = (UINT8)dtr.second; } }
static void cnvdatetime(UTCDateTime *dt, DOSDATE *dosdate, DOSTIME *dostime) { LocalDateTime ldt; DateTimeRec dtr; ZeroMemory(&dtr, sizeof(dtr)); ConvertUTCToLocalDateTime(dt, &ldt); SecondsToDate(ldt.lowSeconds, &dtr); if (dosdate) { dosdate->year = dtr.year; dosdate->month = (UINT8)dtr.month; dosdate->day = (UINT8)dtr.day; } if (dostime) { dostime->hour = (UINT8)dtr.hour; dostime->minute = (UINT8)dtr.minute; dostime->second = (UINT8)dtr.second; } }
void ONScripterLabel::searchSaveFile( SaveFileInfo &save_file_info, int no ) { char file_name[256]; bool use_fullwidth = (script_h.system_menu_script == ScriptHandler::JAPANESE_SCRIPT); script_h.getStringFromInteger( save_file_info.sjis_no, no, (num_save_file >= 10)?2:1, false, use_fullwidth ); #if defined(LINUX) || defined(MACOSX) if (script_h.savedir) sprintf( file_name, "%ssave%d.dat", script_h.savedir, no ); else sprintf( file_name, "%ssave%d.dat", script_h.save_path, no ); struct stat buf; struct tm *tm; if ( stat( file_name, &buf ) != 0 ){ save_file_info.valid = false; return; } time_t mtime = buf.st_mtime; tm = localtime( &mtime ); save_file_info.month = tm->tm_mon + 1; save_file_info.day = tm->tm_mday; save_file_info.hour = tm->tm_hour; save_file_info.minute = tm->tm_min; #elif defined(WIN32) if (script_h.savedir) sprintf( file_name, "%ssave%d.dat", script_h.savedir, no ); else sprintf( file_name, "%ssave%d.dat", script_h.save_path, no ); HANDLE handle; FILETIME tm, ltm; SYSTEMTIME stm; handle = CreateFile( file_name, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ); if ( handle == INVALID_HANDLE_VALUE ){ save_file_info.valid = false; return; } GetFileTime( handle, NULL, NULL, &tm ); FileTimeToLocalFileTime( &tm, <m ); FileTimeToSystemTime( <m, &stm ); CloseHandle( handle ); save_file_info.month = stm.wMonth; save_file_info.day = stm.wDay; save_file_info.hour = stm.wHour; save_file_info.minute = stm.wMinute; #elif defined(MACOS9) if (script_h.savedir) sprintf( file_name, "%ssave%d.dat", script_h.savedir, no ); else sprintf( file_name, "%ssave%d.dat", script_h.save_path, no ); CInfoPBRec pb; Str255 p_file_name; FSSpec file_spec; DateTimeRec tm; c2pstrcpy( p_file_name, file_name ); if ( FSMakeFSSpec(0, 0, p_file_name, &file_spec) != noErr ){ save_file_info.valid = false; return; } pb.hFileInfo.ioNamePtr = file_spec.name; pb.hFileInfo.ioVRefNum = file_spec.vRefNum; pb.hFileInfo.ioFDirIndex = 0; pb.hFileInfo.ioDirID = file_spec.parID; if (PBGetCatInfoSync(&pb) != noErr) { save_file_info.valid = false; return; } SecondsToDate( pb.hFileInfo.ioFlMdDat, &tm ); save_file_info.month = tm.month; save_file_info.day = tm.day; save_file_info.hour = tm.hour; save_file_info.minute = tm.minute; #elif defined(PSP) if (script_h.savedir) sprintf( file_name, "%ssave%d.dat", script_h.savedir, no ); else sprintf( file_name, "%ssave%d.dat", script_h.save_path, no ); SceIoStat buf; if ( sceIoGetstat(file_name, &buf)<0 ){ save_file_info.valid = false; return; } save_file_info.month = buf.st_mtime.month; save_file_info.day = buf.st_mtime.day; save_file_info.hour = buf.st_mtime.hour; save_file_info.minute = buf.st_mtime.minute; #else sprintf( file_name, "save%d.dat", no ); FILE *fp; if ( (fp = fopen( file_name, "rb" )) == NULL ){ save_file_info.valid = false; return; } fclose( fp ); save_file_info.month = 1; save_file_info.day = 1; save_file_info.hour = 0; save_file_info.minute = 0; #endif save_file_info.valid = true; script_h.getStringFromInteger( save_file_info.sjis_month, save_file_info.month, 2, false, use_fullwidth ); script_h.getStringFromInteger( save_file_info.sjis_day, save_file_info.day, 2, false, use_fullwidth ); script_h.getStringFromInteger( save_file_info.sjis_hour, save_file_info.hour, 2, false, use_fullwidth ); script_h.getStringFromInteger( save_file_info.sjis_minute, save_file_info.minute, 2, true, use_fullwidth ); }
ListItem TShioTimeValue::GetNthListItem(long n, short indent, short *style, char *text) {//JLM ListItem item = { this, n, indent, 0 }; text[0] = 0; *style = normal; ///////////// if(n == 0) { // line 1 station name item.indent--; sprintf(text,"Station Name: %s",fStationName); return item; } n--; ///////// // code goes here, possible check if num max/mins below some threshold and then show all values... /*if( 0 <= n && n < this->GetNumValues()) { return TOSSMTimeValue::GetNthListItem(n, indent, style, text); // to show all time values }*/ ///////// if (this->fStationType == 'C') { if( 0 <= n && n < this->GetNumEbbFloodValues()) // show only max/mins { EbbFloodData ebbFloodData; DateTimeRec time; char *p,timeStr[32],valStr[32],typeStr[32],unitsStr[32]=" kts "; ebbFloodData = INDEXH(fEbbFloodDataHdl, n); switch(ebbFloodData.type) { case MinBeforeFlood: strcpy(typeStr,"MinBFld "); break; case MaxFlood: strcpy(typeStr,"MaxFld "); break; case MinBeforeEbb: strcpy(typeStr,"MinBEbb "); break; case MaxEbb: strcpy(typeStr,"MaxEbb "); break; } StringWithoutTrailingZeros(valStr,ebbFloodData.speedInKnots,1); SecondsToDate (ebbFloodData.time, &time); //time.year = time.year %100;// year 2000 fix , JLM 1/25/99 (two digit year) sprintf (timeStr, "%2.2d:%2.2d %02hd/%02hd/%02hd", time.hour, time.minute, time.month, time.day, time.year); //Date2String(&time, timeStr); //if (p = strrchr(timeStr, ':')) p[0] = 0; // remove seconds sprintf(text, "%s%s%s%s",typeStr,valStr,unitsStr,timeStr); return item; } } ///////// else if (this->fStationType == 'H') { if (n == 0) { item.bullet = fHighLowValuesOpen ? BULLET_OPENTRIANGLE : BULLET_CLOSEDTRIANGLE; strcpy(text, "Show High Lows"); return item; } n--; if( 0 <= n && n < this->GetNumHighLowValues() && fHighLowValuesOpen) // show only high/lows { HighLowData highLowData; DateTimeRec time; char timeStr[32],valStr[32],typeStr[32],unitsStr[32]=" ft "; highLowData = INDEXH(fHighLowDataHdl, n); switch(highLowData.type) { case LowTide: strcpy(typeStr,"Low Tide "); break; case HighTide: strcpy(typeStr,"High Tide "); break; default: strcpy(typeStr,"Unknown "); break; } StringWithoutTrailingZeros(valStr,highLowData.height * fScaleFactor,1); SecondsToDate (highLowData.time, &time); sprintf (timeStr, "%2.2d:%2.2d %02hd/%02hd/%02hd", time.hour, time.minute, time.month, time.day, time.year); sprintf(text, "%s%s%s%s",typeStr,valStr,unitsStr,timeStr); return item; } if (n>=this->GetNumHighLowValues() && fHighLowValuesOpen) n-=this->GetNumHighLowValues(); if (n == 0) { item.bullet = fEbbFloodValuesOpen ? BULLET_OPENTRIANGLE : BULLET_CLOSEDTRIANGLE; strcpy(text, "Show Ebb Floods"); return item; } n--; if( (0 <= n && n < 2*(this->GetNumHighLowValues()) - 1 && fEbbFloodValuesOpen)) // show only max/mins, converted from high/lows { HighLowData startHighLowData,endHighLowData; DateTimeRec time; double maxMinDeriv; Seconds midTime,derivTime; long index = floor(n/2.); char timeStr[32],valStr[32],typeStr[32],/*unitsStr[32]=" ft/hr ",*/unitsStr[32]=" kts "; startHighLowData = INDEXH(fHighLowDataHdl, index); endHighLowData = INDEXH(fHighLowDataHdl, index+1); midTime = (endHighLowData.time - startHighLowData.time)/2 + startHighLowData.time; switch(startHighLowData.type) { case LowTide: if (fmod(n,2.) == 0) { strcpy(typeStr,"MinBFld "); derivTime = startHighLowData.time; } else { strcpy(typeStr,"MaxFld "); derivTime = midTime; } break; case HighTide: if (fmod(n,2.) == 0) { strcpy(typeStr,"MinBEbb "); derivTime = startHighLowData.time; } else { strcpy(typeStr,"MaxEbb "); derivTime = midTime; } break; } maxMinDeriv = GetDeriv(startHighLowData.time, startHighLowData.height, endHighLowData.time, endHighLowData.height, derivTime) * fScaleFactor / KNOTSTOMETERSPERSEC; StringWithoutTrailingZeros(valStr,maxMinDeriv,1); SecondsToDate(derivTime, &time); sprintf (timeStr, "%2.2d:%2.2d %02hd/%02hd/%02hd", time.hour, time.minute, time.month, time.day, time.year); sprintf(text, "%s%s%s%s",typeStr,valStr,unitsStr,timeStr); return item; } } else if (this->fStationType == 'P') { if (n == 0) { item.bullet = fHighLowValuesOpen ? BULLET_OPENTRIANGLE : BULLET_CLOSEDTRIANGLE; strcpy(text, "Show High Lows"); return item; } n--; if( 0 <= n && n < this->GetNumHighLowValues() && fHighLowValuesOpen) // show only high/lows { HighLowData highLowData; DateTimeRec time; char timeStr[32],valStr[32],typeStr[32],unitsStr[32]=" ft "; highLowData = INDEXH(fHighLowDataHdl, n); switch(highLowData.type) { case LowTide: strcpy(typeStr,"Low Tide "); break; case HighTide: strcpy(typeStr,"High Tide "); break; default: strcpy(typeStr,"Unknown "); break; } StringWithoutTrailingZeros(valStr,highLowData.height * fScaleFactor,1); SecondsToDate (highLowData.time, &time); sprintf (timeStr, "%2.2d:%2.2d %02hd/%02hd/%02hd", time.hour, time.minute, time.month, time.day, time.year); sprintf(text, "%s%s%s%s",typeStr,valStr,unitsStr,timeStr); return item; } } item.owner = 0; // not our item return item; }