Last active
August 29, 2015 14:26
-
-
Save dannylloyd/9fa00e20a17e2860e5fa to your computer and use it in GitHub Desktop.
Html calendar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Partial Class Calendar | |
| Inherits System.Web.UI.Page | |
| Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load | |
| If Not IsPostBack Then | |
| RenderCalendar() | |
| End If | |
| End Sub | |
| Sub RenderCalendar() | |
| Dim calendar = New StringBuilder() | |
| Dim startDate As New DateTime(2015, 8, 2) | |
| Dim endDate As New DateTime(2015, 8, 8) | |
| Dim [date] As DateTime = startDate | |
| calendar.AppendFormat("{0}<div class=""week weekHeading clearfix"">{0}", vbCrLf) | |
| While [date] <= endDate | |
| Dim dw As DayOfWeek = [date].DayOfWeek | |
| [date] = [date].AddDays(1) | |
| calendar.AppendFormat("{1}<div class=""dayOfWeek dayOfWeek{2}"">{0}</div>{1}", dw.ToString(), vbCrLf, CInt(dw) + 1) | |
| End While | |
| calendar.AppendFormat("{0}</div><!-- End Week -->{0}", vbCrLf) | |
| Dim year = 2015 | |
| Dim month = 7 | |
| 'DateTime.DaysInMonth(year, month) | |
| Dim firstDay = New DateTime(year, month, 1) | |
| Dim dayOfWeek = CInt(firstDay.DayOfWeek) | |
| calendar.AppendFormat("{0}<div class=""week clearfix"">{0}", vbCrLf) | |
| For i = 0 To dayOfWeek - 1 | |
| calendar.AppendFormat("{0}<div class=""day empty""></div>{0}", vbCrLf) | |
| Next | |
| Dim totalDaysInMonth = DateTime.DaysInMonth(year, month) | |
| For i As Integer = 1 To totalDaysInMonth | |
| Dim day = New DateTime(year, month, i) | |
| If day.DayOfWeek = System.DayOfWeek.Sunday Then | |
| calendar.AppendFormat("{0}<div class=""week clearfix"">{0}", vbCrLf) | |
| End If | |
| 'lastDayOfWeekOfMonth | |
| If totalDaysInMonth = day.Day Then | |
| calendar.AppendFormat("{1}<div class=""day dayOfWeek{2} lastDayOfMonth""><span class=""dayNumber"">{0}</span></div>{1}", i, vbCrLf, CInt(day.DayOfWeek) + 1) | |
| ElseIf day.AddDays(7).Month <> day.Month Then | |
| calendar.AppendFormat("{1}<div class=""day dayOfWeek{2} lastDayOfWeekOfMonth""><span class=""dayNumber"">{0}</span></div>{1}", i, vbCrLf, CInt(day.DayOfWeek) + 1) | |
| Else | |
| calendar.AppendFormat("{1}<div class=""day dayOfWeek{2}""><span class=""dayNumber"">{0}</span></div>{1}", i, vbCrLf, CInt(day.DayOfWeek) + 1) | |
| End If | |
| If day.DayOfWeek = System.DayOfWeek.Saturday Then | |
| calendar.AppendFormat("{0}</div><!-- End Week -->{0}", vbCrLf) | |
| End If | |
| Next | |
| litCalendar.Text = calendar.ToString() | |
| End Sub | |
| End Class | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment