Having issue in isDaylightSavingTime in swift

when we check timezone.isDaylightSavingTime(for: <#T##Date#>) we get invalid data for 32 timezones.


Code:

let milliseconds: Double = 1115596800000 //09-MAY-2005 GMT 00:00

let seconds: Int64 = Int64(milliseconds / 1000)

let date = Date(timeIntervalSince1970: TimeInterval(seconds))


let timezone = TimeZone(identifier: "Atlantic/Stanley")!

let components = calendar.dateComponents(in: timezone, from: date)

print("Atlantic/Stanley: \(components.timeZone?.isDaylightSavingTime(for: date))")


we get false value for the date "09-MAY-2005" 32 affected timezone.


List of timezones:

Africa/Windhoek (fixed)

America/Bahia_Banderas (fixed)

America/Cancun (fixed)

America/Chihuahua (fixed)

America/Dawson (fixed)

America/Fort_Nelson (fixed)

America/Godthab (fixed)

America/North_Dakota/Beulah (fixed)

America/Nuuk (fixed)

America/Ojinaga (fixed)

America/Punta_Arenas (fixed)

America/Santarem (fixed)

America/Whitehorse (fixed)

Antarctica/Casey (fixed)

Antarctica/Palmer (fixed)

Asia/Amman (fixed)

Asia/Barnaul (fixed)

Asia/Bishkek (fixed)

Asia/Damascus (fixed)

Asia/Novosibirsk (fixed)

Asia/Sakhalin (fixed)

Asia/Tomsk (fixed)

Atlantic/Stanley (fixed)

Europe/Astrakhan (fixed)

Europe/Istanbul (fixed)

Europe/Minsk (fixed)

Europe/Saratov (fixed)

Europe/Simferopol (fixed)

Europe/Ulyanovsk (fixed)

Pacific/Apia (fixed)

Pacific/Bougainville (fixed)

Pacific/Fakaofo (fixed)

Posted on Jan 3, 2024 8:28 AM

Reply
1 reply

Jan 3, 2024 7:22 PM in response to Praveenpalani

The following works:


import UIKit

let iso8601DateFormatter = ISO8601DateFormatter()
var dateFormatter = DateFormatter()
dateFormatter.dateStyle = .full
dateFormatter.timeStyle = .full

let bogoTimeZone = TimeZone(identifier: "Atlantic/Stanley")!
dateFormatter.timeZone = bogoTimeZone
let dateJanuary = iso8601DateFormatter.date(from: "2005-01-01T00:00:00Z")!
let dateFormattedJanuary = dateFormatter.string(from: dateJanuary)
let dateMay = iso8601DateFormatter.date(from: "2005-05-09T00:00:00Z")!
let dateFormattedMay = dateFormatter.string(from: dateMay )
print("Time in \(bogoTimeZone) in January? \(dateFormattedJanuary)")
print("Time in \(bogoTimeZone) in May? \(dateFormattedMay)")
let isDSTInBogoTimeZoneJanuary = bogoTimeZone.isDaylightSavingTime(for: dateJanuary)
let isDSTInBogoTimeZoneMay = bogoTimeZone.isDaylightSavingTime(for: dateMay)
print("Is it DST in \(bogoTimeZone) on \(dateFormattedJanuary)? \(isDSTInBogoTimeZoneJanuary)")
print("Is it DST in \(bogoTimeZone) on \(dateFormattedMay)? \(isDSTInBogoTimeZoneMay)")


Output:


Time in Atlantic/Stanley (fixed) in January? Friday, December 31, 2004 at 9:00:00 PM Falkland Islands Summer Time
Time in Atlantic/Stanley (fixed) in May? Sunday, May 8, 2005 at 8:00:00 PM Falkland Islands Standard Time
Is it DST in Atlantic/Stanley (fixed) on Friday, December 31, 2004 at 9:00:00 PM Falkland Islands Summer Time? true
Is it DST in Atlantic/Stanley (fixed) on Sunday, May 8, 2005 at 8:00:00 PM Falkland Islands Standard Time? false

Having issue in isDaylightSavingTime in swift

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.