An archive of community.esquilo.io as of Saturday January 26, 2019.

The date() statement does not have local time. How do I setup for my local time?

gwittie

PROGRAM: sd:/projects/Thermal_Control/date_time.nut
//
// Date/Time Demo
//

// Get the current local date/time
t <- date(time(), 'l');

// Print the date + time
print("Local time:" + "\n");

print(t.month + "-" + t.day + "-" + t.year + " T ");
print(t.hour + ":" + t.min + ":" + t.sec + "\n");

t1 <- date(time(), 'u');

// Print the date + time
print("UTC time:" + "\n");
print(t1.month + "-" + t1.day + "-" + t1.year + " T ");
print(t1.hour + ":" + t1.min + ":" + t1.sec + "\n");

print("Squirrel time call: " + time() + "\n");

print("System time: ");
system("time")
//print("\n");

tsec <- time() - 39600; // UTC - 6 hours
t2 <- date(tsec);
print("Local from timestamp-6hrs:\n");
print(t2.month + "-" + t2.day + "-" + t2.year + " T ");
print(t2.hour + ":" + t2.min + ":" + t2.sec + "\n");

OUTPUT:
Running nut 'sd:/projects/Thermal_Control/date_time.nut'.
Local time:
6-0-2015 T 2:4:14
UTC time:
6-0-2015 T 2:4:14
Squirrel time call: 1435716254
System time: 2015-07-01T02:04:14Z
Local from timestamp-6hrs:
5-29-2015 T 15:4:14

gwittie

Also note the error in today's date. It lists today as June 0, 2015 which really should be July 1, 2015 UTC. If it was really local time, it would be June 30, 2015.

patrick

Thanks for reporting this and for the thorough writeup. Setting the local time doesn't seem to be in the standard Squirrel library, so we need to add support. I added a ticket to implement it and to investigate/fix the incorrect time you also see.