kdbが返してくる間抜けな授業時間をパースしてdatetimeを返す

    例:

        月1
        木3,4
        水3,4金5,6
        月・火・水3-6

        sqlite3 ~/.course_list.db 'select periods from courses'|sort|uniq
547795
def parse_stupid_date(c):
    
    start_time = {
        1: { "hour": 8, "minute": 40 },
        2: { "hour": 10, "minute": 10 },
        3: { "hour": 12, "minute": 15 },
        4: { "hour": 13, "minute": 45 },
        5: { "hour": 15, "minute": 15 },
        6: { "hour": 16, "minute": 45 },
    }

    end_time = {
        1: { "hour": 9, "minute": 55 },
        2: { "hour": 11, "minute": 25 },
        3: { "hour": 13, "minute": 30 },
        4: { "hour": 15, "minute": 0 },
        5: { "hour": 16, "minute": 30 },
        6: { "hour": 18, "minute": 0 },
    }

    periods = c['periods']
    dates = []
    while len(periods) > 0:
        m = re.search('((?:.・)*(?:.))([0-9])([,-])([0-9])', periods)
        assert(m is not None)

        groups = list(reversed(list(m.groups())))
        weekdays = groups.pop().split('・')
        period_start = int(groups.pop())

        if len(groups) == 0:
            sep = ','
            period_end = period_start
        else:
            sep = groups.pop()
            period_end = int(groups.pop())

        assert(sep in ['-', ','])
        assert(1 <= period_start <= 6)
        assert(1 <= period_end <= 6)

        if sep == ',':
            assert(period_end - period_start == 1)

        for weekday in weekdays:
            dt = get_start_date(c['modules'], weekday)
            dt_start = dt.replace(**start_time[period_start])
            dt_end = dt.replace(**end_time[period_end])
            dates.append((dt_start, dt_end))

        periods = periods[m.span()[1]:]

    return dates
570951
public static void main(String[] args) {
		Date date = parseDate("2018/01/07 12:11:10", "yyyy/MM/dd HH:mm:ss");
		Date date2 = parseDate("2018/01/07 16:12:15", "yyyy/MM/dd HH:mm:ss");
		System.out.println(date);
		System.out.println(date2);
		System.out.println(getHoursDifference(date, date2));
	}
521923
function format(datetime, formatStr) {
  var t = getDateObject(datetime);
  var hours = undefined,
      o = undefined,
      i = 0;
  formatStr = formatStr || 'YYYY-MM-DD HH:mm:ss';
  hours = t.getHours();
  o = [['M+', t.getMonth() + 1], ['D+', t.getDate()],
  // H 24小时制
  ['H+', hours],
  // h 12小时制
  ['h+', hours > 12 ? hours - 12 : hours], ['m+', t.getMinutes()], ['s+', t.getSeconds()]];
  // 替换 Y
  if (/(Y+)/.test(formatStr)) {
    formatStr = formatStr.replace(RegExp.$1, (t.getFullYear() + '').substr(4 - RegExp.$1.length));
  }
  // 替换 M, D, H, h, m, s
  for (; i < o.length; i++) {
    if (new RegExp('(' + o[i][0] + ')').test(formatStr)) {
      formatStr = formatStr.replace(RegExp.$1, RegExp.$1.length === 1 ? o[i][1] : ('00' + o[i][1]).substr(('' + o[i][1]).length));
    }
  }
  // 替换 a/A 为 am, pm
  return formatStr.replace(/a/ig, hours > 11 ? 'pm' : 'am');
}
1097481
function(startDate, endDate) {
    var current = new Date(startDate);
    var end = new Date(endDate); 
    var dates = [];

    while(current <= end) {

        var m = current.getMonth() + 1;
        var d = current.getDate();
        var oneDate = [
            current.getFullYear(),
            m < 10 ? "0" + m : m,
            d < 10 ? "0" + d : d].join('-');

        dates.push(oneDate);
        current.setDate(current.getDate() + 1);
    }

    return dates;
}
1107617
function mysqlDate (input) {
	var date = new Date(input.getTime());
	date.setMinutes(date.getMinutes() + date.getTimezoneOffset());

	var y = date.getFullYear();
	var m = ('0' + (date.getMonth() + 1)).substr(-2);
	var d = ('0' + date.getDate()).substr(-2);
	var h = ('0' + date.getHours()).substr(-2);
	var i = ('0' + date.getMinutes()).substr(-2);
	var s = ('0' + date.getSeconds()).substr(-2);

	return y + '-' + m + '-' + d + ' ' + h + ':' + i + ':' + s;
}
668521
function closeCause (date) {
  date = this.toDate(date);
  if (!date) {
    return null;
  }
  var info = getDayInfo(this.dayInfo, date);
  if (info && info.open) {
    return '';
  }
  if (info && info.close) {
    return info.events[0] || '臨時休業';
  }
  var cause = this.isSeasonHoliday(date);
  if (cause) {
    return cause;
  }
  if (this.isRegularHoliday(date)) {
    return '定休日';
  }
  if (this.isHolidayClose(date)) {
    return this.getHolidayName(date);
  }
  return '';
}
725475
public static void sqlminute(StringBuilder buf, List<? extends CharSequence> parsedArgs) throws SQLException {
    singleArgumentFunctionCall(buf, "extract(minute from ", "minute", parsedArgs);
  }
