SageTV Community  

Go Back   SageTV Community > SageTV Development and Customizations > SageTV Studio
Forum Rules FAQs Community Downloads Today's Posts Search

Notices

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.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-13-2011, 05:04 PM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,713
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);
			}
		}
	}
All it does is set the HOUR of the DAY to a value, and tests if that is in fact the value in the calendar.

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
This is very odd, since it would appear that it works for all cases, except 2.

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();
All this because I just wanted to create a Date for a specific time of day
Reply With Quote
  #2  
Old 03-13-2011, 06:31 PM
Slugger Slugger is offline
SageTVaholic
 
Join Date: Mar 2007
Location: Kingston, ON
Posts: 4,008
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...
Reply With Quote
  #3  
Old 03-13-2011, 06:44 PM
Slugger Slugger is offline
SageTVaholic
 
Join Date: Mar 2007
Location: Kingston, ON
Posts: 4,008
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...
Reply With Quote
  #4  
Old 03-13-2011, 06:50 PM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,713
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
Reply With Quote
  #5  
Old 03-13-2011, 07:12 PM
MeInMaui's Avatar
MeInMaui MeInMaui is offline
SageTVaholic
 
Join Date: Feb 2005
Location: Maui. HI
Posts: 4,203
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)
Reply With Quote
  #6  
Old 03-13-2011, 08:18 PM
PLUCKYHD PLUCKYHD is offline
SageTVaholic
 
Join Date: Dec 2007
Posts: 6,257
Reply With Quote
  #7  
Old 03-14-2011, 07:00 AM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
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.
Reply With Quote
  #8  
Old 03-14-2011, 07:46 AM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,713
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
Reply With Quote
  #9  
Old 03-14-2011, 01:03 PM
jptheripper jptheripper is offline
Sage Fanatic
 
Join Date: Dec 2007
Location: Florida
Posts: 956
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
Reply With Quote
  #10  
Old 03-17-2011, 06:29 PM
Narflex's Avatar
Narflex Narflex is offline
Sage
 
Join Date: Feb 2003
Location: Redondo Beach, CA
Posts: 6,349
This was pretty funny.
__________________
Jeffrey Kardatzke
Google
Founder of SageTV
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

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


All times are GMT -6. The time now is 06:04 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2023, vBulletin Solutions Inc.
Copyright 2003-2005 SageTV, LLC. All rights reserved.