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

Fixing date to time conversion #94

Merged
merged 2 commits into from
Aug 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions __tests__/dataframe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1575,6 +1575,23 @@ describe("io", () => {
const actual = df.toRecords();
expect(actual).toEqual(expected);
});
test("toRecords:date", () => {
const df = pl
.DataFrame({
date: [new Date()],
})
.withColumn(pl.col("date").cast(pl.Date).alias("date"));
const dt = new Date();
const expected = [
{
date: new Date(
Date.UTC(dt.getFullYear(), dt.getMonth(), dt.getDate(), 0, 0, 0, 0),
),
},
];
const actual = df.toRecords();
expect(JSON.stringify(actual)).toEqual(JSON.stringify(expected));
});
test("toObject", () => {
const expected = {
foo: [1],
Expand Down
5 changes: 4 additions & 1 deletion src/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,11 @@ impl<'a> ToNapiValue for Wrap<AnyValue<'a>> {
AnyValue::Date(v) => {
let mut ptr = std::ptr::null_mut();

// Multiple days to get to Epoch time
let epoch_time: f64 = (v as f64) * 86400000.0;

check_status!(
napi::sys::napi_create_date(env, v as f64, &mut ptr),
napi::sys::napi_create_date(env, epoch_time as f64, &mut ptr),
Bidek56 marked this conversation as resolved.
Show resolved Hide resolved
"Failed to convert rust type `AnyValue::Date` into napi value",
)?;

Expand Down
Loading