Sequelize Multiple TimeZone issue - sql

The Column name CreatedAt has SMALLDATETIME datatype and
I'm saving value as CreatedAt = dayjs().format('YYYY-MM-DD HH:mm:ss')
It's working fine.
But the real issue is that my application provides the user to select his timezone. when the user is selecting any timezone, I want to show the date in that timezone.
I'm using this to convert in the user timezone.
dayjs(user.CreatedAt)
.tz(tz)
.format('YYYY-MM-DDTHH:mm:ssZ')
here tz can use Asia/Kolkata to US/Eastern.
But It's showing the wrong time.
I've tried this but nothing happens
{
host: config.DATABASE_HOST,
dialect: config.DATABASE_DIALECT,
dialectOptions: {
options: { requestTimeout: 3000000, useUTC: true },
},
pool: {
max: 5,
min: 0,
acquire: 30000,
idle: 10000,
},
logging: true,
timezone: '-05:00', // US/Eastern TimeZone
}
Can someone help me with this?

Related

Nodejs converts database time to UTC format without actually converting the date

In My database, I have following values for a column:
created_at: 2018-11-29 00:24:33.967124
But when I query this column to get its data in nodeJS, it returns following data:
created_at: 2018-11-29T00:24:33.967124Z
I do not know who is the culprit here, if it is nodejs/ postgres or timezone.
To explain more here is my query:
let query = "Select created_at from my_table limit 1";
let tableData = await runQuery(query);
console.log(tableData);
Output:
[{ created_at: 2018-11-28T19:24:20.946Z }]
So I do not want node to convert/ format this data and retun the data as it is from database. How I can do that or what I am doing wrong.
Those are the same. Timestamp with zero timezone is the same as timestamp without timezone. And Node.js driver will always give you timestamps with timezone.
const a = Date.parse('2018-11-29T00:24:33.967124Z');
const b = Date.parse('2018-11-29 00:24:33.967124');
console.log(a); //=> 1543451073967
console.log(b); //=> 1543451073967
console.log(a === b); //=> true

How to display UTC time in vega-tooltip "version": "0.5.1",

I use "utc" vega scale in order to display data in UTC time, but when I hover an item in the chart then tooltip show a date in local format. How to display UTC data in vega tooltip?
Here is vega tooltip config
let options = {
showAllFields: false,
fields: [
{
field: "x",
title: "Time",
formatType: "time",
format: "%x %X "+ this.props.data.Timezone
},
{
field: "y",
title: "Value",
formatType: "number"
},
{
field: "value",
title: "Time",
formatType: "time",
format: "%x %X "+this.props.data.Timezone
},
{
field: "label",
title: "Data",
formatType: "string"
},
{
field: "info",
title: "Info",
formatType: "string"
},
{
field: "startTime",
title: "Start",
formatType: "time",
format: "%x %X "+this.props.data.Timezone
},
{
field: "endTime",
title: "End",
formatType: "time",
format: "%x %X "+this.props.data.Timezone
}
]
}
vegaTooltip.vega(vegaView, options);
I can't judge about the data of dates you ingest, but this was discussed recently in https://github.com/altair-viz/altair/pull/1053.
The core of the matter is that you'll have to parse your datetime data in ISO-8601 standard to make your browser parse it as UTC, if you parse your data in a different format it will assumes local time zone:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse
Differences in assumed time zone
Given a date string of "March 7, 2014", parse() assumes a local time
zone, but given an ISO format such as "2014-03-07" it will assume a
time zone of UTC (ES5 and ECMAScript 2015). Therefore Date objects
produced using those strings may represent different moments in time
depending on the version of ECMAScript supported unless the system is
set with a local time zone of UTC. This means that two date strings
that appear equivalent may result in two different values depending on
the format of the string that is being converted.

Eventbrite giving response " wrong datetime format" on hitting event/ endpoint

