Numbers time is an hour out

Hi all,

I’m trying to insert the current date into a numbers spreadsheet but every time it inserts it’s and hour out:

set f to current date

tell application "Numbers"
	tell table 1 of active sheet of front document
		set value of cell 1 of row 1 to f
	end tell
end tell

any ideas?

Thanks,
Nik

It’s an old feature.

The engineers had to make a choice between the “current date-time” and what Applescript call “Time to GMT”.

the trick is exactly as old as the problem.

Don’t try to insert the date as a date but as a string.

The app will treat it as a date but will not apply the GMT/ UTC offset.

At this time : 17:48:05 in France, inserting a date inserts in fact 15:48:05 while inserting as string inserts tha wanted 17/48/05.

set f to (current date) as text

tell application "Numbers"
	tell table 1 of active sheet of front document
		set value of cell 1 of row 1 to f
	end tell
end tell

But there is a drawback.

Try to run :

set f to (current date) as text

tell application "Numbers"
	tell table 1 of active sheet of front document
		set value of cell 1 of row 1 to f
		delay 0.5
		value of cell 1 of row 1
	end tell
end tell

The cell will display 17:48:05 but the script will return 19:48:05 (in France of course)

If you do the same with your original attempt:

set f to (current date)

tell application "Numbers"
	tell table 1 of active sheet of front document
		set value of cell 1 of row 1 to f
		delay 0.5
		value of cell 1 of row 1
	end tell
end tell

The cell will display 15:48:05 and the script will return 17:48:05

As I am one of the users which filed a report about the fact that Numbers wasn’t taking care of the “local time”, I will not complain about the way they answer the question.

Honestly, I don’t know if they may give an answer satisfying every requirements.

My own tip is to use two cells to store a date-time value.
Here, I would insert the value in A1 and insert the formula =“”&A1 in B1

With that, when I need to extract the date-time with a script, I extract it from B1, not from A1 and there is no GMT/UTC offset striking.

There is just a remaining question : is my tip OK if I send my Numbers document to an user working with an other date-time format. If someone want to test, just send a mail at koenig yvan sfr fr

I will respond with an attached document. I assume that it will pass the test but true experience would be better.

Yvan KOENIG (VALLAURIS, France) mardi 19 mai 2015 18:01:19