843949
public void printDate(CharBuffer cb)
  {
    cb.append(DAY_NAMES[(int) (_dayOfEpoch % 7 + 11) % 7]);
    cb.append(", ");
    cb.append((_dayOfMonth + 1) / 10);
    cb.append((_dayOfMonth + 1) % 10);
    cb.append(" ");
    cb.append(MONTH_NAMES[(int) _month]);
    cb.append(" ");
    cb.append(_year);
    cb.append(" ");
    cb.append((_timeOfDay / 36000000L) % 10);
    cb.append((_timeOfDay / 3600000L) % 10);
    cb.append(":");
    cb.append((_timeOfDay / 600000L) % 6);
    cb.append((_timeOfDay / 60000L) % 10);
    cb.append(":");
    cb.append((_timeOfDay / 10000L) % 6);
    cb.append((_timeOfDay / 1000L) % 10);

    if (_zoneName == null || _zoneName.equals("GMT")) {
      cb.append(" GMT");
      return;
    }

    long offset = _zoneOffset;

    if (offset < 0) {
      cb.append(" -");
      offset = - offset;
    } else
      cb.append(" +");

    cb.append((offset / 36000000) % 10);
    cb.append((offset / 3600000) % 10);
    cb.append((offset / 600000) % 6);
    cb.append((offset / 60000) % 10);

    cb.append(" (");
    cb.append(_zoneName);
    cb.append(")");
  }
326834
function SimpleDate(){
    this._monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
    this._monthNamesShort = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];

    var tempDate = new Date();
    this.setYear(tempDate.getFullYear());
    this.setMonth(tempDate.getMonth());
    this.setDate(tempDate.getDate());

    if(arguments[0] != null) {
        if (arguments[0] instanceof Date) {
            tempDate = arguments[0];

            this.setYear(tempDate.getFullYear());
            this.setMonth(tempDate.getMonth());
            this.setDate(tempDate.getDate());
        } else if(arguments[0] instanceof SimpleDate) {
            this.setYear(arguments[0].getYear());
            this.setMonth(arguments[0].getMonth());
            this.setDate(arguments[0].getDate());
        } else if(arguments[0] instanceof Object) {
            var obj = arguments[0];
            if(obj.year != null && obj.month != null && obj.date != null) {
                this.setYear(obj.year);
                this.setMonth(obj.month);
                this.setDate(obj.date);
            } else {
                this.setYear(tempDate.getFullYear());
                this.setMonth(tempDate.getMonth());
                this.setDate(tempDate.getDate());
            }
        }else {
            try {
                this.setYear(parseInt(arguments[0]));
                this.setMonth(parseInt(arguments[1]));
                this.setDate(parseInt(arguments[2]));
            }catch(e) {
                this.setYear(tempDate.getFullYear());
                this.setMonth(tempDate.getMonth());
                this.setDate(tempDate.getDate());
            }
        }
    }
}
844947
def dates(self):
        ''' '''
        dates = []
        d = self.date_a
        while d < self.date_b:
            dates.append(d)
            d += datetime.timedelta(1)

        return dates
