time_t cur_time, xmas_time;
struct tm tm_xmas, *tm_local;
int days;
char buffer[255];
time(&cur_time);
tm_local = localtime(&cur_time);
tm_xmas.tm_sec = 0;
tm_xmas.tm_min = 0;
tm_xmas.tm_hour = 0;
tm_xmas.tm_mday = 25;
tm_xmas.tm_mon = 11;
tm_xmas.tm_year = tm_local->tm_year;
if( tm_local->tm_mon >= 11 && tm_local->tm_mday >= 25 ) /* Christmas has passed this year, go to next year! */
tm_xmas.tm_year++;
xmas_time = mktime( &tm_xmas );
days = static_cast<int>(difftime( xmas_time, time( &cur_time ) ) / ( 3600 * 24 ));
if( days > 0 )
snprintf( buffer, 255, "$n utters the words '%i day%s to Christmas!'.", days, days == 1 ? "" : "s" );
else
snprintf( buffer, 255, "$n utters the words 'Christmas is here! Rejoice!'." );
act( buffer, ch, NULL, NULL, TO_ROOM );
time_t rawtime;
struct tm * timeinfo;
char buffer[80];
time (&rawtime);
timeinfo = localtime (&rawtime);
strftime (buffer, 80, "%X", timeinfo);
sendch (buffer, ch);
void dragon_time (CHAR_DATA *ch)
{
struct tm * timeinfo;
time_t timer;
char buffer[80];
// Set each timestamp set in Central Time
time (¤t_time);
timeinfo = localtime (¤t_time);
strftime (buffer, 80, "Day %d at %I:%M:%S\n\r", timeinfo);
sendch (buffer, ch);
//Add 7 days to the current time, convert to number of seconds from the EPOCH
//then add 7 days times 24 hours times 60 minutes times 60 seconds to get the
//number of seconds in 7 days.
timer = mktime (timeinfo) + (7 * 24 * 60 * 60);
timeinfo = localtime (&timer);
strftime (buffer, 80, "Day %d at %I:%M:%S\n\r", timeinfo);
sendch (buffer, ch);
return;
}
void dragon_remaining (CHAR_DATA *ch)
{
// time_t timer, countdown;
// int newtime;
/*
struct tm *newtime;
struct tm *newcount;
struct tm *final;
char buffer[80];
time (¤t_time);
newtime = localtime(¤t_time);
newcount = newtime + (7 * 24 * 60 * 60);
timer = mktime(newcount);
//time (&countdown);
// countdown = difftime(timer, time (¤t_time));
countdown = difftime (time(¤t_time), timer );
time (&countdown);
final = localtime(&countdown);
strftime (buffer, 80, "Time Left: %d days, %IHrs:%MMins:%SSecs\n\r", final);
sendch(buffer, ch);
*/
struct timeval newtime, faketime;
char buffer[80];
char buf[MSL];
time_t current, settime, final;
gettimeofday (&newtime, NULL);
current = (time_t) newtime.tv_sec;
gettimeofday (&faketime, NULL);
settime = (time_t) faketime.tv_sec;
final = difftime (current, settime);
strcpy (buffer, ctime (&final));
sprintf (buf, "%s", buffer);
sendch (buf, ch);
}
void dragon_remaining (CHAR_DATA *ch)
{
time_t current, newtime, countdown;
struct tm local;
char buffer[80], buf[MSL];
time (¤t);
local = localtime(¤t);
local.tm_sec += 60;
local.tm_min += 60;
local.tm_hour += 24;
local.tm_mday += 7;
newtime = mktime(&local); <— errors here
countdown = difftime(newtime, time(¤t_time));
strcpy (buffer, ctime (&countdown));
sprintf (buf, "%s", buffer);
sendch (buf, ch);
}
void dragon_remaining (CHAR_DATA *ch)
{
time_t current, countdown, ntime;
struct tm new, newtime;
struct tm *local;
char buffer[80], buf[MSL];
time (¤t);
local = localtime(¤t);
new.tm_sec += 60;
new.tm_min += 60;
new.tm_hour += 24;
new.tm_mday += 7;
ntime = mktime(&new);
newtime = mktime(local + new);
countdown = difftime(newtime, time(¤t_time));
start_time = time(0) + (86400 * 7); // now + a week
// time passes…
// …
now_time = time(0);
diff = start_time-now_time; // seconds left;
// logic to display time left here, ie
// below logic is completely wrong, but gives the idea
minutes = diff/60;
hours = diff/60;
days = diff/86400;
void wait ( int seconds )
{
clock_t endwait;
endwait = clock () + seconds * CLOCKS_PER_SEC ;
while (clock() < endwait) {}
}
int main ()
{
int n;
printf ("Starting countdown…\n");
for (n=10; n>0; n–)
{
printf ("%d\n",n);
wait (1);
}
printf ("FIRE!!!\n");
return 0;
}
Output:
Starting countdown…
10
9
8
7
6
5
4
3
2
1
struct tm * timeinfo;
time_t timer, countdown;
char buffer[80];
int down, current, timeleft;
// Set each timestamp set in Central Time
time (¤t_time);
current = time(¤t_time);
countdown = 604800 + time(¤t_time);
down = countdown;
timeleft = (difftime(down, current) / (3600 * 24));
sprintf (buffer, "%d", timeleft);
sendch (buffer, ch);