Skip to content

Instantly share code, notes, and snippets.

@amhed
Created June 17, 2013 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amhed/5798136 to your computer and use it in GitHub Desktop.
Save amhed/5798136 to your computer and use it in GitHub Desktop.
Ejemplo de manejo de horas para Developers.do
using System; using System.Linq; namespace EjemploDevDo { public class HourManagement { //Supongo que esta lista viene de una BD o de algún servicio private static readonly DateTime[] listaFeriados2013 = new[] { new DateTime(2013,1,1), new DateTime(2013,1,6), new DateTime(2013,1,26), new DateTime(2013,2,27), new DateTime(2013,3,29), new DateTime(2013,5,1), new DateTime(2013,5,30), new DateTime(2013,8,16), new DateTime(2013,9,24), new DateTime(2013,11,6), new DateTime(2013,12,25), }; public static DateTime CalcularFechaRespuesta(DateTime fechaInicio, int cantidadHoras) { var horaInicio = 8; var horaTermino = 17; var fechaRespuesta = fechaInicio; //Se aplica la operacion de adición de horas while (cantidadHoras > 0) { var lapsoDia = horaTermino - fechaRespuesta.Hour; fechaRespuesta = fechaRespuesta.AddHours(lapsoDia > cantidadHoras ? cantidadHoras : lapsoDia); if (fechaRespuesta.Hour == horaTermino) { fechaRespuesta = fechaRespuesta.AddDays(1); fechaRespuesta = new DateTime( fechaRespuesta.Year, fechaRespuesta.Month, fechaRespuesta.Day, horaInicio, 0, 0); } cantidadHoras -= lapsoDia; } //Revision de fin de semana if (fechaRespuesta.DayOfWeek == DayOfWeek.Saturday || fechaRespuesta.DayOfWeek == DayOfWeek.Sunday) fechaRespuesta = fechaRespuesta.AddDays(2); //Revision de dias feriados if (listaFeriados2013.Contains(fechaRespuesta)) { fechaRespuesta = fechaRespuesta.AddDays(1); } //Fecha final return fechaRespuesta; } } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment