The Source for Java Technology Collaboration
User: Password:



Felipe Gaucho

Felipe Gaucho's Blog

let's do it again, using GregorianCalendar

Posted by felipegaucho on January 11, 2006 at 07:36 AM | Comments (7)

Few days ago I was listening a client about the framework his company was producing for a long time. Tips about the workflow, security and several other common features of a framework. A special feature gave me a déjà vu: the control of holidays in the financial modules. Every financial calculus is based on working days and every framework I've ever seen in my life had also a module for the calculation of workdays range - subtracting holidays, sundays, etc.

These modules are so identical that I've started to think about the need to include that feature in the java.util.GregorianCalendar or some other implementation of the Calendar Interface.

I know APIs should avoid features from specific applications, such as it was well explained in a recent entry of the Eamonn McManus blog. But this special algorithm - the calculus of workdays within a time interval - is so common that I think it should be included as a generic feature in a next review of the class GregorianCalendar.

Everyone who already implemented such feature knows about its functionality: you store a list of holidays, and the Calendar identify the Sundays for you. The algorithm consists in comparing each day of the time interval with the days from that holidays list. Quite simple, but quite repetitive for all system implementation.

One can argue that companies can implement it just once and reuse the algorithm in the new systems. I agree with that, but I also think such obvious algorithm should be part of the Java API as a facility.

I was thinking about a Java Specification Request or just suggest this new feature to the JDK community, but I prefer to listen you first. I'm not sure if there is something already supported by the API (I didn´t find any reference about that) and I also prefer to discuss its utility with you before to go into the formal aspects of a specification request - a sanity check :).


