Skip to content

Commit

Permalink
Support formating with '\n'
Browse files Browse the repository at this point in the history
  • Loading branch information
CarterLi committed Sep 12, 2019
1 parent c450fe2 commit b7567b2
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/format/index.js
Expand Up @@ -29,7 +29,7 @@ var formattingTokensRegExp = /[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)
// sequences of symbols P, p, and the combinations like `PPPPPPPppppp`
var longFormattingTokensRegExp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g

var escapedStringRegExp = /^'(.*?)'?$/
var escapedStringRegExp = /^'([^]*?)'?$/
var doubleQuoteRegExp = /''/g
var unescapedLatinCharacterRegExp = /[a-zA-Z]/

Expand Down
5 changes: 5 additions & 0 deletions src/format/test.js
Expand Up @@ -50,6 +50,11 @@ describe('format', function() {
assert(format(date, "''h 'o''clock'''") === "'5 o'clock'")
})

it('accepts new line charactor', function() {
var date = new Date(2014, 3, 4, 5)
assert.equal(format(date, "yyyy-MM-dd'\n'HH:mm:ss"), '2014-04-04\n05:00:00')
})

describe('ordinal numbers', function() {
it('ordinal day of an ordinal month', function() {
var result = format(date, "do 'day of the' Mo 'month of' yyyy")
Expand Down
2 changes: 1 addition & 1 deletion src/lightFormat/index.js
Expand Up @@ -15,7 +15,7 @@ import subMilliseconds from '../subMilliseconds/index.js'
// - . matches any single character unmatched by previous parts of the RegExps
var formattingTokensRegExp = /(\w)\1*|''|'(''|[^'])+('|$)|./g

var escapedStringRegExp = /^'(.*?)'?$/
var escapedStringRegExp = /^'([^]*?)'?$/
var doubleQuoteRegExp = /''/g
var unescapedLatinCharacterRegExp = /[a-zA-Z]/

Expand Down
8 changes: 8 additions & 0 deletions src/lightFormat/test.js
Expand Up @@ -22,6 +22,14 @@ describe('lightFormat', () => {
assert(lightFormat(date, "''h 'o''clock'''") === "'5 o'clock'")
})

it('accepts new line charactor', function() {
var date = new Date(2014, 3, 4, 5)
assert.equal(
lightFormat(date, "yyyy-MM-dd'\n'HH:mm:ss"),
'2014-04-04\n05:00:00'
)
})

describe('year', () => {
describe('regular year', () => {
it('works as expected', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/parse/index.js
Expand Up @@ -31,7 +31,7 @@ var formattingTokensRegExp = /[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)
// sequences of symbols P, p, and the combinations like `PPPPPPPppppp`
var longFormattingTokensRegExp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g

var escapedStringRegExp = /^'(.*?)'?$/
var escapedStringRegExp = /^'([^]*?)'?$/
var doubleQuoteRegExp = /''/g

var notWhitespaceRegExp = /\S/
Expand Down
9 changes: 9 additions & 0 deletions src/parse/test.js
Expand Up @@ -20,6 +20,15 @@ describe('parse', function() {
assert.deepEqual(result, new Date(1986, 3 /* Apr */, 4, 5))
})

it('accepts new line charactor', function() {
var result = parse(
'2014-04-04\n05:00:00',
"yyyy-MM-dd'\n'HH:mm:ss",
backupDate
)
assert.deepEqual(result, new Date(2014, 3 /* Apr */, 4, 5))
})

describe('era', function() {
it('abbreviated', function() {
var result = parse('10000 BC', 'yyyyy G', backupDate)
Expand Down

0 comments on commit b7567b2

Please sign in to comment.