Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ SMAUG
➜ SMAUG coding
➜ localtime() question
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Tux
(8 posts) Bio
|
| Date
| Tue 13 Mar 2007 08:23 PM (UTC) |
| Message
| | The server that hosts our smaug sever was moved to California from Georgia. The timezone has changed, and now our time in logs, commands, etc have changed as well. Is there a way to have the time in EST time instead ? The majority of our players are in the EST zone. I know that localtime() calls for the system time. I also know that you can export the TZ variable in linux in your .bash_profile (or whatever shell profile you use) to reflect the changes on a per user basis. However, the smaug server still uses the system's set time and timezone. Any ideas on how to change this? | | Top |
|
| Posted by
| Zeno
USA (2,871 posts) Bio
|
| Date
| Reply #1 on Tue 13 Mar 2007 08:55 PM (UTC) |
| Message
| | Just subtract/add the amount of time needed from it. |
Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org | | Top |
|
| Posted by
| Tux
(8 posts) Bio
|
| Date
| Reply #2 on Tue 13 Mar 2007 09:01 PM (UTC) |
| Message
| | Well, that's what we are having a hard time with. Do I modify the current_time variable? If so how? We are kinda new to learning C programming. Also, would we have to add in if() statements since it's displayed in military time? like if it's the 23rd hour, adding 3 to it would make it 26th hour that doesn't exist? Im not sure how to solve this problem. | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #3 on Tue 13 Mar 2007 10:39 PM (UTC) |
| Message
| localtime takes an argument of time_t, which is returned by the time() call, which is simply seconds since 00:00:00 UTC, January 1, 1970.
Thus, adding or subtracting some seconds from that, *before* attempting to convert to hours/minutes/seconds, will simply adjust the time.
eg.
Make the time an hour later: add 60 * 60
Make the time 3 hours earlier: subtract 3 * 60 * 60
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Tux
(8 posts) Bio
|
| Date
| Reply #4 on Wed 14 Mar 2007 02:10 AM (UTC) |
| Message
| | Sorry to keep bugging, but do you think you could show an example? I'm lost | | Top |
|
| Posted by
| Zeno
USA (2,871 posts) Bio
|
| Date
| Reply #5 on Wed 14 Mar 2007 02:41 AM (UTC) |
| Message
| ch_printf( ch, "Current time + 1 hour: %s\n\r", (char *) ctime( ¤t_time+3600 ));
|
Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org | | Top |
|
| Posted by
| Tux
(8 posts) Bio
|
| Date
| Reply #6 on Wed 14 Mar 2007 03:09 PM (UTC) |
| Message
| When we tried that, we got a message of
Current time: Sat Oct 26 14:02:00 1974
Neither the date, time or year are correct that way. LOL it's like a retro flashback. | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #7 on Thu 15 Mar 2007 03:52 AM (UTC) |
| Message
| I think Zeno's version is a bit wrong, you can't add 3600 to the pointer. This test program works, and prints out the time an hour later than the current time:
#include <time.h>
#include <stdio.h>
int main (void)
{
time_t current_time = time (NULL); // current time
current_time += 3600; // add an hour
printf("Current time + 1 hour: %s\n\r", ctime( ¤t_time ));
} // end of main
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Tux
(8 posts) Bio
|
| Date
| Reply #8 on Thu 15 Mar 2007 03:26 PM (UTC) Amended on Thu 15 Mar 2007 03:28 PM (UTC) by Tux
|
| Message
| Thanks Nick, that did the trick, a simple little
current_time+=10800;
in the do_time function was all we needed to add 3 hours.
Now I get to track down the other places where we have a current_time and adjust those aswell. Also, is there a way to edit it globally?
Appreciate the help everyone, it has been a good learning experience. | | Top |
|
| Posted by
| David Haley
USA (3,881 posts) Bio
|
| Date
| Reply #9 on Thu 15 Mar 2007 03:38 PM (UTC) |
| Message
| You can edit it "globally" by finding the place where current_time is set to begin with, which is, if I remember correctly, comm.c at the beginning of a main loop iteration. Of course, if you do that, you will want to remove your previous change, otherwise you'll be three hours off in the other direction.
That being said, I think it would be improper to change the current time to something that is not the current time. If all you care about is a cosmetic shift, then only adjust times that are printed to the user. I wouldn't play too many games with convincing the whole game that the time is three hours off; a single mistake could seriously mess up your game's timing whereas if all you change are cosmetics, the worst that will happen is that a user will get a time they didn't expect. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | | Top |
|
| Posted by
| Darrik Vequir
(24 posts) Bio
|
| Date
| Reply #10 on Mon 19 Mar 2007 03:46 PM (UTC) |
| Message
|
I'm actually just going through the code now to adjust the time, since my server admin is AWOL and the time is going to be off for the next three weeks.
Adjusting current_time at the time it is set adjusts everything the mud outputs... including the logs, which I actually want. It sets three times... just before the DB load, and before and after the game loop. I'm putting it in as a sysdata variable so I can adjust it back when either my server admin returns or the previous daylight savings time date comes around and it changes itself :).
FYI - If you do put it in as a sysdata variable... don't try to adjust the time in int main... the sysdata structure isn't loaded until boot_db is called. | | Top |
|
| Posted by
| Tech9
(1 post) Bio
|
| Date
| Reply #11 on Mon 19 Mar 2007 10:57 PM (UTC) |
| Message
| Hey Darrik Vequir, can you tell me how you did that? I am trying to do the same thing.
Thanks in advance. | | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
34,353 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top