Skip to content

Instantly share code, notes, and snippets.

@thinca
Created June 15, 2014 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thinca/bd5f71bab74c640022a7 to your computer and use it in GitHub Desktop.
Save thinca/bd5f71bab74c640022a7 to your computer and use it in GitHub Desktop.
let s:assert = themis#helper('assert')
let s:from_format = themis#suite('DateTime.from_format')
function! s:from_format.before()
let self.DT = vital#of('vital').import('DateTime')
endfunction
let s:from_format.title._01 = 'makes a DateTime object from formatted string'
function! s:from_format._01()
let dt = self.DT.from_format('2012-1-02T03:04:05Z', '%Y-%m-%dT%H:%M:%SZ%z')
call s:assert.same(dt.year(), 2012)
call s:assert.same(dt.month(), 1)
call s:assert.same(dt.day(), 2)
call s:assert.same(dt.hour(), 3)
call s:assert.same(dt.minute(), 4)
call s:assert.same(dt.second(), 5)
call s:assert.same(dt.timezone().offset(), 0)
endfunction
let s:from_format.title._02 = 'can treat the some format specifier'
function! s:from_format._02()
let dt = self.DT.from_format('02 Jan 2012 03:04:05 +0900', '%d %b %Y%n%H:%M:%S%n%z', 'C')
call s:assert.same(dt.year(), 2012)
call s:assert.same(dt.month(), 1)
call s:assert.same(dt.day(), 2)
call s:assert.same(dt.hour(), 3)
call s:assert.same(dt.minute(), 4)
call s:assert.same(dt.second(), 5)
call s:assert.same(dt.timezone().hours(), 9)
endfunction
let s:from_format.title._03 = 'can skip any text by %*'
function! s:from_format._03()
let dt = self.DT.from_format('2011-01-03T10:16:46.297581Z', '%Y-%m-%dT%H:%M:%S%*Z%z', 'C')
call s:assert.same(dt.year(), 2011)
call s:assert.same(dt.month(), 1)
call s:assert.same(dt.day(), 3)
call s:assert.same(dt.hour(), 10)
call s:assert.same(dt.minute(), 16)
call s:assert.same(dt.second(), 46)
call s:assert.same(dt.timezone().hours(), 0)
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment