Giter Site home page Giter Site logo

Loading / Encoding issues. about calecto HOT 3 CLOSED

lau avatar lau commented on August 25, 2024
Loading / Encoding issues.

from calecto.

Comments (3)

lau avatar lau commented on August 25, 2024

Hi @benwilson512

Is that when inserting?

What type do you have in your migration for the field where the type is Calecto.DateTime in the schema? This one should work for the migration: :calendar_datetime.

It requires a migration to be run as described in https://github.com/lau/calecto#datetime-with-postgres that adds the calendar_datetime type to the postgres database.

I can insert using
:calecto, "0.17.0", :ecto, "2.2.10", Elixir 1.7.2

from calecto.

benwilson512 avatar benwilson512 commented on August 25, 2024

Hey @lau this is indeed when inserting. The migration I used :timestampz which produced a TIMESTAMP WITH TIMEZONE column type if I look at the table in postgresql.

From your link I'm realizing that this is maybe not what Calect.DateTime expects, does it use a custom database column type?

from calecto.

lau avatar lau commented on August 25, 2024

@benwilson512 Yes, Calecto.DateTime requires a custom database column type. See https://github.com/lau/calecto#the-types
and https://github.com/lau/calecto#datetime-with-postgres

Postgres' "TIMESTAMP WITH TIMEZONE" is not a well named type. One might think that it saves the timezone. It does not. Whatever you save is converted to UTC and saved in UTC. When you read it back from postgres postgres has no idea what timezone it was because the timezone was not saved. So I do not think it is appropriate if you want to have the timezone saved. If all you want to save is UTC DateTimes I would recommend using Ecto's :utc_datetime in the Ecto schema. I think this works with columns created in postgres as timestampz as well. If you use :timestampz I would recommend making sure that the database server and the servers talking to the database always have their time zone set to UTC.

If you want to save datetimes with timezones that are not solely UTC you can use Calecto's custom type. It is a composite type. For Ecto 2.1+ and Elixir 1.3+ this type is the main reason to still use Calecto since Ecto now has a built in equivalent for all of the others. Alternatively you could use two simple fields: a :naive_datetime plus a string with the timezone id e.g. "America/New_York" but then you would have to do some more work yourself when inserting and retrieving them as DateTimes.

from calecto.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.