Refactor
:my
=>
'code'
Codes
Refactorings
Popular
Best
Submit
Spam
Account
Logout
Login
JavaScript doesn't seem to be activated, expect things to be ugly and sloppy!
Learn How to Create Your Own Programming Language
createyourproglang.com
Recent
Simple Particle Engine for a shooter game
Snake / Nibbles clone in C and Ncurses
Please improve
Parsing of XML data has high CPU usage
Convert simple Javascript to jQuery plugin
Active Record getting unique records
List the files in a directory without the directory name or the extension
clean the code
ohs system, recruitment software, hr software, oh&s software, human resources software, ohs software
Array parsing in a block
Popular
Parsing of XML data has high CPU usage
Please improve
Snake / Nibbles clone in C and Ncurses
List the files in a directory without the directory name or the extension
Convert simple Javascript to jQuery plugin
Simple Particle Engine for a shooter game
Active Record getting unique records
Breadth first cartesian product iterator
php refactoring
first BST
Pastable version of
Split DateTime Range Around Midnights
<pre class='prettyprint' language='cs'>public static class MidnightPartitioner { public struct SchedulePartition { public DateTime Start { get; set; } public DateTime End { get; set; } } /// <summary> /// Splits a starting and ending DateTime range into /// SchedulePartition objects. Each SchedulePartition /// represents a span of time spent in a specific date. /// </summary> /// <param name="scheduleStart"></param> /// <param name="scheduleEnd"></param> /// <returns></returns> public static IEnumerable<SchedulePartition> Break(DateTime scheduleStart, DateTime scheduleEnd) { List<SchedulePartition> dayBlocks = new List<SchedulePartition>(); if (scheduleStart <= scheduleEnd) { DateTime tomorrow = scheduleStart.Date.AddDays(1); // Determine when tomorrow is. if (tomorrow < scheduleEnd) /* Schedule ends after tomorrow */ { // Calculates the time spent spent in the scheduleStart date. TimeSpan timeSpentInScheduleStartDate = tomorrow.Subtract(scheduleStart); // Calculates the time spent in the day after the schedule start date TimeSpan timeSpentInDayAfterScheudleStart = scheduleEnd.Subtract(tomorrow); dayBlocks.Add( new SchedulePartition { Start = scheduleStart, End = scheduleStart.Add(timeSpentInScheduleStartDate) } ); if (timeSpentInDayAfterScheudleStart.TotalDays > 1) { dayBlocks.AddRange( Break(tomorrow, scheduleEnd) ); } else { dayBlocks.Add( new SchedulePartition { Start = tomorrow, End = tomorrow.Add(timeSpentInDayAfterScheudleStart) } ); } } else { /* Schedule ends before tomorrow. Cannot be partitioned around midnight. * Return the uncut schedule as a SchedulePartition */ return new[] { new SchedulePartition { Start = scheduleStart, End = scheduleEnd } }; } } else throw new ArgumentException("Chronological error with scheduleStart and scheduleEnd arguments"); return dayBlocks; } }</pre> <a href="http://www.refactormycode.com/codes/942-split-datetime-range-around-midnights" style="color:#fff" title="As seen on RefactorMyCode.com"><img alt="Small_logo" src="http://www.refactormycode.com/images/small_logo.gif" style="border:0" /></a>