ユーザーからの入力に基づいてList<Interval> intervals
を返す必要があります。範囲に夏時間が含まれていない限り、すべて正常に動作します。それが起こった場合、私が得た応答は、その特定の日(この例では11月1日のESTタイムゾーン)のあとにちょっと混乱してしまいます。UTC(joda間隔)からの異なるタイムゾーンに基づくJava夏時間の処理
私のデータはDBにUTCとして保存されているので、私はUTCで作業しています(リクエストはUTCで、私の応答はUTCでもあります)。しかしブラウザでは時刻はローカルのタイムゾーンに変換されます。バックエンドで私はユーザーのタイムゾーンにアクセスできます。
質問は、サマータイムを含むUTCへの応答時間を変換する方法です。ここ
public List<Interval> buildIntervals(BinInterval binSize) {
final DateTime intervalStart = binSize.getInterval().getStart();
final DateTime intervalEnd = binSize.getInterval().getEnd();
final DateTimeZone tz = getCurrentUserTimezone();
List<Interval> intervals = new ArrayList<>();
MutableDateTime currentBinStart = new MutableDateTime(intervalStart);
MutableDateTime currentBinEnd = new MutableDateTime(intervalStart.plus(binSize.getPeriod()));
while (currentBinEnd.isBefore(intervalEnd)) {
intervals.add(makeInterval(currentBinStart, currentBinEnd));
currentBinStart = new MutableDateTime(currentBinStart.toDateTime().plus(binSize.getPeriod()));
currentBinEnd = new MutableDateTime(currentBinEnd.toDateTime().plus(binSize.getPeriod()));
}
}
private static Interval makeInterval(BaseDateTime start, BaseDateTime end) {
return new Interval(start.toDateTime().withZone(DateTimeZone.UTC),
end.toDateTime().withZone(DateTimeZone.UTC));
}
間違っている試料の応答である:
行17の正しいバージョンがあるべきである。行17からendDate: "2015-11-02T05:00:00.000z"
及び終了時間をさらに+5であるべきです。
18行目以降では、開始時間も+5にする必要がありますが、何らかの理由で、日照時間の前後で正しい時間に変換されません。
11月1日以降に範囲を選択すると、それが完全に機能し、+ 5に変換されます。
私のローカルタイムゾーンはESTです。