Bookmark blog post: del.icio.us del.icio.us Digg Digg DZone DZone Furl Furl Reddit Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment

  • Maybe joda time does it?
    http://joda-time.sourceforge.net/

    Posted by: ge0ffrey on January 12, 2006 at 12:00 AM

  • Hum, maybe your own implementation of Calendar class or utility methods? It is really a cool feature but I haven't see it as default in other languages. As you say, "APIs should avoid features from specific applications" to avoid feature overkill and keep themselves simple.

    valeuz...

    Posted by: jackganzha on January 12, 2006 at 04:52 AM

  • Hi,
    I am the project lead on Joda-Time - http://joda-time.sourceforge.net/

    If you are interested in this area, please contact me. We already have two or three source donations in the area of holidays, and I'm ideally looking for someone to assist in combining these to form a proper API. (http://cvs.sourceforge.net/viewcvs.py/joda-time/JodaTimeContrib/holiday/)

    I strongly believe (having done it with Joda-Time) that fleshing out your ideas in open-source first is a good idea before trying to jump into a JSR.

    Stephen
    Email link on the website


    Hi Stephen,

    thank you very much for your offer, but I´m focused on other projects. BTW: I visited your project - Fantastic, the first implementation of that strange calendars (Buddhist?, Ethiopic?) I've ever seen in the Java community - congratulations!

    About the position, I can´t assume it now - your project really deserves observation and I'm sure you will find someone very soon ..

    best regards,


    Felipe Gaúcho

    Posted by: scolebourne on January 12, 2006 at 05:00 AM

  • Oh, PLEASE.
    Why can't people ever get over the attitude that everything and the kitchen sink should be part of the core language?

    :))) the nowadays dilema: inflate the API or accept hundred of third part libraries in the projects ? When we detect a repetitive feature, seems natural to argue about it inclusion into the API. The Java API is not a sacred stuff - it is a specification that can evolve in the future, and our discussions will guarantee its improvements.

    Posted by: jwenting on January 12, 2006 at 11:21 PM

  • Everyone who already implemented such feature knows about its functionality: you store a list of holidays


    This is the problem (I work for an investment bank and had to deal with this at one point). Holidays change and some are not set until a short time before they actually occur, I seem to recall that some Hindu holidays weren't finalised until the astrologers said so just six months before the actual holiday.


    Another problem is deciding whether to use bank holidays or market holidays, in the US and Europe they pretty much coincide but not necessarily in the rest of the work.


    And finally, how would you choose which holiday list to use? You can't use Locale as places like New Zealand have different holidays depending on which part of the country you are in, Auckland and Wellington have a different day off in January.

    In the end we license 30 years of holiday information from a third party vendor Financial Calendar, they send us corrections about three times a week, this information cannot be kep up to date with just JVM releases.


    Regards

    Chris.

    Hi Chris,

    of course each country has its own set of holidays. My suggestion rely on an algorithm to deal with the holidays during calculations and not the holiday list itself. Per example, imagine such situation: a company where the employees works five days a week, and you must to calculate how many working days will be within the interval march, 1 to march, 20. Of course, if you want to know how many days people worked during this period, you want to disconsider Sundays, Saturdays and the holidays.

    // holidays im March: 5, 13
    List holidays = new ArrayList();
    holidays.add(new GregorianCalendar(year, Calendar.MARCH, 5).getTime());
    holidays.add(new GregorianCalendar(year, Calendar.MARCH, 13).getTime());

    Calendar calendar = new GregorianCalendar(2006, 3, 1);
    calendar.ignoreDate(Calendar.Sunday);
    calendar.ignoreDate(Calendar.Saturday);
    calendar.setHolidays(holidays);
    int howManyWorkingDays = calendar.difference(Calendar.DATE, new GregorianCalendar(2006, 3, 20));


    Note several of the above command are pure suggestions, they really doesn´t exists. The generic implementation of methods like ignoreDate, setHolidays and difference could help a lot of developers around the world... just a guess.

    Felipe Gaúcho

    Posted by: gressil on January 13, 2006 at 12:36 PM

  • The subject of a very wonderful and distinct
    I thank you for continuing excellence
    Thank you

    =========================================================================

    ليبيا
    شباب ليبيا
    libya
    منتديات
    منتديات ليبية
    غرائب وحقائق
    أحاديث شريفة
    برامج اسلامية للجوال
    مفاتيح الديجيتل
    الشيرنج
    الرسيفرات
    كتب إسلامية
    خلفيات للموبيل
    الشعر الشعبي
    الصحة والطب
    طب اسنان
    كتب طب اسنان مجانية
    برامج طبية
    تعلم الإنكليزية
    اللغة الفرنسية
    طب الإعشاب
    الخواطرالادبية
    الازياء والمكياج
    تعليم الطبخ
    الاثاث الحديث
    مقاطع كرة قدم
    المصارعه الحرة
    اهداف كوره
    الفوتوشوب
    اروع البرامج
    الدوري الليبي
    خلفيات رياضية
    المصارعة
    كورة عربية
    كرة قدم عالمية
    الدوري الإيطالي
    الدوري الاسباني
    الدوري الإنجليزي
    صور المشاهير
    انواع الحلويات
    افلام كوميدية
    احدث الافلام
    افلام
    التقنية
    تحميل افلام
    برامج
    اخر برامج الجوال
    kaspersky
    أفلام كرتون عربية
    برامج برامج كمبيوتر
    برامج حماية
    برامج اختراق
    برامج صوت
    برامج تحميل برامج احدث البرامج
    محادثة
    خلفيات الطبيعة
    برامج مبايل للتحميل
    اخبار الفن
    احدث الافلام للتحميل
    تحميل افلام رعب
    ترجمةأفلام
    الكامات
    برامج جوال
    برامج محاسبة
    برامج
    kasper
    games
    برامج
    برامج
    انترنت
    برامج صوتية
    شبكات الحاسوب
    خلفيات للويندوز
    تطويرالمواقع
    العاب
    العاب الفيديو
    games
    شفرات
    برامج مسنجر
    خلفيات شاشة
    صور ترحيبيه
    الفوتوشوب
    خلفيات طبيعة
    تطويرالمواقع
    الفوتوشوب
    مقاطع البلوتوت
    مسجات ليبية
    خلفيات
    الفلاش
    التصميم الثلاثي
    برامج الجوال
    العاب الجوال
    فيديو كليب
    مسجات
    ترددات ستالايت
    نغمات

    Posted by: libyan on May 30, 2008 at 03:25 PM

  • Thanks so much for this! This is exactly what I was looking for.
    ///////////////////////////FLV to AVI converterFLV to WMV
    FLV to MPEG
    FLV Converter
    SWF to FLV
    M4V converter
    Ipod to PC
    Ipod to PC transfer
    DVD to iPod AVI to SWF site has all solution on FLV to SWF,
    WMV to SWF, MPEG to SWF,
    3GP to SWF, DivX to SWF,AVI to FLV
    and other video to SWF, FLV ecoded by Java.
    May it Gadgets helpful To your lifestyle... Enjoy!

    Posted by: quinceseed on June 19, 2008 at 08:15 PM



Only logged in users may post comments. Login Here.


Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds