Skip to content

Commit

Permalink
Merge branch 'develop' into pu/scopedNE
Browse files Browse the repository at this point in the history
  • Loading branch information
izulin committed Apr 26, 2021
2 parents 773c727 + c223cd0 commit 0b6ff87
Show file tree
Hide file tree
Showing 11 changed files with 410 additions and 274 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Fixed issues with scoped named expression. (#646, #641)

### Fixed
- Fixed an issue with losing formating info about DateTime numbers. (#626)

## [0.5.0] - 2021-04-15

### Changed
Expand Down
13 changes: 10 additions & 3 deletions src/CellContentParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ import {Config} from './Config'
import {DateTimeHelper} from './DateTimeHelper'
import {UnableToParseError} from './errors'
import {fixNegativeZero, isNumberOverflow} from './interpreter/ArithmeticHelper'
import {cloneNumber, CurrencyNumber, ExtendedNumber, getRawValue, PercentNumber} from './interpreter/InterpreterValue'
import {
cloneNumber,
CurrencyNumber,
DateNumber,
ExtendedNumber,
getRawValue,
PercentNumber
} from './interpreter/InterpreterValue'
import {Maybe} from './Maybe'
import {NumberLiteralHelper} from './NumberLiteralHelper'

Expand Down Expand Up @@ -127,11 +134,11 @@ export class CellContentParser {
} else if (typeof content === 'boolean') {
return new CellContent.Boolean(content)
} else if (content instanceof Date) {
return new CellContent.Number(this.dateHelper.dateToNumber({
return new CellContent.Number(new DateNumber(this.dateHelper.dateToNumber({
day: content.getDate(),
month: content.getMonth() + 1,
year: content.getFullYear()
}))
}), 'Date()'))
} else if (typeof content === 'string') {
if (isBoolean(content)) {
return new CellContent.Boolean(content.toLowerCase() === 'true')
Expand Down
16 changes: 8 additions & 8 deletions src/DateTimeHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,19 @@ export class DateTimeHelper {
}

public dateStringToDateNumber(dateTimeString: string): Maybe<ExtendedNumber> {
const dateTime = this.parseDateTimeFromConfigFormats(dateTimeString)
const {dateTime, dateFormat = '', timeFormat = ''} = this.parseDateTimeFromConfigFormats(dateTimeString)
if(dateTime === undefined) {
return undefined
}
if(instanceOfSimpleTime(dateTime)) {
if(instanceOfSimpleDate(dateTime)) {
return new DateTimeNumber(timeToNumber(dateTime) + this.dateToNumber(dateTime) )
return new DateTimeNumber(timeToNumber(dateTime) + this.dateToNumber(dateTime), dateFormat + ' ' + timeFormat)
} else {
return new TimeNumber(timeToNumber(dateTime))
return new TimeNumber(timeToNumber(dateTime), timeFormat)
}
} else {
if(instanceOfSimpleDate(dateTime)) {
return new DateNumber( this.dateToNumber(dateTime) )
return new DateNumber( this.dateToNumber(dateTime), dateFormat)
} else {
return 0
}
Expand All @@ -108,21 +108,21 @@ export class DateTimeHelper {
return dateTime
}

public parseDateTimeFromConfigFormats(dateTimeString: string): Maybe<DateTime> {
public parseDateTimeFromConfigFormats(dateTimeString: string): Partial<{dateTime: DateTime, dateFormat: string, timeFormat: string}> {
return this.parseDateTimeFromFormats(dateTimeString, this.config.dateFormats, this.config.timeFormats)
}
private parseDateTimeFromFormats(dateTimeString: string, dateFormats: string[], timeFormats: string[]): Maybe<DateTime> {
private parseDateTimeFromFormats(dateTimeString: string, dateFormats: string[], timeFormats: string[]): Partial<{dateTime: DateTime, dateFormat: string, timeFormat: string}> {
const dateFormatsIterate = dateFormats.length===0 ? [undefined] : dateFormats
const timeFormatsIterate = timeFormats.length===0 ? [undefined] : timeFormats
for (const dateFormat of dateFormatsIterate) {
for (const timeFormat of timeFormatsIterate) {
const dateTime = this.parseSingleFormat(dateTimeString, dateFormat, timeFormat)
if (dateTime !== undefined) {
return dateTime
return {dateTime, timeFormat, dateFormat}
}
}
}
return undefined
return {}
}

public getNullYear() {
Expand Down
Loading

0 comments on commit 0b6ff87

Please sign in to comment.