Calculate number of days between two days in Jira

Jira can be a perfect tool for managing any type of projects. However, out of the box, Jira doesn’t have a start date and end date fields and if you created these two fields as custom one you can’t link them directly to the time tracking functionality without a custom script.

I did some research and I found ScriptRunner for Jira App (add-on) from adaptavist. By using this app you can write your own custom script using groovy and run it to extend the functionalities of Jira.

I created a script to calculate the estimated days between two fields (Start date and End date) and it will update Jira time tracking fields (Estimated and Remaining). Also the script will take into consideration the previously logged time in the calculations.

You have to enable time tracking in Jira, create these two fields, install the app and add the script to Behavior from Administration menu on the End date field.

import java.text.DateFormat;
import java.util.Calendar;
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.properties.ApplicationProperties
import com.atlassian.jira.util.JiraDurationUtils

JiraDurationUtils jiraDurationUtils = ComponentAccessor.getComponent(JiraDurationUtils.class)
ApplicationProperties applicationProperties = ComponentAccessor.getApplicationProperties()

// Get a pointer to my custom fields
def startDateField = getFieldByName("Start date")
def endDateField = getFieldByName("End date")
def originalEstimateField = getFieldById("timetracking_originalestimate")
def remainingEstimateField = getFieldById("timetracking_remainingestimate")


// Get the Values of My Date Fields
def startDateFieldVal = startDateField.getValue() as Date
def endDateFieldVal = endDateField.getValue() as Date

def value = (originalEstimateField.getValue()) as String
def remvalue = (remainingEstimateField.getValue()) as String

// Specify a variable used for storing the number of weekdays between two dates
int ellapsedTime;

// Check if End Date contains a valid value
if (endDateFieldVal) {

    // Calculate the number of weekdays between the start and end date below
    Calendar cal1 = Calendar.getInstance();
    Calendar cal2 = Calendar.getInstance();
    cal1.setTime(startDateFieldVal);
    cal2.setTime(endDateFieldVal != null ? endDateFieldVal : startDateFieldVal);

    if (cal2.before(cal1)) {
        // Don't attempt to calculate days if end date is before the start date
        return 0;
    }

    while (cal1.before(cal2)) {
        // If the days include weekends skip those days and do not count them
        if ((Calendar.SATURDAY != cal1.get(Calendar.DAY_OF_WEEK))
        && (Calendar.SUNDAY != cal1.get(Calendar.DAY_OF_WEEK))) {
            ellapsedTime++;
        }
        cal1.add(Calendar.DATE, 1);
    }

    // End of code block for calculating the number of weekdays

    // Work out the long value by multiplying the number of days against the number of hours in our work day
    // that we have configured inside JIRA e.g 4 * 480 = L1920 which represents 4 days 
    long updatedEstimatedDays = ellapsedTime * 480 + 480 as Long // Plus 480 to add on the day that the current day that the date calculation chops off.
    
    long longoriginalEstimateField = jiraDurationUtils.parseDuration(value, applicationProperties.getDefaultLocale()) / 3600  as Long
    long longremainingEstimateField = jiraDurationUtils.parseDuration(remvalue, applicationProperties.getDefaultLocale()) / 3600 as Long
    
    long originalEstimatedDays = longoriginalEstimateField ? longoriginalEstimateField : 0
    long originalRemainingDays = longremainingEstimateField ? longremainingEstimateField : 0
    long diffInDays = updatedEstimatedDays - originalEstimatedDays

    if(diffInDays >= 0 ) {
        originalEstimateField.setFormValue(updatedEstimatedDays)
        remainingEstimateField.setFormValue(originalRemainingDays + diffInDays)
    }
}

Firefox & Me – Episode 1: Before I met you…

It was end of 90s when the whole Internet was orbiting around Internet Explorer, people started to forget what is Internet. There were not too many choices left. Internet is becoming Internet Explorer. My first love is now in the ICU for a long time, many tried to revive it but all the vital signs are showing that the end is getting soon and saving it is beyond anyone. I have to deal with the fact that Netscape is dying and it is taking its last breathe. I am still refusing to go out with Internet Explorer, simply because I don’t want to see the virtual world only from its own eyes. I want to shape my own world and control it by myself. I started to look for alternatives, I went out with opera couple of times, it was pretty, flexible has lots of characteristics that attracted me. But it was too complicated to deal with, many things that always made me confused. After struggling few times, we decided to break up. I tried to go out with other browsers but most of them they had the same personality of Internet explorer but they were having different dress and make up. I was looking for the one that will win my heart and the one that I should give my support. The one that I will be proud of when others see us together.
To be continue …

