miércoles, 9 de julio de 2008

Sumar fechas sin tomar en cuenta fines de semana

Una compañerita de trabajo me pidió un favor el cual consistía en poder sumarle a una fecha N días pero sin tomar en cuenta los fines de semana.Las siguientes funciones hacen dicha tarea:
  • DateTimeIgnoringWeekEnds: La cual recibe como parametros la fecha inicial y los días a sumar.


  • NumberOfWeekEndDays: Esta función es usada por la función anterior y nos ayuda a saber cuantos días son sabado o domingo entre dos fechas.

private int NumberOfWeekEndDays(DateTime startDate, DateTime endDate)
{
int intContador = 0;
DateTime tempDate = startDate;
while (tempDate <= endDate)
{
if (tempDate.DayOfWeek == DayOfWeek.Saturday ||
tempDate.DayOfWeek == DayOfWeek.Sunday)
{
intContador++;
}
tempDate = tempDate.AddDays(1);
}

return intContador;
}

public DateTime DateTimeIgnoringWeekEnds(DateTime starDate, int days)
{
int intweekends = 0;
int intHelp = 0;

DateTime endDate = starDate.AddDays(days);

do
{
intweekends = NumberOfWeekEndDays(starDate, endDate);
endDate = starDate.AddDays(days + intweekends);

if (intHelp == 0 || intHelp != intweekends)
intHelp = intweekends;
else
intweekends = 0;

} while (intweekends != 0);

return endDate;
}

    Ejemplo :

DateTime dtmFechInicio = DateTime.Now;
DateTime dtmFechaFinal = DateTimeIgnoringWeekEnds(dtmFechInicio, 13);

lunes, 21 de enero de 2008

Srcipt#

Script# brings the C# development experience (programming and tooling) to the JavaScript/Ajax world.

The Script# compiler is a C# compiler that generates JavaScript as its output instead of IL. A key goal of the compiler to produce readable JavaScript (as if you had authored it by hand), and would be comfortable deploying into real apps. Hence the translation works from C# source directly into JavaScript without an intermediate IL layer. The compiler can also produce equivalent, but much more compact script for use in release mode deployment. The compiler does not introduce any additional levels of abstraction, thereby allowing you full control of what your application does. In essense the best of script with the best of C#!

The Script# compiler can optionally be used with the Script# Framework that provides a more productive application development platform for larger, and more complex applications.

http://projects.nikhilk.net