Save a birthDate via qraphql in postgres - postgresql

I would like to save a birthdate from an (react) input (type = 'date'), send it via GraphQL to node backend and persist it in postgres in a date format.
Input in HTML: 09.07.2000
In GraphQL resolver: 2000-07-09T00:00:00.000Z
Date format in Postgres (original output in console): 09.07.2000
Well, that's what i expected. But now, if i request the same field:
Date format in Postgres (original output in console): 09.07.2000
Graphql response: 08.07.2000
HTML Input: 08.07.2000
If I change the scalar in graphQl schema to String, the following string returns: Fri Jul 09 2000 00:00:00 GMT+0200 (CEST)
Code
schema
scalar Date
type Child {
...
birthDate: Date
...
}
resolvers
const { GraphQLDate } = require('graphql-iso-date')
...
Date: GraphQLDate,
Problem
It looks like there is a problem in converting the date format from different timezones. If there is no timezone the scalar resolver guess a timezone. But this is a birthdate, it hast to be the same date on every timezone. How can I fix this? Do I have to use a string instead of date in prostgres?
Thanks for any support 🙏 I'm really lost
UPDATE
It looks like knex.js is the problem.
A normal SQL query responds the expected date. But a query with knex.js response a datetime.

Related

Converting from 'H:mm a' format back to DateTime can't be parsed

const date = DateTime.fromISO('2022-03-27T08:50').toFormat('H:mm a') // 08:50 AM
console.log(DateTime.fromISO(date))
If I attempt the above, in the console log I get this explanation in the 'invalid' field:
explanation: "the input "8:30 AM" can't be parsed as ISO 8601"
reason: "unparsable"
Is it not possible to revert the string back to a date?
You can parse back "8:30 AM" as DateTime using fromFormat:
Create a DateTime from an input string and format string. Defaults to en-US if no locale has been specified, regardless of the system's locale. For a table of tokens and their interpretations, see here.
but the information about year, month and day are lost and so the new DateTime will default to the current day.
Example:
const DateTime = luxon.DateTime;
const date = DateTime.fromISO('2022-03-27T08:50').toFormat('H:mm a') // 8:50 AM
console.log(DateTime.fromFormat(date, 'h:mm a').toISO())
<script src="https://cdn.jsdelivr.net/npm/luxon#2.3.1/build/global/luxon.min.js"></script>

Persisting time with timezone offset in mongodb with nestjs

I have a nestjs application which has a very date heavy schema.
According to my understanding date is stored in mongo without timezone. My API accepts time in ISO format with timezone offset.
Inserting following object {"date": "2009-06-30T18:30:00+11:00"}
will result in following document in the mongo database {date: ISODate('2009-06-30T07:30:00.000Z'), _id: "..."}
So the timezone offset is lost.
Is there an elegant way to keep the timezone offset and deliver the ISO string with the same offset on an GET request? Maybe make use of the class-transformer and store the offset in a separate property? If yes, how?
Here are the involved classes. (There is a dedicated ItemDto for GET requests which is not shown here.)
Dto:
export class CreateItemDto {
// Some other props are here
/**
* Date of this Information.
* #example "1900-01-01T05:00:00.000+05:00"
*/
#IsNotEmpty()
#IsDate()
#Type(() => Date)
date: Date;
}
Schema:
export class ItemSchema {
// Some other props are here
#Prop({ type: Date, required: true })
date!: Date;
}
In many cases the client application will convert and display the time in current local time zone, no matter in which time zone the timestamp was inserted.
If this is not sufficient for you then you have to store the time zone information in a separate field along with the actual timestamp.

Rails Add TimeStamp to DatePicker Date From Form

I'm using rails 5.2.4.4 and ruby 2.6.4
I'm using the JQuery DatePicker on a form. It is giving me a date in the format: mm/dd/YYYY. What I need to do is add a time-stamp to that so I can make the date look like 01/12/2021 23:23:59. I thought I could add the end_of_day method in a before_hook call, but rails does not like that:
# in model:
validates :end_date, :presence => true
before_save :set_end_date_timestamp
def set_end_date_timestamp
if self.end_date?
self.end_date.end_of_day!
end
end
That gives me an error: NoMethodError (undefined method 'end_of_day!' for Tue, 12 Jan 2021 00:00:00 EST -05:00:Time)
What am I doing wrong? And, what is the most railsie way to accomplish this?
Found this:
<script>
// make date format user friendly: mm/dd/yyyy
$("#course_swap_request_date_start_date").datepicker(
{ dateFormat: "mm/dd/yy 00:00:01" }
);
$("#course_swap_request_date_end_date").datepicker(
{ dateFormat: "mm/dd/yy 23:59:59" }
);
</script>
For my specific app, I need to set the start_date timestamp to 00:00:01 and the end_date timestamp to 23:59:59. I could not get beginning_of_day and end_of_day to work. Since DatePicker allows us to set the timestamp this way, it was an easy way to do this, albeit a bit of a cheap-hack.

How to assign current date to a date field in odoo 10

How to show current date before clicking the date field in odoo?
Odoo Date field class provides methods to get default values for like today.
For dates the method is called context_today() and for datetimes context_timestamp(). You are able to pass a timestamp to this methods to either get today/now (without timestamp) or a timestamp which will be formed by the logged in users timezone.
Code Example:
from odoo import fields, models
class MyModel(models.Model):
_name = 'my.model'
def _default_my_date(self):
return fields.Date.context_today(self)
my_date = fields.Date(string='My Date', default=_default_my_date)
Or the lambda version:
my_date = fields.Date(
string='My Date', default=lambda s: fields.Date.context_today(s))
I found it.It is Simple, just write this on your python code like:
date = fields.Datetime(string="Date", default=lambda *a: datetime.now(),required=True)
or
like this
date = fields.Datetime(string="Date current action", default=lambda *a: datetime.now())
or
like this
date = fields.Date(default=fields.Date.today)

UTC formatted string time to local time in Word

I have a Document Property that stores a DateTime in the UTC format.
For example:
2017-08-23T11:42:55.1094139Z
Now I would like to display this DateTime in my Word Document, there for I use the following field:
{ DOCPROPERTY LAST_UPDATED }
(FYI: LAST_UPDATED isnt the DateTime the file was last modified, but the last time the user clicked a sync button of my addin)
This will display the string as is, so in the UTC format.
I hoped that the following, would turn the UTC into the local DateTime.
{ DOCPROPERTY LAST_UPDATED \# "dd.MM.yyyy HH:mm:ss" }
but sadly, it ignores the CurrentCulture/LocalTimeZone completly and just displays it as
23.08.2017 11:42:55
Instead of the desired
23.08.2017 13:42:55
How can I achieve my goal? Store a DateTime in my Word Document that is independet of Region/TimeZones and let it display the local time?