logo

JavaScript DateTime

A library of datetime manipulations (ripped from the python datetime module) for manipulating date times, especially for plotting.

Browse Code in SVN Repository

Date, Time, Datetime, Duration (absolute ms), Span/Interval (start&end)

Refererences

Plotting Dates & Times

How lables on absolute datetime ranges are formatted

  Few 1-4
(most info -- only what changes and one constant)
Medium 5-10 (a shortened version of Few) Lots >10 (top of two lines - the largest interval that changes more than 10 or more times in the range)
Many Years 1980, 1990, 2000, 2010 '80, '85, '90, '95, '00, '05, '10, '15 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 00, 02, 04, 06, 08, 10
Few Years 1998, 1999, 2000, 2001    
One Or Two Years January 1999, June 1999, January 2000, June 2000 Oct99, Nov99, Dec99, Jan00, Feb00, Mar00, JFMAMJJASONDJFMAMJJASONDJFM
12 Months Mar 99, Jun 99, Sep 99, Dec 99, Mar 00,    
Few Months December 1999, January 2000, February 2000, March 2000 Dec 15, Jan 1, Jan 15, Feb 1, Feb 15, Mar 1
or
1-Jan, 15-Jan, 1-Feb, 15-Feb, 1-Mar
12/15, 12/20, 12/25, 1/1, 1/5, 1/10, 1/15, 1/20, 1/25, 2/1, 2/5, 2/10, 2/15, 2/20, 2/25, 3/1, 3/5
or
15-D, 20-D, 25-D, 1-J, 5-J, 10-J, 15-J, 20-J, 25-J, 1-F, 5-F, 10-F, 15-F, 20-F, 25-F, 1-M, 5-M
30 Days Dec 20 1999, Jan 1 2000, Jan 10 2000, Jan 20 2000 Dec 20, Dec 25, Jan 1, Jan 5, Jan 10, Jan 15, Jan 20 dd
15 Days Dec   dd
Few Days Dec 31 12:00pm, Dec 31 6:00pm, Jan 1 12:00am, Jan 1 6:00am (every day)    
Few Hours      
10-60 Minutes mm-dd h:mm:ss h:mm:ss mm
1-10 Minutes mm-dd h:mm:ss mm:ss ss
1-60 Seconds h:mm:ss mm:ss ss
Less than a second h:mm:ss.u ss.u .uu

Calculating Days of Week & Leap Years

   char *day_of_week(int day, int month, int year)
   {
      int cent;
      char *dayofweek[] = {
         "Sunday", "Monday", "Tuesday", "Wednesday",
         "Thursday", "Friday", "Saturday"
      };

      /* adjust months so February is the last one */
      month -= 2;
      if (month < 1) {
         month += 12;
         --year;
      }
      /* split by century */
      cent = year / 100;
      year %= 100;
      return (dayofweek[((26 * month - 2) / 10 + day + year
                        + year / 4 + cent / 4 + 5 * cent) % 7]);
   }

   int leap_year(int year)
   {
       return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
   }