Hijri to Gregorian date conversion in Java 8

One of the main features released in Java SE 8 is the new date time api (java.time package). It has been a long standing pain for java developers to manipulate dates using the cumbersome Calendar api. Usually developers would go for external date time libraries like JodaTime to get over the issues with the default java Calendar api.

The good news for us in the islamic world is that Java SE 8 includes support for Hijri Calendar (Umm
Alqurra) by default. Date conversions from and to Hirji couldn’t be easier. The code snippet below shows an example on how to do this Java 8.

import java.time.chrono.HijrahChronology;
import java.time.chrono.HijrahDate;
import java.time.chrono.IsoChronology;

* Created by Mohamed on 3/23/2014
public class Main {
    public static void main(String[] args) {
        HijrahDate date = HijrahChronology.INSTANCE.dateNow();

Running this will print on the console the following:

Hijrah-umalqura AH 1435-05-27

How about creating arbitrary Hijri dates let’s say my 10/11/1404 and printing the full month name? as simple as:

  HijrahDate date = HijrahChronology.INSTANCE.date(1404,11,10);

which will show the output:


All of this of course is just scratching the surface of what’s possible with the api. For more check the date and time api documentation here http://docs.oracle.com/javase/tutorial/datetime/index.html


Fixing NuPack Installation Problems

NuPack is a new package management tool released to solve the issues related to getting and referencing third party open source libraries in your .Net projects. I decided to take it for a spin since I am fan of package management tools on Linux (apt-get, yum etc.). While you can download NuPack by its own, I installed the tool as part of the ASP.NET MVC3 installation which I got through the Web Platform Installer.

Every thing installed fine but when I tried to use NuPack I got this error message:

Cannot convert the "Microsoft.PowerShell.Commands.SecurityDescriptorCommandsBase"
 value of type "System.String" to type "System.Type"


I searched the web for a little but didn’t find a solution I then stumbled upon this blog post http://www.marcioalthmann.net/2010/10/corrigindo-problema-na-inicializao-do-nupack/ which is in Spanish so google translate ftw.

The solution is pretty simple if you have Reflector.NET installed you just need to go to Tools –> Add-In Manager :


and disable it then restart Visual Studio.


Tada! You have NuPack ready to install your libraries for you.

The “Guy” tag

One of the very first questions that people ask when you say you are a developer goes something like: “What language do you use?” “Windows or Linux?” and my personal favorite “Are you a .NET guy or a Java guy?”. First of all I don’t think that software development is radically different using this technology or that. Software developers should be aware of the various technologies available and when presented with a problem choose the best technology to do the job.

This does not mean that a developer should be a jack of all trades and just jump into projects using technologies which he is not familiar with. Think of different technologies like different human spoken languages. While your brain still works the same no matter what language you are speaking, each new language you learn gives you new ways to construct sentences.

Generally I try to keep doing the following:

  • Read the release notes of major releases of technologies that am not proficient on (.NET vs Java, EF vs NHibernate guys am looking at you).
  • Have a small pet project  that I keep implementing in new technologies to have a hands on feel of the technology.
  • Have constructive discussions with any experts that you know in the unknown technology. A friend of mine gave me a good introduction to Ruby so thanks http://yaserxp.wordpress.com .
  • Be willing to switch your main focus once you are sure a new technology is worth it.

In short don’t allowed yourself to be categorized as “…. Guy”.