فيرفكس بين الإصدارات السريعة والشركات

قرار موزيلا الاخير بالتوجه نحو الاصدارات السريعة من فيرفكس أدى لخلق عدة مشاكل للشركات التي اعتمدت فيرفكس كمتصفحها الرئيسي، فسرعة اصدار نسخة جديدة مرة كل ٦ اسابيع قام بإرباك الشركات التي سوف يتطلب منها مجهود إضافي لفحص توافق تطبيقاتها مع الإصدارات الجديدة وكذلك تحميل النسخ الجديدة على أجهزة المستخدمين. ولأن موزيلا هدفها الأول هو إيصال أحدث التكنولوجيا لكافة المستخدمين والإستماع لشكواهم قامت موزيلا بتشكيل مجموعة بحث خاصة للشركات حيث قامت بتوجيه دعوة مفتوحة لجميع الشركات والمهتمين للمشاركة في هذه المجموعة وتم إنشاء مجموعة تتكون من موظفين من موزيلا  و ممثيلين عن الشركات المهتمه ومتطوعين مهتمين بهذا المجال وذلك للتوصل لأرضية مشتركة بين موزيلا والشركات، وخلال شهرين من المباحثات واللقاءات تم التوصل الى اقتراح يقوم بارضاء جميع الاطراف وهي نسخة من فيرفكس بدعم مطول للشركات حيث ستوفر موزيلا دعم لهذا الاصدار وتحديث لفترة ٧ اصدارات متتالية اي ٤٢ اسبوع. وخلال هذه الفترة ستوفر موزيلا تحديثات لهذه النسخ اذا وجد فيها مشاكل متعلقة بالأمن على الانترنت. ولن تقوم موزيلا بالإعلان عن هذه النسخة من خلال صفحتها الرئيسية ولكن فقط من خلال صفحتها المتعلقة بالشركات وسوف يتم تسميتها بإسم آخر بالإضافة لفيرفكس Firefox ESR لكي يتم تميزها عن نسخة فيرفكس الإعتيادية. وبعد إنتهاء مدة ٤٢ اسبوع او ٧ اصدارات من فيرفكس ستقوم موزيلا بتحديث نسخة الدعم المطول تلقائيا. وهذه النسخ ستعمل على ويندوز وماك ولينكس ولن تشمل نسخة فيرفكس الجوال. الرسمة التالية هي لتوضيح الفرق بين نسخة فيرفكس ونسخة فيرفكس بالدعم المطول Firefox ESR

وبناءا على الرسم السابق فإن عملية فحص نسخ فيرفكس ذو الدعم المطول ستتم قبل الاصدار ب ١٢ اسبوعا لكي تعطي الشركات فرصة اكبر للتأكد من توافق التطبيقات مع النسخة الجديدة وأيضا سيتم إعطاء ١٢ اسبوع آخر لعملية التحميل للنسخ الجديدة والتحول إليها. إذا كنت أحد المهتمين بهذه الاصدارات من فيرفكس قم بالإنضمام للمجموعة الشركات وشارك فيها وأسمع صوتك لموزيلا.

موزيلا وأنا – البدايات

