Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. That's an useless class

That's an useless class

Scheduled Pinned Locked Moved The Weird and The Wonderful
6 Posts 6 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    doud
    wrote on last edited by
    #1
    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 &&
    
    C V S N D 5 Replies Last reply
    0
    • D doud
      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 &&
      
      C Offline
      C Offline
      Covean
      wrote on last edited by
      #2

      My favs are:
      public static string GetHour() - very confusing if you take a look at functions like GetDay/GetMonth... public static bool IsDate(DateTime date) - how is this function able not to return true?

      Greetings Covean

      1 Reply Last reply
      0
      • D doud
        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 &&
        
        V Offline
        V Offline
        V 0
        wrote on last edited by
        #3

        Some developers don't mind multiple returns in one function, but for me, that's a wtf in itself. Not to mention returning a complete statement instead of a value.

        V.

        1 Reply Last reply
        0
        • D doud
          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 &&
          
          S Offline
          S Offline
          Som Shekhar
          wrote on last edited by
          #4

          I agree that it is a useless class. Usually such classes are very useful for future scaling and I do use such classes to make sure that all references are taken from these classes only. It is like creating your own custom controls derived from base controls. Any future modifications are resembled uniformly. But even after thinking a lot, I couldn't understand what this guy was trying to achieve here. It can't be used for scaling also :(

          1 Reply Last reply
          0
          • D doud
            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 &&
            
            N Offline
            N Offline
            nxaspisol
            wrote on last edited by
            #5

            Thanks, that made standing up early on sunday worth it!

            1 Reply Last reply
            0
            • D doud
              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 &&
              
              D Offline
              D Offline
              Don Kackman
              wrote on last edited by
              #6

              This is the best part of the class

              doud wrote:

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

              Maybe rename the class to DateTimeExtendedGetNewGuidAsString

              10 PRINT "Software is hard. - D. Knuth" 20 GOTO 10

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups