Comments (3)
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.
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.
@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 DateTime
s.
from calecto.
Related Issues (20)
- Ecto cannot cast DateTime in query HOT 4
- 0.4.0 breaks my build HOT 10
- Mix task for adding Postgres type is broken HOT 3
- Rename Calecto.Model HOT 3
- Calendar.DateTime can't be used directly in queries HOT 5
- Integration tests HOT 1
- Hex dependency resolution failed HOT 4
- how to query HOT 5
- Issue with Ecto 2.0.0-rc4
- How to use timezone with timestamps(inserted_at, updated_at) columns? HOT 1
- Compile warnings HOT 2
- Update the hex package HOT 3
- Converting non-UTC timezones to UTC during cast HOT 4
- Duplicated modules HOT 15
- Casting from Calendar.DateTime to DateTimeUTC is not working at all HOT 5
- Unlock calendar
- Ecto 3.x.y dependency question HOT 5
- ecto3 branch: Calecto.DateTime does not conform to Ecto 3.5 Ecto.Type behavior HOT 4
- Quick licensing question HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from calecto.