2012年5月9日 星期三

android.text.format.Time.normalize(boolean ignoreDst) sucks!!

因為想檢查輸入的日期是否合法
於是找上了 android.text.format.Time
http://developer.android.com/reference/android/text/format/Time.html#normalize%28boolean%29 上的說明也提到
Ensures the values in each field are in range. For example if the current value of this calendar is March 32, normalize() will convert it to April 1.
會將非法輸入自動變更為合法日期,正好符合需求

但測了 2 月 30 日的結果卻是完全不變,依舊是 2 月 30 日
本來以為是 API 本身的 bug,但測了範例的 3 月 32 日卻又正常運作
心想該不會條件只檢查了是否小於 32 日吧,於是又測了 4 月 31 日,結果出來真的還是 4 月 31 日(´・ω・`)

有夠陽春的啦,別說閏年的判斷了,連最基本的月份判斷都沒做(=△=. )

0 コメント:

張貼留言