I am writing a script in python to create an event.Newbie at this.Below is the entire script code for reference.
import requests,json
from datetime import datetime
event={}
event['name']={}
print("Enter the following:\ntitle of event")
event['name']['html']=input()
event['description']={}
event['description']['html']=input("Event description:\n")
event['start']={}
startdate=datetime.strptime(input("start datetime eg :Jun 1 2005 1:33PM :\n"),'%b %d %Y %I:%M%p')
event['start']['utc']=str(startdate.date())+'T'+str(startdate.time())+'Z'
#event['start']['utc']=startdate.isoformat()+"Z"
#Turning datetime in YYYY-MM-DDThh:mm:ssZ format
event['start']['timezone']=input("timezone eg Asia/kolkata\n")
event['end']={}
enddate=datetime.strptime(input("end datetime eg :Jun 1 2005 1:33PM\n"),'%b %d %Y %I:%M%p')
event['end']['utc']=str(enddate.date())+'T'+str(enddate.time())+'Z'
#event['end']['utc']=enddate.isoformat()+"Z"
event['end']['timezone']=event['start']['timezone']
event['currency']=input("3 letter code")
response = requests.post("https://www.eventbriteapi.com/v3/events/",
headers = {
"Authorization": "Bearer NC.....",
"Content-Type" : "application/json"
},
data=json.dumps({"event":event}),
verify = True, # Verify SSL certificate
)
Strictly followed the docs https://www.eventbrite.com/developer/v3/endpoints/events/
According to docs datatype of event.start.utc and event.start.end data shall be datetime i.e "2010-01-31T13:00:00Z"
We can see in the comments I also tried with isoformat function.
On printing event object I found the same format as specified in the docs.
But receiving response.content as event.start invalid argument or event.start.utc as datetime wrong format use instead "YYYY-MM-DDThh:mm:ssZ" !!
I ran into date issues with Eventbrite too; after debugging found this to work for events:
{ event:
{ name: { html: 'Postman API Event!' },
description:
{ html: 'My fav event is The Winter Formal.' },
start: { timezone: 'America/Los_Angeles', utc: '2018-09-06T00:19:53Z' },
currency: 'USD',
listed: false,
end: { timezone: 'America/Los_Angeles', utc: '2018-09-06T00:20:53Z' } } }
and of course, different date formats in another part of API ;-)
Regarding discounts / cross event discount, where the docs specify a
Naive Local ISO8601 date and time format
First I've heard of the 'Naive' format? Why no example Eventbrite? Here's what worked:
2018-10-11T12:13:14

date format with extjs 4 not rendering in date picker

I have the following date picker
{
xtype: 'datefield',
id: 'FinalDespatchDate',
name: 'FinalDespatchDate',
fieldLabel: 'Part Despatch Date',
labelWidth: 150,
width: 370,
validateOnChange: false,
format: 'd/m/Y'
},
In my model i have
{
mapping:'FinalDespatchDate',
name:'FinalDespatchDate',
type: 'date',
dateFormat:'d/m/Y'
},
if in my model i don't include the dateFormat. The date binds to my date picker but it sends the date in an incorrect format. When i add dateFormat it sends the date in the correct format it just no longer binds to the datepicker. ie the above configuration display nothing in the date picker
Does your data come from server with properly formatted date value ('d/m/Y') in this (non-working) configuration?

Loading date/time into Sencha Touch Model

I'm using Sencha Touch 1.1. I have the following model and store:
Ext.regModel(TrafficResponse.Models.IncidentReports, {
idProperty: 'Id',
fields: [
{name: 'Id', type: 'int'},
{name: 'TMCRequestedTime', type: 'date'},
{name: 'TRUDetectedTime', type: 'date'},
{name: 'SiteArrivalTime', type: 'date'},
{name: 'SiteDepartedTime', type: 'date'}
],
proxy: {
type: 'localstorage',
id: TrafficResponse.Stores.IncidentReports
},
writer: {
type: 'json'
}
});
truApp.stores.incidentReportStore = new Ext.data.Store({
model: TrafficResponse.Models.IncidentReports,
id: TrafficResponse.Stores.IncidentReports,
autoLoad: true
});
I set the date value using a date/time picker (not a standard Sencha control) and use the updateRecord method of the form to update the model with the values on the form.
After sync() has been done the record in localstorage has the date value in the following format:
2012-02-09T22:15:00.000Z
The value on the date/time picker is Friday, February 10 2012 08:15 so it appears as though the GMT value is being stored.
After refreshing the browser and loading the model from localstorage, the value in localstorage is retained as above but it is not loaded into the model. The value in the model is null.
If I change the model and add dateFormat: 'c' to the field configuration, the date is loaded into the model with the following value:
Thu Feb 09 2012 22:15:00 GMT+1000 (E. Australia Standard Time)
The date is displayed on the form with that value as well which is 10 hours before the date that was set originally.
What can I do to get the date to load correctly and retain the timezone?
After a lot of stepping though code I discovered that the issue was caused by date-js. I removed date-js and used Sencha Date functions and everything now works correctly.