مع بدايات القرن 21 وأفول نجم المتصفح العزيز عليّ نيتسكيب وسيطرت ميكروسوفت على سوق المتصفحات بدأت بالبحث عن بديل اخر أو كما أحب دائما أن أوصفه بالمنطقة المحايدة التي تبعدني عن جشع وتحكم الشركات. فكانت اول تجربة لي مع المتصفح موزيلا 1.0 الذي تم بناءه من نيتسكيب وكان يحتوي على بريد الكتروني وبرنامج تحرير لصفحات الوب وبرنامج محادثه، كان شبيه لدرجة كبيرة بنتيسكيب ولكن مع الفرق بالإسم. كان ذلك في بدايات 2002 وما إن اقترب عام 2002 من نهايته قرأت خبر عن بدء العمل على تطوير متصفح جديد سوف يقوم بعمل نقله نوعية في عالم المتصفحات وكان اسمه فينكس (نسبة إلى الطائر الاسطوري الذي يولد من الرماد) انا من اشد المعجبين بهذا الطائر الاسطورة لذلك كنت احب هذا الاسم 🙂 فقمت بتحميل النسخة 0.2 وكانت بدائية ولكن المتصفح كان سريع ويختلف عن الانترنت اكسبلورر ومع اصدار النسخة 0.4 وإدخال الألسنه على المتصفح زاد إرتباطي به وأصبح المتصفح الأول على جهازي. وبدأت ايضا بمتابعة ميتشيل بيكر (كانت في ذلك الوقت المديرة التنفيذبة لموزبلا) وقراءت لقائتها في المجالات وعلى مواقع الانترنت. ومع إصدار النسخة 0.6 ومع مشاكل في الحقوق الملكية الفكرية تم تغير الاسم لفيربرد بدل فينيكس، بدأ المتطوعين بإصدار المتصفح بعدة لغات فقررت البدء بتعريب واجهة الاستخدام فقمت بمراسلة موزيلا وهناك بدأت الصعوبات بمحاولتي ليس فقط التعريب ولكن قلب الواجهة بالكامل من اليسار إلى اليمين وبعدة محاولات وبمساعدة مطورين موزيلا نجحنا بإصدار أول نسخة معربة من فيربيرد ومع إقتراب الموعد النهائي لإصدار المتصفح تم تغير الإسم للمرة الأخيرة مع الشعار إلى فيرفكس وتم إصدار النسخة المعربة مع النسخة الإنجليزية كان انجاز بالنسبة لي لا يوجد عندي أي إحصائية بعدد تحميل النسخة المعربة للمتصفح في ذلك الوقت – ربما كنت الوحيد الذي قمت بتحميلها – ولكن بالنسبة لي كان إنجاز بتقديم خيار آخر للمستخدم ودعم لحضور اللغة العربية ولو كان بشكل بسيط على الوب. بالمناسبة مازلت احتفظ بأول قميص لفيرفكس 1.0 وأول دمية لفيرفكس 🙂 لما تحمل لي من معاني ودائما تذكرني بالبدايات…

موزيلا وأنا

قررت أن أقوم بكاتبة عدة مقالات أتحدث فيها عن موزيلا من جوانب عدّة ليس فقط كمؤسسة تقوم باصدار المتصفح فيرفكس ولكن كمؤسسة لها رسالة واهداف اكبر من مجرد اصدار متصفح. وهذه الأفكار تشكلت من تجربتي الشخصية في العمل التطوعي مع موزيلا لمدة 10 سنوات تقريبا.وهي وجهة نظر شخصية أعبر فيها عن رأيي الشخصي وكيف أرى موزيلا ولماذا أقوم بدعمها والحديث عنها وكيف كان لها تأثير على عدة جوانب من حياتي المهنية والشخصية. فإذا كنت من المهتمين بموزيلا قم بزيارة الموقع مرّة أخرى قريبا….

موزيلا و نظام تشغيل، لماذا؟

قبل عدة ايام اعلنت موزيلا عن مشروع جديد باسم B2G وهو عبارة عن نظام تشغيل للاجهزة الخلوية واللوحية، الكل بدأ بالتحدث عن هذا المشروع كأن موزيلا ستدخل المنافسة في تطوير نظام تشغيل جنبا الى جنب مع مايكروسوفت وجوجل وابل. ولكن برأي الشخصي لدي وجهة نظر اخرى وقراءة مختلفه للخبر. فموزيلا لا تفكر الدخول في سباق التطوير لانظمة تشغيل لانه ليس مجالها. موزيلا منذ بداية تأسيسها وهي تحاول ان تعرف المستخدم بخياراته ووضعها بين يديه. فكانت البداية مع فيرفكس كمتصفح يحمل هذه الافكار بتعريف المستخدم بوجود البديل وان الخيار بيده وانه هو صاحب القرار في اختياراته.

