67 howm-mode.vim (2-35) HowmDateTime2Int() ã®ä½æ
ãã§ã¯ããã¡ãã«30åç ®è¾¼ãã ãã®ããã
ã¨ãããã¨ã§ããããªãã ãã© HowmDateTime2Int() ãä½ã£ãã以åããã¼ãã¼ãè¨ã£ã¦ãæååããæ¥ä»ãããããæ°å¤ã¸ã®å¤æãã¿ã¤ã ã¾ã¼ã³ã¾ããã¨ãããªãé©å½ãhowm_timezone_hour, howm_timezone_min ã§ã¿ã¤ã ã¾ã¼ã³ã«é¢ããä¿®æ£ãè¡ããã§ããããã«ãã£ã¦ããã¨ã¯ã¡ã£ã¡ãããæ£è¦è¡¨ç¾ã§ã²ã£ã±ãã ãã¦æ£ããã確èªãã¦è¶³ãã¦ãã ããèå¿ãªæ°å¤å¤æã®é¨å㯠HowmDate2Int() ã§ä½¿ããã¦ãããæ¢åã®ãã®ãå©ç¨ãã¦ããã®ã§ããã¡ããæ£ããåãã¦ããã°ãã¾ãåãã¯ãã
" 注æ: HowmDate2Int() ã¨ã¯åºæºæ¥æãè¿ãå¤ã®ç¨®é¡ãéã " " format ã«ãããã£ã¦æ¸ãããæ¥ä» date ã解éã ( TimeZone ãèæ ®ãã ), " 1970-01-01 00:00:00 ããã®çµéç§æ°ãè¿ã. " 1970-01-01 00:00:00 以åã, " 2038-01-01 00:00:00 以éã®ãã¼ã¿ã®å ´å㯠-1 ãè¿ã. " ãã®ä», 解éã§ããªãã£ãå ´åã -1 ãè¿ã. " æ¢å®å¤: å¹´:1970, æ:1, æ¥:1, æ:0, å:0, ç§:0, TimeZone:+09:00 function! HowmDateTime2Int(datetime, format) " TimeZone ã®è¨å® if !exists('g:howm_timezone_hour') || \ g:howm_timezone_hour < -12 || 13 < g:howm_timezone_hour let tz_hour = 9 endif if !exists('g:howm_timezone_min') || \ g:howm_timezone_min < 0 || 59 < g:howm_timezone_min let tz_min = 0 endif let format = '\V' . escape(a:format, '\') let format = substitute(format, '\C%F', escape('%Y-%m-%d', '\~&'), 'g') let format = substitute(format, '\C%T', escape('%H:%M:%S', '\~&'), 'g') let format = substitute(format, '\C%R', escape('%H:%M', '\~&'), 'g') let pat = format let pat = substitute(pat, '\C%Y', escape('\m\d\{4}\V', '\~&'), 'g') let pat = substitute(pat, '\C%m', escape('\m\d\{2}\V', '\~&'), 'g') let pat = substitute(pat, '\C%d', escape('\m\d\{2}\V', '\~&'), 'g') let pat = substitute(pat, '\C%H', escape('\m\d\{2}\V', '\~&'), 'g') let pat = substitute(pat, '\C%M', escape('\m\d\{2}\V', '\~&'), 'g') let pat = substitute(pat, '\C%S', escape('\m\d\{2}\V', '\~&'), 'g') if a:datetime !~ pat | return -1 | endif let date_pat = pat " %Y if format !~# '%Y' let year = 1970 else let pat = format let pat = substitute(pat, '\C%Y', escape('\m\(\d\{4}\)\V', '\~&'), 'g') let pat = substitute(pat, '\C%m', escape('\m\d\{2}\V', '\~&'), 'g') let pat = substitute(pat, '\C%d', escape('\m\d\{2}\V', '\~&'), 'g') let pat = substitute(pat, '\C%H', escape('\m\d\{2}\V', '\~&'), 'g') let pat = substitute(pat, '\C%M', escape('\m\d\{2}\V', '\~&'), 'g') let pat = substitute(pat, '\C%S', escape('\m\d\{2}\V', '\~&'), 'g') let year = substitute(a:datetime, pat, '\1', 'g') + 0 if year < 1970 || 2038 <= year | return -1 | endif endif " ec 'year: ' . year " %m if format !~# '%m' let month = 1 else let pat = format let pat = substitute(pat, '\C%Y', escape('\m\d\{4}\V', '\~&'), 'g') let pat = substitute(pat, '\C%m', escape('\m\(\d\{2}\)\V', '\~&'), 'g') let pat = substitute(pat, '\C%d', escape('\m\d\{2}\V', '\~&'), 'g') let pat = substitute(pat, '\C%H', escape('\m\d\{2}\V', '\~&'), 'g') let pat = substitute(pat, '\C%M', escape('\m\d\{2}\V', '\~&'), 'g') let pat = substitute(pat, '\C%S', escape('\m\d\{2}\V', '\~&'), 'g') let month = substitute(a:datetime, pat, '\1', 'g') + 0 if month < 1 || 12 < month | return -1 | endif endif " ec 'month: ' . month " %d if format !~# '%d' let day = 1 else let pat = format let pat = substitute(pat, '\C%Y', escape('\m\d\{4}\V', '\~&'), 'g') let pat = substitute(pat, '\C%m', escape('\m\d\{2}\V', '\~&'), 'g') let pat = substitute(pat, '\C%d', escape('\m\(\d\{2}\)\V', '\~&'), 'g') let pat = substitute(pat, '\C%H', escape('\m\d\{2}\V', '\~&'), 'g') let pat = substitute(pat, '\C%M', escape('\m\d\{2}\V', '\~&'), 'g') let pat = substitute(pat, '\C%S', escape('\m\d\{2}\V', '\~&'), 'g') let day = substitute(a:datetime, pat, '\1', 'g') + 0 if day < 1 || 31 < day | return -1 | endif if 28 < day if month =~ '^\%(\<2\|4\|6\|9\|11\)$' && 30 < day | return -1 | endif if month == '2' if (year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0)) if 29 < day | return -1 | endif else if 28 < day | return -1 | endif endif endif endif endif " ec 'day: ' . day " %H if format !~# '%H' let hour = 0 else let pat = format let pat = substitute(pat, '\C%Y', escape('\m\d\{4}\V', '\~&'), 'g') let pat = substitute(pat, '\C%m', escape('\m\d\{2}\V', '\~&'), 'g') let pat = substitute(pat, '\C%d', escape('\m\d\{2}\V', '\~&'), 'g') let pat = substitute(pat, '\C%H', escape('\m\(\d\{2}\)\V', '\~&'), 'g') let pat = substitute(pat, '\C%M', escape('\m\d\{2}\V', '\~&'), 'g') let pat = substitute(pat, '\C%S', escape('\m\d\{2}\V', '\~&'), 'g') let hour = substitute(a:datetime, pat, '\1', 'g') + 0 if hour < 0 || 23 < hour | return -1 | endif endif " ec 'hour: ' . hour " %M if format !~# '%M' let min = 0 else let pat = format let pat = substitute(pat, '\C%Y', escape('\m\d\{4}\V', '\~&'), 'g') let pat = substitute(pat, '\C%m', escape('\m\d\{2}\V', '\~&'), 'g') let pat = substitute(pat, '\C%d', escape('\m\d\{2}\V', '\~&'), 'g') let pat = substitute(pat, '\C%H', escape('\m\d\{2}\V', '\~&'), 'g') let pat = substitute(pat, '\C%M', escape('\m\(\d\{2}\)\V', '\~&'), 'g') let pat = substitute(pat, '\C%S', escape('\m\d\{2}\V', '\~&'), 'g') let min = substitute(a:datetime, pat, '\1', 'g') + 0 if min < 0 || 59 < min | return -1 | endif endif " ec 'min: ' . min " %S if format !~# '%S' let sec = 0 else let pat = format let pat = substitute(pat, '\C%Y', escape('\m\d\{4}\V', '\~&'), 'g') let pat = substitute(pat, '\C%m', escape('\m\d\{2}\V', '\~&'), 'g') let pat = substitute(pat, '\C%d', escape('\m\d\{2}\V', '\~&'), 'g') let pat = substitute(pat, '\C%H', escape('\m\d\{2}\V', '\~&'), 'g') let pat = substitute(pat, '\C%M', escape('\m\d\{2}\V', '\~&'), 'g') let pat = substitute(pat, '\C%S', escape('\m\(\d\{2}\)\V', '\~&'), 'g') let sec = substitute(a:datetime, pat, '\1', 'g') + 0 if sec < 0 || 59 < sec | return -1 | endif endif " ec 'sec: ' . sec " 719527 : HowmDate2Int('1970-01-01', '%Y-%m-%d') " 86400 : 60 * 60 * 24 let retval = (s:ymd2int(year, month, day) - s:ymd2int(1970, 1, 1)) * 86400 if format =~# '%H' || format =~# '%M' || format =~# '%S' " TimeZone ãèæ ® let retval = retval + hour * 60 * 60 - (tz_hour * 60 * 60) if tz_hour > 0 let retval = retval + min * 60 + (tz_min * 60) else let retval = retval + min * 60 - (tz_min * 60) endif end let retval = retval + sec if retval < 0 | return -1 | endif " echo strftime('%Y-%m-%d %H:%M:%S', retval) return retval endfunction