|
SageTV Studio Discussion related to the SageTV Studio application produced by SageTV. Questions, issues, problems, suggestions, etc. relating to the Studio software application should be posted here. |
|
Thread Tools | Search this Thread | Display Modes |
#1
|
||||
|
||||
Is Java Calendar Broken??
I have a weird issue with the Java calendar... and I've tested this on 2 different JVMs...
Here the test code Code:
public void testCalendar() { for (int i=0;i<24;i++) { Calendar c = Calendar.getInstance(); c.set(Calendar.HOUR_OF_DAY, i); c.getTime(); // force field updates if (c.get(Calendar.HOUR_OF_DAY)!=i) { System.out.println("Calednar Broken for: " + i); } else { System.out.println("Calendar Pass: " + i); } } } My results are... Code:
Calendar Pass: 0 Calendar Pass: 1 Calednar Broken for: 2 Calendar Pass: 3 Calendar Pass: 4 Calendar Pass: 5 Calendar Pass: 6 Calendar Pass: 7 Calendar Pass: 8 Calendar Pass: 9 Calendar Pass: 10 Calendar Pass: 11 Calendar Pass: 12 Calendar Pass: 13 Calendar Pass: 14 Calendar Pass: 15 Calendar Pass: 16 Calendar Pass: 17 Calendar Pass: 18 Calendar Pass: 19 Calendar Pass: 20 Calendar Pass: 21 Calendar Pass: 22 Calendar Pass: 23 If I call c.clear() before setting the HOUR of the DAY, then I get the expected results, but that defeats the purpose, since I lose the date. If create a calendar by setting all the date/time fields, it's broken again. Can anyone confirm if the code snippet that I posted works/fails on their system?? I tried searching for bugs about this, but nothing this specific (although most people agree, the java calendar sucks). In order to work around this... I have to do the following... Code:
Calendar now = Calendar.getInstance(); // it's deprecated, but Calendar appeared broken, when seting HOUR_OF_DAY with a value of 2??? Date d = new Date(now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH), hr, minute, 0); return d.getTime();
__________________
Batch Metadata Tools (User Guides) - SageTV App (Android) - SageTV Plex Channel - My Other Android Apps - sagex-api wrappers - Google+ - Phoenix Renamer Downloads SageTV V9 | Android MiniClient |
#2
|
|||
|
|||
You run that test code today and there will be no hour 2 because of daylight savings time. You run that tomorrow and I assume it'll work as expected.
__________________
Twitter: @ddb_db Server: Intel i5-4570 Quad Core, 16GB RAM, 1 x 128GB OS SSD (Win7 Pro x64 SP1), 1 x 2TB media drive Capture: 2 x Colossus STB Controller: 1 x USB-UIRT Software:Java 1.7.0_71; SageTV 7.1.9 Clients: 1 x HD300, 2 x HD200, 1 x SageClient, 1 x PlaceShifter Plugins: Too many to list now... |
#3
|
|||
|
|||
Quickly ported your code to a Groovy script and ran it in my JVM (1.6.0_24) and it fails for today, but succeeds for tomorrow (as expected). Your only problem is you picked one of the two bad days a year to muck around with date/calendar code. And I suspect you probably wasted a lot of time looking at your code today!
Code:
def testCal(Date d) { println "Testing for $d..."; for (int i=0;i<24;i++) { Calendar c = Calendar.getInstance(); c.setTime(d); c.set(Calendar.HOUR_OF_DAY, i); c.getTime(); // force field updates if (c.get(Calendar.HOUR_OF_DAY)!=i) { System.out.println("Calednar Broken for: " + i); } else { System.out.println("Calendar Pass: " + i); } } println "===" } testCal(new Date(2011 - 1900, 2, 13)); // Sun, Mar 13; start of daylight savings in North America testCal(new Date(2011 - 1900, 2, 14)); // Mon, Mar 14; hour 2 should now exist Code:
Testing for Sun Mar 13 00:00:00 EST 2011... Calendar Pass: 0 Calendar Pass: 1 Calednar Broken for: 2 Calendar Pass: 3 Calendar Pass: 4 Calendar Pass: 5 Calendar Pass: 6 Calendar Pass: 7 Calendar Pass: 8 Calendar Pass: 9 Calendar Pass: 10 Calendar Pass: 11 Calendar Pass: 12 Calendar Pass: 13 Calendar Pass: 14 Calendar Pass: 15 Calendar Pass: 16 Calendar Pass: 17 Calendar Pass: 18 Calendar Pass: 19 Calendar Pass: 20 Calendar Pass: 21 Calendar Pass: 22 Calendar Pass: 23 === Testing for Mon Mar 14 00:00:00 EDT 2011... Calendar Pass: 0 Calendar Pass: 1 Calendar Pass: 2 Calendar Pass: 3 Calendar Pass: 4 Calendar Pass: 5 Calendar Pass: 6 Calendar Pass: 7 Calendar Pass: 8 Calendar Pass: 9 Calendar Pass: 10 Calendar Pass: 11 Calendar Pass: 12 Calendar Pass: 13 Calendar Pass: 14 Calendar Pass: 15 Calendar Pass: 16 Calendar Pass: 17 Calendar Pass: 18 Calendar Pass: 19 Calendar Pass: 20 Calendar Pass: 21 Calendar Pass: 22 Calendar Pass: 23 ===
__________________
Twitter: @ddb_db Server: Intel i5-4570 Quad Core, 16GB RAM, 1 x 128GB OS SSD (Win7 Pro x64 SP1), 1 x 2TB media drive Capture: 2 x Colossus STB Controller: 1 x USB-UIRT Software:Java 1.7.0_71; SageTV 7.1.9 Clients: 1 x HD300, 2 x HD200, 1 x SageClient, 1 x PlaceShifter Plugins: Too many to list now... |
#4
|
||||
|
||||
You're right... I picked a bad day to play with the calendar object
So actually it's not broken, it's doing the correct thing, just that for today... there is no hour 2... damn... If I had just randomly picked a couple of other other hours for my junit test, I would have been so much further ahead
__________________
Batch Metadata Tools (User Guides) - SageTV App (Android) - SageTV Plex Channel - My Other Android Apps - sagex-api wrappers - Google+ - Phoenix Renamer Downloads SageTV V9 | Android MiniClient |
#5
|
||||
|
||||
I'm sorry, but that's hilarious.
__________________
"Everything doesn't exist. I'm thirsty." ...later... "No, it's real!!! I'm full." - Nikolaus (4yrs old) |
#6
|
|||
|
|||
|
#7
|
||||
|
||||
I had a laugh last night when I read this but I refrained from posting because I can imagine just how frustrated Sean must have been.
__________________
Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders. |
#8
|
||||
|
||||
It was real funny... not
Fortunately, I didn't wast too much time (but enough, none the less), on it. When it wasn't working I decided to post about it because it was baffling how hour 2 would just die... The sad thing is that it never occurred to me that i was dst related
__________________
Batch Metadata Tools (User Guides) - SageTV App (Android) - SageTV Plex Channel - My Other Android Apps - sagex-api wrappers - Google+ - Phoenix Renamer Downloads SageTV V9 | Android MiniClient |
#9
|
|||
|
|||
Well, we are all really glad you posted it. Because now none of us, especially you, will ever forget
__________________
Gigabyte GA-MA770-DS3/4gb DDR2/AMD Phenom 955 3.2ghz Quad Core Windows 7 64bit Home Premium Hauppauge 1600/1850/2250/colossus/2650(CableCard 2 tuner) 8tb RAID5 storage/media/other &3tb RAID5 backup storage on a HighPoint RocketRaid 2680 1tb 3 disk Recording Pool all in a beautiful Antec 1200 SageMyMovies/Comskip/PlayON/SageDCT/SRE HD100/HD300 extenders |
#10
|
||||
|
||||
This was pretty funny.
__________________
Jeffrey Kardatzke Founder of SageTV |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
STV Import: Google Calendar for SageMC (v0.4 / May 24, 2007) | MeInMaui | SageMC Custom Interface | 208 | 01-18-2010 01:59 PM |
Google Calendar | rosemary | SageTV Customizations | 3 | 09-02-2009 01:52 PM |
Google Calendar | sam.griffin.bht | SageTV Customizations | 2 | 06-05-2009 10:39 AM |
Big problem with Google Calendar STV import!! | mrshanes | SageMC Custom Interface | 6 | 03-26-2008 05:57 AM |
Broken Server Java Version | Steve52 | SageTV Software | 5 | 03-14-2007 04:40 PM |