2008年4月14日月曜日

Google App Engine 入門4 Pythonで時差の処理




テンプレートの利用はあきらめて、Python 本体にて時刻の計算処理を行うことにしました。 (index.html でなく helloworld.py を変更)

Types and Property ClassesDatastore Value Types datetime.datetime に説明があります、
さらに詳細は Python へ  the datetime module documentation. のリンクとなています。
日本語だとこのあたりが timedeltaオブジェトなのですが、Python 自体に慣れていないので、実際に動作テストしてみました。

Pythonによるテストのため、まず PATH=C:\Python25  を追加しておきます。
環境変数 TZ による影響があるようです。

C:\google\helloworld>set TZ=
C:\google\helloworld>python
Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)]
>>> import datetime
>>> print datetime.datetime.now()
2008-04-14 13:17:36.953000
>>>

C:\google\helloworld>set TZ=JST
C:\google\helloworld>python
Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)]
>>> import datetime
>>> print datetime.datetime.now()
2008-04-14 04:21:32.015000
>>>
Ctl+Z で終了
-- test scrit tt.py
import datetime

class JST(datetime.tzinfo):
def utcoffset(self, dt):
return datetime.timedelta(hours=9)
def dst(self, dt):
return datetime.timedelta(0)
def tzname(self, dt):
return "JST"

print datetime.datetime.now().isoformat()
print datetime.datetime.now(JST()).isoformat()
実行結果
C:\google\helloworld>python tt.py
2008-04-14T04:28:33.468000
2008-04-14T13:28:33.468000+09:00

まずは、 helloworld.py の class MainPage にて以下のように出力するようにしました。
for greeting in greetings:
・・・
d = greeting.date + datetime.timedelta(hours=9)
self.response.out.write('%s
' % d.strftime("%Y/%m/%d %H:%M:%S") )
として対応することにしました。

参考
Pythonで現在の日付を取得してフォーマットする
http://www.r-stone.net/blogs/satoshi/2008/02/python.html

Unityでドアの開閉はAnimatorそれともiTween?

Mac Mini M2 の Unity で Sketchup のデータを復元したつづき。 以前、苦労して作成したドアの開閉が動作しないので修復する。 どうやって動かしていたのか、また忘れそうなので記録しておく。             Animator 左右のドア PlaneL,...