Receiving an incorrect time in SQL - reactjs

I'm interested in getting a full date in SQL this way 2021/02/02 20:12:36
And the date is kept in such a way 2021/02/02 00:00:00
On the server side I get a correct date like this 2021/02/02 20:12:36
On the client side I get this way 2021/02/02 03:00:00
This is the format I get in React
I don't know why:(
Maybe here's the problem
const FormatDate = (date) => {
try {
console.log(date);
return format(date, "yyyy/MM/dd hh:mm:ss");
} catch (e) {
return "";
}
};

I think this is error of browser auto add offset at client
You can try this code to show right time at client
new Date(DATE_REPONSE_FROM_SERVER).getTime() - new Date().getTimezoneOffset() * 60 * 1000
But you need add offset at server if you send this time to server
Other way, I this you convert time to string and response this string
Hope this help for you

Related

Specify time of events sent with AppInsights?

Is there a way to set the time of events manually sent in App Insights? I'm using the ApplicationInsights package from #microsoft/applicationinsights-web in a react app. As an example, I want to execute something like this at 6:00pm ETC Apr 26, 2022:
appInsights.trackEvent({
name: "my cool event",
properties: {
greeting: "hello world"
},
});
But have it logged in my azure portal as happening at 5:00pm ETC Apr 26, 2022. I figured there would be a time property or something I could set on the parameter object, but that doesn't seem to be the case.
AFAIK, We have trackDependencyData, which is the IDependencyTelemetry interface, which has startTime as a parameter to know the telemetry event start time.
Sample code:-
var success = false;
var startTime = new Date().getTime();
try
{
success = dependency.Call();
}
finally
{
var elapsed = new Date() - startTime;
telemetry.trackDependency({
dependencyTypeName: "myDependency",
name: "myCall",
duration: elapsed,
success: success
});
}
For more information please refer the below links:-
MICROSOFT DOCUMENT| trackDependency , API SUMMARY
SO THREAD | Azure Application Insight JavaScript SDK trackEvent Timestamp

Avoid duplicated publication in Meteor