1315595
private void getWeeklyDates(Calendar calendar, int frequency, List<Date> dates)
   {
      int currentDay = calendar.get(Calendar.DAY_OF_WEEK);

      while (moreDates(calendar, dates))
      {
         int offset = 0;
         for (int dayIndex = 0; dayIndex < 7; dayIndex++)
         {
            if (getWeeklyDay(Day.getInstance(currentDay)))
            {
               if (offset != 0)
               {
                  calendar.add(Calendar.DAY_OF_YEAR, offset);
                  offset = 0;
               }
               if (!moreDates(calendar, dates))
               {
                  break;
               }
               dates.add(calendar.getTime());
            }

            ++offset;
            ++currentDay;

            if (currentDay > 7)
            {
               currentDay = 1;
            }
         }

         if (frequency > 1)
         {
            offset += (7 * (frequency - 1));
         }
         calendar.add(Calendar.DAY_OF_YEAR, offset);
      }
   }
596412
function stringToRegularHolidays (value) {
  var regular = {};
  value = value.split(',').map(x => x.trim());

  // 曜日
  regular.week = makeMap(getWeekIndex(value) || []);

  // 日
  var day = value.map(x => REG_NUM.test(x) ? x * 1 : 0)
                 .filter(x => 1 <= x && x <= 31);
  regular.day = makeMap(day);

  // 第nw曜日
  var xweek = value.map(x => {
    var m = x.match(REG_NUMYOBI);
    if (m) {
      var n = +m[1];
      n = 5 < n ? 5 : n;
      var w = getWeekIndex(m[2]);
      if (1 <= n && w !== null) {
        return n + '-' + w;
      }
    }
    return null;
  }).filter(x => x);
  regular.xweek = makeMap(xweek);
  return regular;
}
488238
def query_dated(num=8, kind='1'):
        '''
        
        '''
        return TabPost.select().where(
            TabPost.kind == kind
        ).order_by(
            TabPost.time_update.asc()
        ).limit(num)
1219326
function getRange(koyomi, range) {

  if (!range) {
    return dateToFyRange(koyomi);
  }

  // その日を含む月
  if (range instanceof Date) {
    return {
      year    : range.getFullYear(),
      month   : range.getMonth() + 1,
      endYear : range.getFullYear(),
      endMonth: range.getMonth() + 1
    };
  }

  // 年度指定
  if (typeof range === 'number' || /^\d{1,4}$/.test(range)) {
    return dateToFyRange(koyomi, range + '-' + koyomi.startMonth + '-1');
  }

  // Y/M-Y/Mの形式
  if (typeof range === 'string') {
    var m = range.match(REG_RANGE);
    if (m) {
      return {
        year    : +m[1],
        month   : +m[2],
        endYear : +m[3] || +m[1],
        endMonth: +m[4] || +m[2]
      };
    }
  }

  // 既定値
  return dateToFyRange(koyomi);
}
1356849
public static java.sql.Date getSqlDate(int year, int month, int date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(new java.util.Date(0));
        cal.set(Calendar.YEAR, year);
        cal.set(Calendar.MONTH, month - 1);
        cal.set(Calendar.DATE, date);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);

        return getSqlDate(cal.getTime());
    }
887318
public static Integer getRemainingDayOfMonth(Date date) {

        if (date == null)
            return null;

        // 月天数
        int days = getDayNumOfMonth(date);
        // 第几天
        int dayOfMonth = getDayOfMonth(date);

        return days - dayOfMonth;
    }
634198
function resetBizCache (date) {
  // 全キャッシュ削除
  if (!date) {
    this.bizCache = {};
    return true;
  }

  var cache = this.bizCache;

  // 年度キャッシュを全削除
  if (date === 'year') {
    Object.keys(cache).forEach(x=>{if(x.indexOf('-')===-1){delete cache[x];}});
    return true;
  }

  date = this.toDate(date);
  if (!date) {
    return false;
  }

  // 個別の日が含まれるキャッシュを削除
  var year = date.getFullYear();
  var month = date.getMonth() + 1;
  // 月キャッシュの削除
  delete cache[year + '-' + month];
  // 年度キャッシュの削除
  if (month < this.startMonth) {
    delete cache[year - 1];
  } else {
    delete cache[year];
  }

  return true;
}