This question already has an answer here:
How to reliably determine time zone for a user from the Twitter API?
(1 answer)
Closed 5 years ago.
I'm looking at the Twitter REST API, and I see that the /users/show endpoint returns a string time zone. I'd like to translate this to an org.joda.time.DateTimeZone. Unfortunately, the value given in the example (https://dev.twitter.com/docs/api/1/get/users/show) "Pacific Time (US & Canada)", does not play nice with the DateTimeZone IDs (see below for a full list). How can I translate this Twitter time zone to a Joda DateTimeZone?
Here are the Joda DateTimeZone IDs:
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
Africa/Asmara
Africa/Asmera
Africa/Bamako
Africa/Bangui
Africa/Banjul
Africa/Bissau
Africa/Blantyre
Africa/Brazzaville
Africa/Bujumbura
Africa/Cairo
Africa/Casablanca
Africa/Ceuta
Africa/Conakry
Africa/Dakar
Africa/Dar_es_Salaam
Africa/Djibouti
Africa/Douala
Africa/El_Aaiun
Africa/Freetown
Africa/Gaborone
Africa/Harare
Africa/Johannesburg
Africa/Juba
Africa/Kampala
Africa/Khartoum
Africa/Kigali
Africa/Kinshasa
Africa/Lagos
Africa/Libreville
Africa/Lome
Africa/Luanda
Africa/Lubumbashi
Africa/Lusaka
Africa/Malabo
Africa/Maputo
Africa/Maseru
Africa/Mbabane
Africa/Mogadishu
Africa/Monrovia
Africa/Nairobi
Africa/Ndjamena
Africa/Niamey
Africa/Nouakchott
Africa/Ouagadougou
Africa/Porto-Novo
Africa/Sao_Tome
Africa/Timbuktu
Africa/Tripoli
Africa/Tunis
Africa/Windhoek
America/Adak
America/Anchorage
America/Anguilla
America/Antigua
America/Araguaina
America/Argentina/Buenos_Aires
America/Argentina/Catamarca
America/Argentina/ComodRivadavia
America/Argentina/Cordoba
America/Argentina/Jujuy
America/Argentina/La_Rioja
America/Argentina/Mendoza
America/Argentina/Rio_Gallegos
America/Argentina/Salta
America/Argentina/San_Juan
America/Argentina/San_Luis
America/Argentina/Tucuman
America/Argentina/Ushuaia
America/Aruba
America/Asuncion
America/Atikokan
America/Atka
America/Bahia
America/Bahia_Banderas
America/Barbados
America/Belem
America/Belize
America/Blanc-Sablon
America/Boa_Vista
America/Bogota
America/Boise
America/Buenos_Aires
America/Cambridge_Bay
America/Campo_Grande
America/Cancun
America/Caracas
America/Catamarca
America/Cayenne
America/Cayman
America/Chicago
America/Chihuahua
America/Coral_Harbour
America/Cordoba
America/Costa_Rica
America/Cuiaba
America/Curacao
America/Danmarkshavn
America/Dawson
America/Dawson_Creek
America/Denver
America/Detroit
America/Dominica
America/Edmonton
America/Eirunepe
America/El_Salvador
America/Ensenada
America/Fort_Wayne
America/Fortaleza
America/Glace_Bay
America/Godthab
America/Goose_Bay
America/Grand_Turk
America/Grenada
America/Guadeloupe
America/Guatemala
America/Guayaquil
America/Guyana
America/Halifax
America/Havana
America/Hermosillo
America/Indiana/Indianapolis
America/Indiana/Knox
America/Indiana/Marengo
America/Indiana/Petersburg
America/Indiana/Tell_City
America/Indiana/Vevay
America/Indiana/Vincennes
America/Indiana/Winamac
America/Indianapolis
America/Inuvik
America/Iqaluit
America/Jamaica
America/Jujuy
America/Juneau
America/Kentucky/Louisville
America/Kentucky/Monticello
America/Knox_IN
America/Kralendijk
America/La_Paz
America/Lima
America/Los_Angeles
America/Louisville
America/Lower_Princes
America/Maceio
America/Managua
America/Manaus
America/Marigot
America/Martinique
America/Matamoros
America/Mazatlan
America/Mendoza
America/Menominee
America/Merida
America/Metlakatla
America/Mexico_City
America/Miquelon
America/Moncton
America/Monterrey
America/Montevideo
America/Montreal
America/Montserrat
America/Nassau
America/New_York
America/Nipigon
America/Nome
America/Noronha
America/North_Dakota/Beulah
America/North_Dakota/Center
America/North_Dakota/New_Salem
America/Ojinaga
America/Panama
America/Pangnirtung
America/Paramaribo
America/Phoenix
America/Port-au-Prince
America/Port_of_Spain
America/Porto_Acre
America/Porto_Velho
America/Puerto_Rico
America/Rainy_River
America/Rankin_Inlet
America/Recife
America/Regina
America/Resolute
America/Rio_Branco
America/Rosario
America/Santa_Isabel
America/Santarem
America/Santiago
America/Santo_Domingo
America/Sao_Paulo
America/Scoresbysund
America/Shiprock
America/Sitka
America/St_Barthelemy
America/St_Johns
America/St_Kitts
America/St_Lucia
America/St_Thomas
America/St_Vincent
America/Swift_Current
America/Tegucigalpa
America/Thule
America/Thunder_Bay
America/Tijuana
America/Toronto
America/Tortola
America/Vancouver
America/Virgin
America/Whitehorse
America/Winnipeg
America/Yakutat
America/Yellowknife
Antarctica/Casey
Antarctica/Davis
Antarctica/DumontDUrville
Antarctica/Macquarie
Antarctica/Mawson
Antarctica/McMurdo
Antarctica/Palmer
Antarctica/Rothera
Antarctica/South_Pole
Antarctica/Syowa
Antarctica/Vostok
Arctic/Longyearbyen
Asia/Aden
Asia/Almaty
Asia/Amman
Asia/Anadyr
Asia/Aqtau
Asia/Aqtobe
Asia/Ashgabat
Asia/Ashkhabad
Asia/Baghdad
Asia/Bahrain
Asia/Baku
Asia/Bangkok
Asia/Beirut
Asia/Bishkek
Asia/Brunei
Asia/Calcutta
Asia/Choibalsan
Asia/Chongqing
Asia/Chungking
Asia/Colombo
Asia/Dacca
Asia/Damascus
Asia/Dhaka
Asia/Dili
Asia/Dubai
Asia/Dushanbe
Asia/Gaza
Asia/Harbin
Asia/Hebron
Asia/Ho_Chi_Minh
Asia/Hong_Kong
Asia/Hovd
Asia/Irkutsk
Asia/Istanbul
Asia/Jakarta
Asia/Jayapura
Asia/Jerusalem
Asia/Kabul
Asia/Kamchatka
Asia/Karachi
Asia/Kashgar
Asia/Kathmandu
Asia/Katmandu
Asia/Kolkata
Asia/Krasnoyarsk
Asia/Kuala_Lumpur
Asia/Kuching
Asia/Kuwait
Asia/Macao
Asia/Macau
Asia/Magadan
Asia/Makassar
Asia/Manila
Asia/Muscat
Asia/Nicosia
Asia/Novokuznetsk
Asia/Novosibirsk
Asia/Omsk
Asia/Oral
Asia/Phnom_Penh
Asia/Pontianak
Asia/Pyongyang
Asia/Qatar
Asia/Qyzylorda
Asia/Rangoon
Asia/Riyadh
Asia/Saigon
Asia/Sakhalin
Asia/Samarkand
Asia/Seoul
Asia/Shanghai
Asia/Singapore
Asia/Taipei
Asia/Tashkent
Asia/Tbilisi
Asia/Tehran
Asia/Tel_Aviv
Asia/Thimbu
Asia/Thimphu
Asia/Tokyo
Asia/Ujung_Pandang
Asia/Ulaanbaatar
Asia/Ulan_Bator
Asia/Urumqi
Asia/Vientiane
Asia/Vladivostok
Asia/Yakutsk
Asia/Yekaterinburg
Asia/Yerevan
Atlantic/Azores
Atlantic/Bermuda
Atlantic/Canary
Atlantic/Cape_Verde
Atlantic/Faeroe
Atlantic/Faroe
Atlantic/Jan_Mayen
Atlantic/Madeira
Atlantic/Reykjavik
Atlantic/South_Georgia
Atlantic/St_Helena
Atlantic/Stanley
Australia/ACT
Australia/Adelaide
Australia/Brisbane
Australia/Broken_Hill
Australia/Canberra
Australia/Currie
Australia/Darwin
Australia/Eucla
Australia/Hobart
Australia/LHI
Australia/Lindeman
Australia/Lord_Howe
Australia/Melbourne
Australia/NSW
Australia/North
Australia/Perth
Australia/Queensland
Australia/South
Australia/Sydney
Australia/Tasmania
Australia/Victoria
Australia/West
Australia/Yancowinna
Brazil/Acre
Brazil/DeNoronha
Brazil/East
Brazil/West
CET
CST6CDT
Canada/Atlantic
Canada/Central
Canada/East-Saskatchewan
Canada/Eastern
Canada/Mountain
Canada/Newfoundland
Canada/Pacific
Canada/Saskatchewan
Canada/Yukon
Chile/Continental
Chile/EasterIsland
Cuba
EET
EST
EST5EDT
Egypt
Eire
Etc/GMT
Etc/GMT+0
Etc/GMT+1
Etc/GMT+10
Etc/GMT+11
Etc/GMT+12
Etc/GMT+2
Etc/GMT+3
Etc/GMT+4
Etc/GMT+5
Etc/GMT+6
Etc/GMT+7
Etc/GMT+8
Etc/GMT+9
Etc/GMT-0
Etc/GMT-1
Etc/GMT-10
Etc/GMT-11
Etc/GMT-12
Etc/GMT-13
Etc/GMT-14
Etc/GMT-2
Etc/GMT-3
Etc/GMT-4
Etc/GMT-5
Etc/GMT-6
Etc/GMT-7
Etc/GMT-8
Etc/GMT-9
Etc/GMT0
Etc/Greenwich
Etc/UCT
Etc/UTC
Etc/Universal
Etc/Zulu
Europe/Amsterdam
Europe/Andorra
Europe/Athens
Europe/Belfast
Europe/Belgrade
Europe/Berlin
Europe/Bratislava
Europe/Brussels
Europe/Bucharest
Europe/Budapest
Europe/Chisinau
Europe/Copenhagen
Europe/Dublin
Europe/Gibraltar
Europe/Guernsey
Europe/Helsinki
Europe/Isle_of_Man
Europe/Istanbul
Europe/Jersey
Europe/Kaliningrad
Europe/Kiev
Europe/Lisbon
Europe/Ljubljana
Europe/London
Europe/Luxembourg
Europe/Madrid
Europe/Malta
Europe/Mariehamn
Europe/Minsk
Europe/Monaco
Europe/Moscow
Europe/Nicosia
Europe/Oslo
Europe/Paris
Europe/Podgorica
Europe/Prague
Europe/Riga
Europe/Rome
Europe/Samara
Europe/San_Marino
Europe/Sarajevo
Europe/Simferopol
Europe/Skopje
Europe/Sofia
Europe/Stockholm
Europe/Tallinn
Europe/Tirane
Europe/Tiraspol
Europe/Uzhgorod
Europe/Vaduz
Europe/Vatican
Europe/Vienna
Europe/Vilnius
Europe/Volgograd
Europe/Warsaw
Europe/Zagreb
Europe/Zaporozhye
Europe/Zurich
GB
GB-Eire
GMT
GMT+0
GMT-0
GMT0
Greenwich
HST
Hongkong
Iceland
Indian/Antananarivo
Indian/Chagos
Indian/Christmas
Indian/Cocos
Indian/Comoro
Indian/Kerguelen
Indian/Mahe
Indian/Maldives
Indian/Mauritius
Indian/Mayotte
Indian/Reunion
Iran
Israel
Jamaica
Japan
Kwajalein
Libya
MET
MST
MST7MDT
Mexico/BajaNorte
Mexico/BajaSur
Mexico/General
NZ
NZ-CHAT
Navajo
PRC
PST8PDT
Pacific/Apia
Pacific/Auckland
Pacific/Chatham
Pacific/Chuuk
Pacific/Easter
Pacific/Efate
Pacific/Enderbury
Pacific/Fakaofo
Pacific/Fiji
Pacific/Funafuti
Pacific/Galapagos
Pacific/Gambier
Pacific/Guadalcanal
Pacific/Guam
Pacific/Honolulu
Pacific/Johnston
Pacific/Kiritimati
Pacific/Kosrae
Pacific/Kwajalein
Pacific/Majuro
Pacific/Marquesas
Pacific/Midway
Pacific/Nauru
Pacific/Niue
Pacific/Norfolk
Pacific/Noumea
Pacific/Pago_Pago
Pacific/Palau
Pacific/Pitcairn
Pacific/Pohnpei
Pacific/Ponape
Pacific/Port_Moresby
Pacific/Rarotonga
Pacific/Saipan
Pacific/Samoa
Pacific/Tahiti
Pacific/Tarawa
Pacific/Tongatapu
Pacific/Truk
Pacific/Wake
Pacific/Wallis
Pacific/Yap
Poland
Portugal
ROC
ROK
Singapore
Turkey
UCT
US/Alaska
US/Aleutian
US/Arizona
US/Central
US/East-Indiana
US/Eastern
US/Hawaii
US/Indiana-Starke
US/Michigan
US/Mountain
US/Pacific
US/Pacific-New
US/Samoa
UTC
Universal
W-SU
WET
Zulu
use param utc_offset instead of time_zone
utc_offset store offset in seconds
DateTimeZone tz = DateTimeZone.forOffsetMillis(utc_offset_from_response * 1000);
Related
I'm using time.h with tm_hour to get the hour of the day, but the time is in 12 Hr format by default.
I need 24 Hour format (00-23 Hrs) for simple event time code, like:
time_t now;
struct tm * timeinfo;
time(&now);
timeinfo = localtime(&now);
Serial.println("24 Hr Time is: %H:%M:%S\n", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); //test
Serial.println(timeinfo->tm_hour);
if ((timeinfo->tm_hour)>= 22) // 10PM Event
//Do something here
Any syntax assistance appreciated.
I'm trying to extend TimeZone in Swift so that I can initialize it to give me a TimeZone at random. I've landed on the below, but there's a couple of things that seem wrong.
init?(random: Bool = false) {
if random {
let randomIdentifier = TimeZone.knownTimeZoneIdentifiers.randomElement()!
self.init(identifier: String(randomIdentifier))
} else {
return nil
}
}
Firstly, when I initialize a random element and print the result, it seems to have '(fixed)' added on to the end - what would be causing that please?
Secondly, is this even the correct approach to this problem? It seems odd that I'd even give the option to initialize with 'false', as other initializers offer all the other non-random initializations.
Any thoughts would be much appreciated!
One solution could be
extension TimeZone {
static var random: TimeZone? {
return TimeZone(identifier: TimeZone.knownTimeZoneIdentifiers.randomElement()!)
}
}
let random = TimeZone.random
random?.identifier // the name you're looking for
You could even change the random computed variable to return a non-optional as you can be sure knownTimeZoneIdentifiers is not empty.
static var random: TimeZone {
return TimeZone(identifier: TimeZone.knownTimeZoneIdentifiers.randomElement()!)!
}
Time zones are tricky because there is no definitive standard, even though it may seem like there is. I came across this problem a while back and produced this list from the Swift library:
"HST": "Pacific/Honolulu", -10
"AKST": "America/Juneau", -9
"AKDT": "America/Juneau", -9
"PDT": "America/Los_Angeles", -8
"PST": "America/Los_Angeles", -8
"MST": "America/Phoenix", -7
"MDT": "America/Denver", -7
"CDT": "America/Chicago", -6
"CST": "America/Chicago", -6
"PET": "America/Lima", -5
"COT": "America/Bogota", -5
"EDT": "America/New_York", -5
"EST": "America/New_York", -5
"AST": "America/Halifax", -4
"ADT": "America/Halifax", -4
"NST": "America/St_Johns", -330
"NDT": "America/St_Johns", -330
"CLST": "America/Santiago", -3
"ART": "America/Argentina/Buenos_Aires", -3
"CLT": "America/Santiago", -3
"BRT": "America/Sao_Paulo", -2
"BRST": "America/Sao_Paulo", -2
"GMT": "GMT", 0
"UTC": "UTC", 0
"WET": "Europe/Lisbon", 0
"BST": "Europe/London", 0
"WEST": "Europe/Lisbon", 0
"CEST": "Europe/Paris", +1
"CET": "Europe/Paris", +1
"WAT": "Africa/Lagos", +1
"EEST": "Europe/Athens", +2
"CAT": "Africa/Harare", +2
"EET": "Europe/Athens", +2
"MSK": "Europe/Moscow", +3
"MSD": "Europe/Moscow", +3
"TRT": "Europe/Istanbul", +3
"EAT": "Africa/Addis_Ababa", +3
"IRST": "Asia/Tehran", +330
"GST": "Asia/Dubai", +4
"PKT": "Asia/Karachi", +5
"IST": "Asia/Kolkata", +530
"BDT": "Asia/Dhaka", +6
"ICT": "Asia/Bangkok", +7
"WIT": "Asia/Jakarta", +7
"SGT": "Asia/Singapore", +8
"PHT": "Asia/Manila", +8
"HKT": "Asia/Hong_Kong", +8
"KST": "Asia/Seoul", +9
"JST": "Asia/Tokyo”, +9
"NZDT": "Pacific/Auckland", +13
"NZST": "Pacific/Auckland", +13
The duplicates show you just how "standard" this stuff is. You can curate your own list based on what you consider correct and produce a legitimate randomizer from that set.
The problem with Jack's answer is that time zone identifiers in Swift are uneven; some zones are overrepresented and others underrepresented based on how many regions Swift considers popular in that zone. Australia has 12 identifiers even though the country only has 3 time zones, for instance. To save time, you could just randomly generate a number between -12 hours and +14 hours in seconds and return a time zone using seconds from GMT.
extension TimeZone {
static var random: TimeZone? {
return TimeZone(secondsFromGMT: Int.random(in: -43200...50400))
}
}
if let t = TimeZone.random {
print(t)
}
If you want a neat division of time zones, just divide them into blocks and randomly select from that set. Just realize that there are half and quarter time zones too; not every time zone is a clean plus or minus 1 hour from its neighbor. If you do this approach, your array will have more than 24 integers, which should not worry you.
I'm pulling a timestamp from a datebase, it is using RFC3339 format but the timezone is missing. So when I try to compare the timestamps it will be off. How do I change dbtime to be Eastern time?
// time format
const
(
RFC3339 = "2006-01-02T15:04:05Z07:00"
)
//now time
now := time.Now()
nowtime := now.Unix()
fmt.Println("Nowtime:", nowtime)
fmt.Println("Now:", now)
//time in db
fmt.Println("Dbtime string:", dbtime)
udbtime, err := time.Parse.EST(RFC3339,dbtime)
fmt.Println("RFC3339: " + RFC3339)
fmt.Println("dbtime parsed", udbtime)
fmt.Println("dbtime parsed unixtime", udbtime.Unix())
My output is
Nowtime: 1466443640
Now: 2016-06-20 13:27:20.963232824 -0400 EDT
Dbtime string: 2016-06-20T12:41:45.14Z
RFC3339: 2006-01-02T15:04:05Z07:00
dbtime parsed 2016-06-20 12:41:45.14 +0000 UTC
dbtime parsed unixtime 1466426505
You could parse the timestamps using the defined time.RFC3339 like you've shown, and adjust them after the fact by adding the UTC offset so that they are correct in UTC.
udbtime = udbtime.Add(4*time.Hour)
This however requires that you check whether each time falls in EST or EDT to add the correct offset, unless you can assume they are all EDT.
A better way would be to use your own time format without a specific TZ offset (the Z isn't part of the time specification for parsing), and parse it with time.ParseInLocation.
This way you can account for the correct offset depending on whether the time would have been in EST or EDT.
https://play.golang.org/p/IrUnTwvlkk
RFC3339local := "2006-01-02T15:04:05Z"
loc, err := time.LoadLocation("America/New_York")
if err != nil {
log.Fatal(err)
}
ts1 := "2016-06-20T12:41:45.14Z"
t1, _ := time.ParseInLocation(RFC3339local, ts1, loc)
fmt.Println(t1)
// prints: 2016-06-20 12:41:45.14 -0400 EDT
ts2 := "2016-01-20T12:41:45.14Z"
t2, _ = time.ParseInLocation(RFC3339local, ts2, loc)
fmt.Println(t2)
// prints: 2016-01-20 12:41:45.14 -0500 EST
you can try go-carbon,a simple,semantic and developer-fridendly golang package for datetime
carbon.Parse("2020-12-31").ToRfc3339String()
// output
2020-12-31T00:00:00+08:00
https://github.com/golang-module/carbon
I work with an export from a Zimbra calendar and wold like to create a list of all events occurring on each day. The simplified calendar looks like this.
BEGIN:VCALENDAR
X-WR-CALNAME:Test-Parking
VERSION:2.0
BEGIN:VTIMEZONE
TZID:Europe/Berlin
BEGIN:STANDARD
DTSTART:19710101T030000
TZOFFSETTO:+0100
TZOFFSETFROM:+0200
RRULE:FREQ=YEARLY;WKST=MO;INTERVAL=1;BYMONTH=10;BYDAY=-1SU
TZNAME:CET
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
RRULE:FREQ=DAILY;COUNT=3;INTERVAL=1
SUMMARY:Day Event 3 Times
DTSTART;VALUE=DATE:20120911
DTEND;VALUE=DATE:20120912
END:VEVENT
BEGIN:VEVENT
SUMMARY:4 hours event
DTSTART;TZID="Europe/Berlin":20120911T090000
DTEND;TZID="Europe/Berlin":20120911T130000
END:VEVENT
END:VCALENDAR
Now i have written some lines of code to filter the events:
public class CalendarTester {
private Calendar calendar;
private TimeZoneRegistry registry;
public static void main(String[] args) throws Exception {
CalendarTester tester = new CalendarTester();
tester.run();
}
private void run() throws IOException, ParserException, URISyntaxException,
ParseException {
readCalendar();
TimeZone tz = registry.getTimeZone("Europe/Berlin");
SimpleDateFormat formatter = new SimpleDateFormat();
GregorianCalendar cal = new GregorianCalendar(2012,
GregorianCalendar.SEPTEMBER, 10);
cal.set(GregorianCalendar.HOUR_OF_DAY, 0);
cal.set(GregorianCalendar.MINUTE, 0);
cal.set(GregorianCalendar.SECOND, 0);
cal.setTimeZone(tz);
for (int i = 0; i < 5; i++) {
Period p = new Period(new DateTime(cal.getTime()), new Dur(1, 0, 0,
0));
p.setTimeZone(tz);
Rule[] rules = new Rule[1];
rules[0] = new PeriodRule(p);
Filter f = new Filter(rules, Filter.MATCH_ALL);
System.out.println("_____________");
System.out.println(formatter.format(cal.getTime()));
for (Object event : f.filter(calendar
.getComponents(Component.VEVENT))) {
printEvent((VEvent) event, formatter);
}
cal.add(GregorianCalendar.DAY_OF_YEAR, 1);
}
}
private void printEvent(VEvent event, SimpleDateFormat formatter) {
System.out.println("Start: "
+ formatter.format(event.getStartDate().getDate()) + " End: "
+ formatter.format(event.getEndDate().getDate()) + " Summary: "
+ event.getSummary().getValue());
}
private void readCalendar() throws FileNotFoundException, IOException,
ParserException {
FileInputStream fin = new FileInputStream(
"files/Recuring_Calendar_Entry_From_To.ics");
CalendarBuilder builder = new CalendarBuilder();
calendar = builder.build(fin);
registry = builder.getRegistry();
}
}
Now i get the Simple event correctly but the 3 time occuring one day event 4 times, because of the wrong start and end times.
_____________
10.09.12 01:00
_____________
11.09.12 01:00
Start: 11.09.12 02:00 End: 12.09.12 02:00 Summary: Day Event 3 Times
Start: 11.09.12 10:00 End: 11.09.12 14:00 Summary: 4 hours event
_____________
12.09.12 01:00
Start: 11.09.12 02:00 End: 12.09.12 02:00 Summary: Day Event 3 Times
_____________
13.09.12 01:00
Start: 11.09.12 02:00 End: 12.09.12 02:00 Summary: Day Event 3 Times
_____________
14.09.12 01:00
Start: 11.09.12 02:00 End: 12.09.12 02:00 Summary: Day Event 3 Times
So if anyone has an idea what i have to change at the import or at the filter, that i get all events in the same timezone.
Tanks for any suggestions, Cy
I did some tests to figure out what is going on. The start was the Tests for the filters in:
test/net/fortuna/ical4j/filter/PeriodRuleTest.java
If i create a new all day event like it is shown there everything is ok.
If i add a recure roule the functionality is broken.
Recur recur = new Recur("FREQ=DAILY;COUNT=3;INTERVAL=1");
event.getProperties().add(new RRule(recur));
Now the Event matches for the starting date and on the following 3 days as it is shown in the sample above.
If I set the COUNT=1 in the rule the event now matches 2 times. Maybe I do not understand the recurring rule? If I take a look at the web calendar (Zimbra) where I exported this events everything is like i expected.
Here you can see my test class
I noticed a couple of things:
The first thing is that your "Day Event 3 Times" event is not using the Europe/Berlin timezone for its dates, so the event is effectively in "floating time". This may not matter if your local timezone is Europe/Berlin tho.
Second, the same event spans 11 Sep - 12 Sep. So with the recurrence rule you will end up with three event instances:
11 Sep - 12 Sep
12 Sep - 13 Sep
13 Sep - 14 Sep
I didn't look too closely at what the code is doing, but that might explain why you are getting matches on 14 sep.
I currently have a list of DateTimes stored as the timezone's UTC datetime. When I go to convert from UTC to local datetime and when the date falls on the start of Daylight Standard time, the hour that repeats is 1am and not 2am.
I use the following to convert from UTC to local time. Notice that 1am repeats in local1 and local2. I expected 2am to repeat.
Which is correct?
TimeZoneInfo tz = TimeZoneInfo.FindSystemTimeZoneById("Mountain Standard Time");
//UTC time
var utc1 = new DateTime(1990, 10, 28, 7, 0, 0); //This is start of daylight standard time.
var utc2 = new DateTime(1990, 10, 28, 8, 0, 0);
var utc3 = new DateTime(1990, 10, 28, 9, 0, 0);
utc1 = DateTime.SpecifyKind(utc1, DateTimeKind.Utc);
utc2 = DateTime.SpecifyKind(utc2, DateTimeKind.Utc);
utc3 = DateTime.SpecifyKind(utc3, DateTimeKind.Utc);
//Get the local time with adjustment for Daylight standard time, "fall back"
var local1 = TimeZoneInfo.ConvertTimeFromUtc(utc1, tz); //Returns 1am
var local2 = TimeZoneInfo.ConvertTimeFromUtc(utc2, tz); //Returns 1am. Should this be 2am?
var local3 = TimeZoneInfo.ConvertTimeFromUtc(utc3, tz); //Returns 2am
At 2am you "fall back" to 1am (1:59 -> 1), hence 1am is repeated and 2am only occurs one hour later. similarly when you "spring forward" there would be NO 2 AM (1:59 -> 3)
source: http://aa.usno.navy.mil/faq/docs/daylight_time.php (US Naval Observatory keeps the US DoD official time (source for that: http://www.usno.navy.mil/USNO/time))