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)
    }
}

Being Different

Everyone in the world agrees that we are different, brothers raised in the same family and under the same roof are different, twin that grow up on the same time in the same womb are different. Two tress are different even if they are coming from the same fruit’s seeds.

With my new yoga experience I learned that there are even differences in the same body! For example, my left leg is different than the right one, my right shoulder is different than the left one! How much I can do with my right arm is different than the left one! But with all these differences they shape one body that live in peace, they work together in harmony to help doing everything I ask. I never saw my left foot refuse to work with my right one because it has different size or less flexibility. I never felt that my right eyes asking my left one to leave my body because is less stronger. On the opposite, if my left eye is less stronger, my right one will do more effort to cover this gap. When my left leg get tired my body lean to my stronger right leg to give more support. They work as a whole to make me what I am now.

I wonder why people in our society don’t look into themselves and learn from their bodies that being different is not something bad. It is part of the beauty of our life and with our differences we fill the gaps between each others. We can live in peace and harmony, we can support each other in one society even if we are different exactly like my left leg support the different right leg in the same body!

Prisoner of the time

Today I discovered that I am completely prisoner of the time!

Today I went to my Yoga class a little bit earlier and before the class started I noticed that I am not wearing my Fitbit watch. For a moment I had a panic attack but then I remembered that I connected to my PC at work to be recharged and I forgot to take it back again. I told myself, tomorrow I will get it, that’s not an issue.

I started to prepare my yoga mat, and I sat on my cushion waiting for the class to start, unconsciously after few moments I looked at my arm to see the time, but the watch was not there. I felt irritated because I felt that I don’t know what’s the time now! How long I have to wait until the class to start?! I looked around to see if there is a clock but nothing was there, just empty walls. I said to myself; close your eyes Rami and try to clear your head from the daily thoughts. But this idea of losing the track of time kept coming back again. I had a discomfort feelings, I am losing the track of the time! I am getting lost!!

The class started, I tried to focus more on the instructions but from time to time, something jump in my head, asking what’s the time now?! I had to fight this feelings couple of times until I won. I completely let the time go and I lost the track of time. The only thing that I was focusing on my breathes and how to put my self in the posture.

I finished the class, and I don’t know what is the time now, my head is clear, I don’t care if it is late or it is early. I arrived at home and once I entered my living room I noticed the time and I said to myself. It felt like if I was away for a very long time!

We are prisoner of the time (at least me), sometimes we lose the joy of a moment because we are afraid that it will end soon. We keep looking into our watches/mobiles or clocks to know our location in time. We lost the sense of time because we keep tracking of it, we are afraid to be left alone without knowing the time because we are afraid to be by ourselves so we don’t face ourselves for a longer period.

What I learned today is to set myself free from my time’s prison, to enjoy the moment and face myself without a fear.

Yoga – A new experience

When I started  Yoga exercises five years ago, I wanted to bring balance to my life because I know that yoga is all about balance. Gym and weight lifting is not something for me. I feel that I have more connection with yoga. Since I start practicing I understood my body more and I started to listen to it more.

Now, I am having different experience guided by a teacher.  I started to see Yoga in different dimension I didn’t see it before. Yoga is about balance but also about to do what your body allow you do in the moment and slowly let it expand naturally and with a flow. It feels natural because it connects your with your body rhythm through your breath. It sync your movement with your natural body rhythm to bring you to a next level of harmony.

I will keep exploring more about my new Yoga experience and I am looking forward to see where this time it is going to take me.

We see what we want to see!

I am a visual person, I like to visualize everything I am thinking of or I want to do. For that reason, I have a strong visual memory. Everyday when I leave my house I remember everything exactly where it was with every details. So if anything happened during my absence and alter that I would know immediately. Few days ago, I return from work as usual and the first thing I would do after removing my shoes and jacket is to raise the temperature of my central heater. I went there to put it up, but I was surprised to see it  already set to 21 which the usual temperature that I am used too. The first thing crossed my mind was “maybe I forgot to lower it in the morning before leaving to work, so no need to panic. And why would a thief put the temperature up?!”. I felt more relaxed with that idea and I went to kitchen to prepare my dinner. The first thing that I noticed was the towel that I used to clean the sink is still wet! That raised a question again inside my head but I said to myself “You know that it is cold and things take time to dry, and again why would a thief clean the kitchen?!”. Then I noticed another thing odd, the hand of my water sink was set to the maximum, and usually I don’t put it like this or never. Also, once I opened it; directly a hot water came out. At this moment I stopped and said to myself ” definitely there was someone in the apartment and he left before my arrival with few minutes, how come then the water came that hot directly!” For a moment I wanted to panic but deep inside me the person that was here  didn’t mean any harm! Then I remembered, and I started to laugh. My landlord called me in the morning and asked me if he can come to the apartment and check the central heating for annual maintenance while I am at work :)! Now everything make sense to me.

When I think about what happened again, I see how sometimes we see things happening on front of us, screaming on our face saying there is something wrong happening here, but we intentionally ignore them because we don’t want to believe that thing is happening and we only want to see what we want to see!

شو تعلمت من الركض؟

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

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

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

احكي عربي

المشهد الاول:

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

المشهد التاني:

بتكون في احد المجتماعت التجارية، الام ماشية وابنها الصغير تركها وراح، بتنادي عليه… ماما come here، مش قلتلك انك ما تروح بعيد! او بتخبط بحد ماشي او حد بيخبط فيك بيحكلك Sorry؟! والله في كلمة بالعربي اسمها أسف!!! او بتناوله او بتناولها شي بتحكيلك Thank you! طيب مالها شكرا…

المشهد الثالث:

بتكون فاتح الفيسبوك بروح بطلعك صاحبك وبرسالة وبكتبلك (rhd3as sads5 dads9) وبعدها ابتسامة؟؟؟ طبعا مخي ببطل يجمع شو هاد بالزبط بقعد افك الشفرة! (اه انا قاصدكم انتوا اللي بتكتبولي هيك) بتحكيله او بتحكيلها فيك تكتب عربي، بقلك لا هاي اسرع..مش فاهم كيف اسرع كابس الكبسة سواء حرف عربي او لاتيني… المهم بدك تكتب بأحرف لاتيني بتكب لغة افهمها يا انجليزي يا فرنسي غير هيك… غيِّر للعربي.

المشهد الرابع:

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

الشي الوحيد اللي بيخطر على بالك وانت بتبسم وبتحكي لحالك… يا ريت قومي يعلمون….

ملاحظه: مش معنا هاد الحكي اني ملاك ما بعمل شغلات وما بكتب بلغات تانية! لما بدي اكتب شي بلغة تانية بكون موجه الموضوع للكل مش بس لمجتمعنا… هون كلهم ١٦ مليون واحد في العالم وكل شي عندهم معمول بلغتهم حتى اجهزتهم الخلوية بتكون بلغتهم… ما صاروا متخلفين ولا ناقصهم شي بالعكس من دول العالم الاول!!

عُلبة الدُّخان…

المشهد الأول:
السلام عليكم، مجمع الشمال؟ سأل صاحب سيارة الأجرة التي استوقفها.
اه تفضل؛ بس حط الشنطة ورا. اجابه السائق.
انطلقت السياره مسرعة نحو مجمع الشمال؛ وفي الطريق قطع السائق الصمت وقال:
انشاء الله نازل على الضفة؟
انشاء الله؛ اجابه وهو يحاول تذكر كم سائق اجره سأله نفس السؤال.
وين نازل على خير؟ يسأل السائق مجددا.
على نابلس ياحجّ. اجابه وهو يتفقد كومة الأوراق الثبوتية لعله نسي شيئا منها.
الله يّسِّر امرك؛ اخدت معك دُّخان؟ سأل السائق مرة اخرى.
لا والله يا حجّ ماأخدت. ما بدخِّن.
خُد معك، بتبيعهم هناك بطِّلع حق نزلتك، أنا عملت هيك لما نزلت على الصيف. انت بتعرف. كم بتربح بالكروز!لا ياحجّ ، بشتري من السوق الحُرّة على الجسر، في محاولة لإنهاء الحِوار.

المشهد الثاني
وقف يبحث بعينه يميناً ويسارا عن حقيبته بين جبال الحقائب المتناثرة هنا وهناك. لو أني وضعت علامة فارقة على حقيبتي لأصبح إيجادها من بين هذه الحقائب سهلاً جداً، أخذ يحدث نفسه. وفجأة أعاده إلى الواقع صوت امرأة تتحدث إليه :
مرحبا يا خالتي
أهلين ردَّ عليها.
شايل معك دُّخان يا خالتي؟
لا ما بدخن وما في حد عندنا في البيت بدخن!
في عندي كروزين دخان اغلبك اتشيللي اياهم معك، اذا أخدوهم منك عادي
لا ياخالتي ما بشيل معي، أجابها وهو يبتسم.
بعينك الله يا خالتي بس الاتنين هذول ولو بدّي اغلبك.
معلش ياخالتي، مستعجل وما بدّي استنى حد وانا طالع.
ماشي ياخالتي، شكرًا ألك. جوابته وعلى وجهها نظرة حزن لعل قلبه يرق وَيأخذ معه علبتا الدُّخان.

المشهد الثالث:
المكان هاظ لحد؟ سأله احد المسافرين عن المقعد الخالي بجانبه في الباص المُتجه إلى أريحا.
لا مش لحد تفضل. اجابه وهو بتنفس الصعداء بإن رحلته اوشكت على النهاية.
الجسر اليوم فاظي وما غلّبوا حد في الجمارك، لو كنت عارف كان جيبت معي كمان دُّخان! يحاول المسافر كسر الجمود والدخول في حديث.
اه اليوم مشيت الأمور بسرعه، الحمدالله. وهو يأمل ان يدعه لوحده.
شايف الباص هاظ، بتحداك انه تلاقي راكب مش شايل معه دُّخان، قالها المسافر وهو يضحك وفي صوته نبرة تحدي.
خطر على باله ان يجيبه “أنا لا أحمل دُّخان ” ولكن منع نفسه لان ذلك سيدخله في سين وجيم ولماذا وجميع علامات الاستفهام. فأجابه اختصارا للحديث “معك حق”.
في تلك اللحظة خطر في باله شيء وحيد وهو كيف اختزلت احلام شعب بعلبة دُّخان يجلبها معه عبر الحدود!!

الكروز: هو علبة الدخان الكبيرة التي تحتوي على ١٠ علب صغيرة

Firefox & Me: Episode 2: First encounter

It was end of summer 2002, I was sitting on my balcony having my afternoon coffee and flipping the pages of PC magazine, when a big article that cover one page about a new browser called Phoenix grabbed my attention.  I read the article very fast then jumped behind my PC and started to type the URL to download it, I was thinking is it going to be the one! The file was 8 MB, I was surprised how small it was, but with my dial up connection and 1Kbps speed, I have to wait more in order to have it downloaded. Once I have on my PC, I open the zip file, looking for the EXE, version 0.1, that’s interesting; I was telling myself. I launch it, and started to browse, opening many pages, it is really fast, responsive; even I can even customize the toolbar. What kind of browser is this?! Without hesitation, I clicked the button; you are going to be my default browser from now on…

To be continue…