I'm trying to export some data into a CSV file from a MySQL database using Meter/Sequelize. What I've done so far is to create a Meteor method called by the client which then call a server side function that return the data and I parse it into a csv string. My issue is returning the date client-side.
What I did
I have my CSV String server-side and I'm using FileSaver.js which can only be used client-side.
My "solution" was to create a client-side collection in which I published the String.
methods.js
run({exportParam}) {
if (!this.isSimulation) {
query.booksQuery(exportParam.sorted, exportParam.filtered, 0).then(
result => {
let CSVArr = [];
result.rows.forEach((value) => {
CSVArr.push(value.dataValues);
});
const CSVString = Baby.unparse(CSVArr,{ delimiter: ";"});<-CSV String
console.log("CSVString : ", CSVString);
Meteor.publish("CSVString", function() { <= publication
this.added("CSVCollection", Random.id(), {CSVString: CSVString});
this.ready();
});
});
}
},
And on the client-side I subscribe to the publication this way :
ExportButton.jsx
const handle = Meteor.subscribe('CSVString', {}, function() {
const exportString = myTempCollection.findOne().CSVString;
const blob = new Blob([exportString], {type:"text/plain;charset=utf
8"});
FileSaver.saveAs(blob, "test.csv");
});
My issue
It works great the first time I click my button and a CSV file is downloaded. The problem is that if I do it again I get the same file as the first one and I get this message on my console.
Ignoring duplicate publish named 'CSVString'
I'm pretty sure the problem comes from the fact that every time I click the button the same "CSVString" publication is created.
I'd like to know to know if there is a solution to this problem or if my approach is wrong.
Please let me know if you need anything else.
You are correct in assuming that you are trying to publish to the same collection every time. I think you should only do the publish once, and do that separately from inserting a record into the collection.

Angular resource converting Date object into String while fetching data

I am using Angular resource for ajax operations in my project. I have some date fields i am converting them into JavaScript Date() Object at server when i am fetching the data, i am using Node js (Express js ) at server side. At client side i require this date object for uib datepicker. My Server code for date conversion is:
findAndFormatDate: function (data) {
Object.keys(data).forEach(function (key) {
if (key.indexOf("date") !== -1 || key.indexOf("Date") !== -1) {
data[key] = new Date(data[key]);
if (data[key] instanceof Date) {
console.log("Yes it is a date, and the type is ", typeof data[key]);
}
}
});
return data;
}
and at server console i am getting the message Yes it is a date, and the type is object, but when i am getting this data at client side and checking the typeof this date field then it is showing string and i need to again convert it at client side then it is working properly, i am not able to understand why it requires two time conversion, i want to convert in only at server side so how can i avoid the conversion at client side?

Office 365 Calendar API retrieving only 10 records

I am getting an Issue when trying to fetch the events from Office 365 Calendar
The issue is that I am able to fetch only 10 Events and eventsResult.MorePagesAvailable is always false
I have more than 50 meetings in a month and the eventsResult is fetching only 10
Code to fetch Events :-
var eventSource = service.Me.Calendar.Events;
if (!String.IsNullOrEmpty(calendarId))
{
eventSource = service.Me.Calendars[calendarId].GetCalendarView(lowerBounday, upperBoundary);
// lowerBounday - Start Date for fetching events from calendar
// upperBoundary - End Date for fetching events from calendar
var eventsResult = await (from i in eventSource orderby i.Start select i).ExecuteAsync();
}
Same issue is coming for fetching all Calendars
I have more the 10 calendars in Office 365 but still getting only 10 with MorePagesAvailable as false.
Code to fetch All Calendars :-
var allCalendars = await service.Me.Calendars.ExecuteAsync();
bool checkNextPage = false;
do
{
if (checkNextPage && allCalendars.MorePagesAvailable)
{
allCalendars = await allCalendars.GetNextPageAsync();
}
foreach (ICalendar calendar in allCalendars.CurrentPage)
{
lock (calendars)
{
calendars.Add(new CalendarData(calendar.Name, calendar.Id)
{
HasWriteAccess = true,
IsFreeBusy = true
});
}
}
if(!checkNextPage)
checkNextPage = true;
} while(allCalendars.MorePagesAvailable)
We are using Microsoft.Office365 DLL's version 1.0.35 for this code.
It was working fine till 10-sept-2015. Is there anything changed with API or we are missing something?
Any help would be really appreciated.
Turns out this is a know issue that our engineers are working on. Sorry for the inconvenience!
UPDATE: The fix is in the pipeline. I'm seeing the #odata.nextLink in responses on my tenants, so it looks like it's hitting servers in production.
10 is the default number. You need to use somthing like this https://outlook.office.com/api/v1.0/me/messages?$top=number number= 5, 10...how many events you want. More details:https://msdn.microsoft.com/office/office365/APi/complex-types-for-mail-contacts-calendar#UseODataqueryparametersPageresults

Can I customize my AngularJS application to display local times?

I am using an ASP.NET MVC / ASP.NET Web API back-end for my application. When a user updates data the time is recorded like this:
public HttpResponseMessage PutContent(int id, Content content)
{
if (id != content.ContentId)
{
return Request.CreateResponse(HttpStatusCode.BadRequest);
}
try
{
content.ModifiedDate = DateTime.Now;
content.ModifiedBy = User.Identity.GetUserId();
_uow.Contents.Update(content);
_uow.Commit();
return Request.CreateResponse(HttpStatusCode.OK, content);
}
catch (Exception ex)
{
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex);
}
}
When the user looks at the modified time they see what I assume is the server time. Is there a way that I can allow them to see the local time that the change was made?
Note that already I do some formatting but I am not sure if there is a way that I can convert the date and have this matched up with my local users who could be in any location:
<input disabled="disabled" type="text"
value="{{modal.data.modifiedDate | date:'MM/dd/yy HH:mm'}}" />
To start with it is always better to save the dates on server in UTC. So on the server use the method DateTime.UtcNow.
And while sending the data to client, if you are not custom formatting the date, i believe the date send contains the timezone information as well. AngularJS can handle that correct using date filter. See this fiddle http://jsfiddle.net/jHSLe/1/
Assuming the date you are getting is in UTC, you can use the excellent Moment.js to easily convert it to local time as described here:
http://momentjs.com/docs/#/manipulating/local/

Resources