Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 59 additions & 59 deletions PersianDatePicker-MVC/PersianDateExtension.cs
Original file line number Diff line number Diff line change
@@ -1,60 +1,60 @@
//By: Bahman Nikkhahan
//February 2013
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace PersianDatePicker_MVC
{
public static class PersianDateExtension
{
public static string GetPersianDateString(DateTime? date)
{
string PersianDate = "";
if (!date.HasValue)
{
return PersianDate;
}
System.Globalization.PersianCalendar p = new System.Globalization.PersianCalendar();
int Year = p.GetYear(date.Value);
int Month = p.GetMonth(date.Value);
int Day = p.GetDayOfMonth(date.Value);
string MonthName = "فروردین";
switch (Month)
{
case 1: { MonthName = "فروردین"; break; }
case 2: { MonthName = "اردیبهشت"; break; }
case 3: { MonthName = "خرداد"; break; }
case 4: { MonthName = "تیر"; break; }
case 5: { MonthName = "مرداد"; break; }
case 6: { MonthName = "شهریور"; break; }
case 7: { MonthName = "مهر"; break; }
case 8: { MonthName = "آبان"; break; }
case 9: { MonthName = "آذر"; break; }
case 10: { MonthName = "دی"; break; }
case 11: { MonthName = "بهمن"; break; }
case 12: { MonthName = "اسفند"; break; }
default: { MonthName = "فروردین"; break; }
}
PersianDate = Day.ToString() + " " + MonthName + " " + Year.ToString();
return PersianDate;
}
public static string GetPersianDateStringSlashed(DateTime? date)
{
string PersianDate = "";
if (!date.HasValue)
{
return PersianDate;
}
System.Globalization.PersianCalendar p = new System.Globalization.PersianCalendar();
int Year = p.GetYear(date.Value);
int Month = p.GetMonth(date.Value);
int Day = p.GetDayOfMonth(date.Value);
PersianDate = Day.ToString() + "/" + Month.ToString() + "/" + Year.ToString();
return PersianDate;
}
}
//By: Bahman Nikkhahan
//February 2013
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace PersianDatePicker_MVC
{
public static class PersianDateExtension
{
public static string GetPersianDateString(DateTime? date)
{
string PersianDate = "";
if (!date.HasValue)
{
return PersianDate;
}
System.Globalization.PersianCalendar p = new System.Globalization.PersianCalendar();
int Year = p.GetYear(date.Value);
int Month = p.GetMonth(date.Value);
int Day = p.GetDayOfMonth(date.Value);
string MonthName = "فروردین";
switch (Month)
{
case 1: { MonthName = "فروردین"; break; }
case 2: { MonthName = "اردیبهشت"; break; }
case 3: { MonthName = "خرداد"; break; }
case 4: { MonthName = "تیر"; break; }
case 5: { MonthName = "مرداد"; break; }
case 6: { MonthName = "شهریور"; break; }
case 7: { MonthName = "مهر"; break; }
case 8: { MonthName = "آبان"; break; }
case 9: { MonthName = "آذر"; break; }
case 10: { MonthName = "دی"; break; }
case 11: { MonthName = "بهمن"; break; }
case 12: { MonthName = "اسفند"; break; }
default: { MonthName = "فروردین"; break; }
}
PersianDate = Day.ToString() + " " + MonthName + " " + Year.ToString();
return PersianDate;
}
public static string GetPersianDateStringSlashed(DateTime? date)
{
string PersianDate = "";
if (!date.HasValue)
{
return PersianDate;
}
System.Globalization.PersianCalendar p = new System.Globalization.PersianCalendar();
int Year = p.GetYear(date.Value);
int Month = p.GetMonth(date.Value);
int Day = p.GetDayOfMonth(date.Value);

PersianDate = Day.ToString() + "/" + Month.ToString() + "/" + Year.ToString();
return PersianDate;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ last edit: 25/07/2013
day = '0' + day.toString();
var textboxname = $(this).attr('name');
var textboxnamewithoutprefix = textboxname.substring(0, textboxname.indexOf('.EnglishDateTextbox'));

//in Models that have nested item '.' must be replace to '_' otherwise getElementById will fail
textboxnamewithoutprefix = textboxnamewithoutprefix.replace('.', '_');

document.getElementById(textboxnamewithoutprefix).value = date.getFullYear() + '/' + month + '/' + day;
}
});
Expand Down