@ovotech/avro-logical-types
Advanced tools
Comparing version 1.0.2 to 1.1.2
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const avsc_1 = require("avsc"); | ||
const millisecondsInADay = 8.64e7; | ||
const epoch_days_1 = require("./helpers/epoch-days"); | ||
/** | ||
@@ -10,6 +10,6 @@ * Custom logical type used to encode native Date objects as int. | ||
_fromValue(val) { | ||
return new Date(val * millisecondsInADay).toISOString(); | ||
return epoch_days_1.toDate(val).toISOString(); | ||
} | ||
_toValue(date) { | ||
return date instanceof Date ? Math.floor(date.getTime() / millisecondsInADay) : date; | ||
return epoch_days_1.fromDate(date); | ||
} | ||
@@ -16,0 +16,0 @@ _resolve(type) { |
export { DateType } from './DateType'; | ||
export { DateAsDateType } from './DateAsDateType'; | ||
export { DecimalType } from './DecimalType'; | ||
export { TimestampType } from './TimestampType'; | ||
export { TimestampAsDateType } from './TimestampAsDateType'; |
@@ -5,4 +5,10 @@ "use strict"; | ||
exports.DateType = DateType_1.DateType; | ||
var DateAsDateType_1 = require("./DateAsDateType"); | ||
exports.DateAsDateType = DateAsDateType_1.DateAsDateType; | ||
var DecimalType_1 = require("./DecimalType"); | ||
exports.DecimalType = DecimalType_1.DecimalType; | ||
var TimestampType_1 = require("./TimestampType"); | ||
exports.TimestampType = TimestampType_1.TimestampType; | ||
var TimestampAsDateType_1 = require("./TimestampAsDateType"); | ||
exports.TimestampAsDateType = TimestampAsDateType_1.TimestampAsDateType; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@ovotech/avro-logical-types", | ||
"description": "Some logical types for avsc", | ||
"version": "1.0.2", | ||
"version": "1.1.2", | ||
"main": "dist/index.js", | ||
@@ -36,3 +36,7 @@ "source": "src/index.ts", | ||
}, | ||
"gitHead": "08920fa2c6cc9a25f01f9de4c1b2283291d93b1b" | ||
"dependencies": { | ||
"decimal.js": "^10.2.0", | ||
"int64-buffer": "^0.99.1007" | ||
}, | ||
"gitHead": "b992ed1db9f1c046702b4749676be4773f99d20e" | ||
} |
@@ -35,2 +35,14 @@ # Avro Logical Types | ||
### Available Types | ||
**DateType**: Dates serialised as epoch days (number of days since epoch), deserialised as ISO String | ||
**DateAsDateType**: Dates serialised as epoch days (number of days since epoch), deserialised as an instance of `Date` | ||
**TimestampType**: Dates serialised as timestamp, deserialised as ISO String | ||
**TimestampAsDateType**: Dates serialised as timestamp, deserialised as an instance of `Date` | ||
**DecimalType**: Decimal, up to 64bit (or 63 bit signed), serialised as bytes, deserialised as an instance of [decimal.js](https://npmjs.com/decimal.js) | ||
## Running the tests | ||
@@ -37,0 +49,0 @@ |
import { Type, types } from 'avsc'; | ||
import { toDate, fromDate } from './helpers/epoch-days'; | ||
const millisecondsInADay = 8.64e7; | ||
/** | ||
@@ -10,6 +9,6 @@ * Custom logical type used to encode native Date objects as int. | ||
_fromValue(val: number) { | ||
return new Date(val * millisecondsInADay).toISOString(); | ||
return toDate(val).toISOString(); | ||
} | ||
_toValue(date: any) { | ||
return date instanceof Date ? Math.floor(date.getTime() / millisecondsInADay) : date; | ||
return fromDate(date); | ||
} | ||
@@ -16,0 +15,0 @@ _resolve(type: any) { |
export { DateType } from './DateType'; | ||
export { DateAsDateType } from './DateAsDateType'; | ||
export { DecimalType } from './DecimalType'; | ||
export { TimestampType } from './TimestampType'; | ||
export { TimestampAsDateType } from './TimestampAsDateType'; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
21003
31
359
76
3
1
+ Addeddecimal.js@^10.2.0
+ Addedint64-buffer@^0.99.1007
+ Addeddecimal.js@10.4.3(transitive)
+ Addedint64-buffer@0.99.1007(transitive)