ثم قامت بموزيلا باصدار ثندربيرد برنامج البريد الالكتروني بنفس الاهداف. وقبل سنه تقريبا شعرت موزيلا بان الوب مستهدفه مرة اخرى وفي خطر من الشركات التي تقوم باصدار برامج للاجهزة الخلوية فاطلقت مشروع التطبيقات المفتوحة الذي قام بوضع مثال كيف يجب ان تكون الطريقة المثلى لتطوير هذه التطبيقات وكيفه توزيعها عن طريق متاجر التطبيقات.

والان موزيلا تقدم مبادرة اخرى في برامج التشغيل، هناك فرق كبير وواضح بين مبادرة موزيلا وبرنامج التشغيل من جوجل. حيث برنامج التشغيل من جوجل وتطبيقاته تعمل على متصفح كروم ولكن تطبيقات موزيلا تعمل على الوب وليس على فيرفكس ويمكنها انت تعمل على اي جهاز يستطيع الوصول الى الانترنت.

في جميع برامجها او مبادرتها، تحاول موزيلا بتوعية المستخدم بأن الخيار بيده وان الوب ملكه فلا يجوز لاحد ان يسيطر عليها او يتحكم بها ويجعلها حكرا له.

Mozilla Boot to Gecko (B2G), Why?!!!


Everyone on my twitter or Facebook or even at my office were sharing with me the news about Mozilla B2G (Mozilla Boot to Gecko), even few friends they told me Mozilla is copying Google with their Chrome OS.

But For me the news was not a big surprise may be because I read it in different way and I know it’s still fall under Mozilla mission. What I believe Mozilla is not trying here to be a player in the OS area because it’s not their area but as usual they trying to show the users their options and to build a model for a modern open Mobile/Tablet OS that everyone can benefit from it.

When Mozilla start working on the Web App project (An app can be run on any device, any browser, distributed from any app store or even from developer store), it was to give the developer an example how the Apps should be, open not a closed manipulated by companies, not centralized and everyone must follow their rules or you will be kicked out, you sit your own rules by yourself and you take the control of your efforts and investments.

Imagine if you are a developer and building an apps that can run on any OS that have access to the web (because Apps on this model will be running on the Web not on Firefox) without modifying the code or learning new technology.

The main difference in Chrome OS and the coming Mozilla B2G is Google building their model on Chrome but Mozilla is building their model on the web.
If you look to Firefox, is not just a browser, it’s piece of software that packed with ideas and concepts, it’s an idol for how the browser should be, and how the web should be, pushing towards a standardization and openness, giving the user a choice to run the web or living his online experience as he want.

Ask MS/Apple/Java/Google developers, what’s their main pain point, they will answer, if I develop an app to run on MS platform and I want to run it on iOS or Android I have to rewrite the whole code and before that I have to learn a new technology and concept and invest more time and effort. What Mozilla is trying to do here with B2G is to bridge the gap by promoting common/standard development tools to build and app that can run on whatever device you have and whatever OS does the user own.

It’s just sitting an example for how the Web should be, how your online life should be. This is how I am reading the news.

Together We Shine

شهر حزيران من الاشهر المميزة في تاريخ مجتمعات موزيلا في المنطقة العربية، بحضور ممثلين مجتمعات موزيلا في الجزائر وتونس ومصر وفلسطين والاردن تم عقد الاجتماع الاول لمجتمعات موزيلا العربية في عمّان بين 25 و26 حزيران بحضور مينشيل بيكر رئيسة موزيلا وبيروس بابيداس مدير مجتمعات موزيلا في المنطقة.
تم طرح ونقاش عدة قضايا في الاجتماع تهم مجتمعات موزيلا المحلية في المنطقة منها التعاون المشترك وتبادل الخبرات، مزيد من المعلومات والصور والمقابلات في الروابط التي في الاسفل

 

25/26 June were amazing days for all Mozillians around the Arabic world, Mozilla communities around the Arabic world gathered in Amman for the 1st Mozilla – Arabic Community in Amman.

Mozillians from Algeria, Tunisia, Egypt, Palestine and Jordan are attended this event. Also Mitchell Baker Mozilla chairperson, attended the two event days for the 1st time. Pierros – Mozilla community Manager was their also.

The meeting discussed several issues regarding the local communities and future cross collaborations between the communities.

You can read different posts about the meeting in Arabic/English/French on the links blow, also you can view the events photos and interviews below