Monday, September 29, 2014

Display thaana dates in dhivehi sites.


Here is a small JavaScript snippet which can be used to display date strings in thaana format.

thaanaDates.js

 function thaanaDates(dateObj){   
           this.getLong = function() {  
             return dateObj.getDate() + " " + dateObj.getThaanaMonthName() + " " + dateObj.getFullYear() + " (" + dateObj.getThaanaDayName() + ")";  
           }  
           this.getShort = function() {  
             return dateObj.getDate() + " " + dateObj.getThaanaMonthName() + " " + dateObj.getFullYear();  
           }  
           this.getLongReverse = function() {  
              return dateObj.getFullYear() + " " + dateObj.getThaanaMonthName() + " " + dateObj.getDate() + "، " + dateObj.getThaanaDayName() + "";  
           }  
           this.getDayFirst = function() {  
              return dateObj.getThaanaDayName() + "، " + dateObj.getDate() + " " + dateObj.getThaanaMonthName() + " " + dateObj.getFullYear() + "";  
           }       
 }  
 Date.prototype.getThaanaMonthName = function() {  
           var m = ["ޖަނަވަރީ","ފެބްރުއަރީ","މާރިޗު","އޭޕުރީލް","މޭ","ޖޫން","ޖުލައި","އޯގަސްޓް","ސެޕްޓެމްބަރު","އޮކްޓޯބަރު","ނޮވެމްބަރު","ޑިސެމްބަރު"];            
           return m[this.getMonth()];  
 }   
 Date.prototype.getThaanaDayName = function() {  
           var d = ["އާދީއްތަ","ހޯމަ","އަންގާރަ","ބުދަ","ބުރާސްފަތި","ހުކުރު","ހޮނިހިރު"];  
           return d[this.getDay()];  
 }  


Methods:

  •  getLong: Displays long formatted thaana date string
  •  getShort: Displays date without a day string
  •  getLongReverse: Displays date string with year at the beginning
  •  getDayFirst: Displays date string with day string at the beginning

Simpla Usage:


 document.getElementById("demo").innerHTML = new thaanaDates(new Date).getLong();  

Downloads:

thaanaDates.js
thaanaDates.min.js

No comments: