Click here to Skip to main content
15,905,614 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
QuestionRe: Subclassing Pin
Chris Meech1-Apr-10 3:05
Chris Meech1-Apr-10 3:05 
AnswerRe: Subclassing Pin
Ian Shlasko1-Apr-10 10:56
Ian Shlasko1-Apr-10 10:56 
GeneralEncoding IP addresses Pin
Bernhard Hiller26-Mar-10 4:31
Bernhard Hiller26-Mar-10 4:31 
GeneralRe: Encoding IP addresses Pin
adgonz26-Mar-10 5:36
adgonz26-Mar-10 5:36 
GeneralRe: Encoding IP addresses Pin
reflex@codeproject30-Mar-10 8:24
reflex@codeproject30-Mar-10 8:24 
GeneralRe: Encoding IP addresses Pin
adgonz30-Mar-10 8:54
adgonz30-Mar-10 8:54 
GeneralRe: Encoding IP addresses Pin
supercat97-Apr-10 7:29
supercat97-Apr-10 7:29 
GeneralThat's an useless class Pin
doud26-Mar-10 3:19
professionaldoud26-Mar-10 3:19 
public class DateTimeExtended
{
    protected static readonly Logger Log = NLog.LogManager.GetCurrentClassLogger();

    public enum Days { Sun=0, Mon, Tue, Wed, Thu, Fri, Sat };

    public static string[] FerialDays = {"0101",
                                         "0501",
                                         "0508",
                                         "0714",
                                         "0815",
                                         "1101",
                                         "1111",
                                         "1225",
                                        };

    public static DateTime GetDate()
    {
        return DateTime.Now;
    }

    public static string GetDate(string format)
    {
        try
        {
            if(String.IsNullOrEmpty(format))
                return GetDate().ToString();
            else
                return GetDate().ToString(format);
        }
        catch
        {
            return DateTime.Now.ToString();
        }
    }

    public static string GetHour()
    {
        return DateTime.Now.Hour.ToString("00") + ":" + DateTime.Now.Minute.ToString("00") + ":" + DateTime.Now.Second.ToString("00");
    }

    public static int GetDay()
    {
        return (int) DateTime.Now.Day;
    }

    public static int GetMonth()
    {
        return (int) DateTime.Now.Month;
    }

    public static int GetYear()
    {
        return (int) DateTime.Now.Year;
    }

    public static int GetDayOfWeek()
    {
        return (int) DateTime.Now.DayOfWeek;
    }

    public static string GetNextMonthStart(DateTime date, int NbMois)
    {
        DateTime _date = date.AddMonths(NbMois);
        return _date.Year.ToString("0000") + "-" + _date.Month.ToString("00") + "-" + "01";
    }

    public static bool IsDate(DateTime date)
    {
        try
        {
            int day = date.Day;
            int month = date.Month;
            int year = date.Year;

            if(month == 2)
            {
                if(day == 30 || day == 31)
                    return false;
                if(day == 29)
                    return ((year%4 == 0 && year%100 != 0) || year%400 == 0);
            }

            if (day == 31)
                return !(month == 4 || month == 6 || month == 9 || month == 11);

            return true;
        }
        catch { return false; }
    }

    public static string GetGuid()
    {
        return Guid.NewGuid().ToString();
    }

     public static DateTime GetDateValue(string sVal)
    {
        DateTime dtRet;
        sVal = sVal.Replace("-", "").Replace("/", "");
        try
        {
            int nAdd = 0;
            if (Convert.ToInt32(sVal.Substring(0, 2)) < 80)
            {
                nAdd = 2000;
            }
            else
            {
                nAdd = 1980;
            }

            if (sVal.Length == 6)
            {
                //YYMMDD
                dtRet = new DateTime(nAdd + Convert.ToInt32(sVal.Substring(0, 2)), Convert.ToInt32(sVal.Substring(2, 2)), Convert.ToInt32(sVal.Substring(4, 2)), 0, 0, 0);
                return dtRet;
            }
            if (sVal.Length == 8)
            {
                if (sVal.IndexOf("-") > 0)
                {
                    //YY-MM-DD
                    dtRet = new DateTime(nAdd + Convert.ToInt32(sVal.Substring(0, 2)), Convert.ToInt32(sVal.Substring(3, 2)), Convert.ToInt32(sVal.Substring(6, 2)), 0, 0, 0);
                    return dtRet;
                }

                //YYYYMMDD
                dtRet = new DateTime(Convert.ToInt32(sVal.Substring(0, 4)), Convert.ToInt32(sVal.Substring(4, 2)), Convert.ToInt32(sVal.Substring(6, 2)), 0, 0, 0);
                return dtRet;
            }
            if (sVal.Length == 10)
            {
                //YYYY-MM-DD
                dtRet = new DateTime(Convert.ToInt32(sVal.Substring(0, 4)), Convert.ToInt32(sVal.Substring(5, 2)), Convert.ToInt32(sVal.Substring(8, 2)), 0, 0, 0);
                return dtRet;
            }
            return Convert.ToDateTime(sVal);
        }
        catch (Exception)
        {
        }
        dtRet = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0);
        return dtRet;
    }

}


This code has been in use for years, even if it's totaly uselless.
GeneralRe: That's an useless class Pin
Covean26-Mar-10 4:00
Covean26-Mar-10 4:00 
GeneralRe: That's an useless class Pin
V.26-Mar-10 4:59
professionalV.26-Mar-10 4:59 
GeneralRe: That's an useless class Pin
Som Shekhar27-Mar-10 4:19
Som Shekhar27-Mar-10 4:19 
GeneralRe: That's an useless class Pin
nxaspisol27-Mar-10 22:31
nxaspisol27-Mar-10 22:31 
GeneralRe: That's an useless class Pin
Don Kackman29-Mar-10 14:37
Don Kackman29-Mar-10 14:37 
GeneralMidPointRounding for Math.Round() method in .Net Application Pin
elizas24-Mar-10 1:03
elizas24-Mar-10 1:03 
GeneralRe: MidPointRounding for Math.Round() method in .Net Application Pin
Keith Barrow24-Mar-10 1:30
professionalKeith Barrow24-Mar-10 1:30 
GeneralRe: MidPointRounding for Math.Round() method in .Net Application Pin
PIEBALDconsult24-Mar-10 5:13
mvePIEBALDconsult24-Mar-10 5:13 
GeneralRe: MidPointRounding for Math.Round() method in .Net Application Pin
David Skelly24-Mar-10 7:38
David Skelly24-Mar-10 7:38 
GeneralRe: MidPointRounding for Math.Round() method in .Net Application Pin
fabrice.leal24-Mar-10 7:50
fabrice.leal24-Mar-10 7:50 
GeneralRe: MidPointRounding for Math.Round() method in .Net Application Pin
David Skelly24-Mar-10 23:39
David Skelly24-Mar-10 23:39 
JokeRe: MidPointRounding for Math.Round() method in .Net Application Pin
Jeremy Tierman25-Mar-10 7:11
Jeremy Tierman25-Mar-10 7:11 
GeneralRe: MidPointRounding for Math.Round() method in .Net Application Pin
peterchen24-Mar-10 22:42
peterchen24-Mar-10 22:42 
GeneralThe next big paradigm shift in database design Pin
Jeroen De Dauw22-Mar-10 10:57
Jeroen De Dauw22-Mar-10 10:57 
GeneralRe: The next big paradigm shift in database design Pin
Dalek Dave22-Mar-10 15:33
professionalDalek Dave22-Mar-10 15:33 
GeneralRe: The next big paradigm shift in database design Pin
Luc Pattyn22-Mar-10 16:18
sitebuilderLuc Pattyn22-Mar-10 16:18 
GeneralRe: The next big paradigm shift in database design Pin
cptKoala22-Mar-10 20:50
cptKoala22-Mar-10 20:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.