Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support formating with '\n' #1417

Merged
merged 1 commit into from Sep 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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