Exchange Api send incorrect invitation in Israel timezone - api

I faced to following problem with sending invitation in .net using exchange API
Send invitation in Israel timezone with start time =09/09/2013 4.30 Israel.
But it is displayed in outlook 09/09/2013 6.30 Israel.
It works properly for other time zones for example for EST.
Does anybody has any idea how to fix this?
Sample:
service.AutodiscoverUrl(loginForm.tbEmailAddress.Text, f);
TimeZoneInfo timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("Israel Standard Time");
Appointment appointment = new Appointment(service);
appointment.Subject = "subj";
appointment.Body = new MessageBody(BodyType.Text, "body");
appointment.StartTimeZone = timeZoneInfo;
appointment.Start = GetDateTime(new DateTime(2013, 09, 09, 04, 0, 0));
appointment.EndTimeZone = timeZoneInfo;
appointment.End = GetDateTime(new DateTime(2013, 09, 09, 04, 30, 0));
appointment.IsAllDayEvent = false;
appointment.Importance = Importance.Normal;
appointment.RequiredAttendees.Add("Lena", "email...");
appointment.Save(SendInvitationsMode.SendOnlyToAll);
...
private static DateTime GetDateTime(DateTime dateTime)
{
return new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute,
dateTime.Second, dateTime.Millisecond, DateTimeKind.Unspecified
);
}
I use Microsoft.Exchange.WebServices.dll 15.0.516.14

it's actually a known issue with Exchange EWS itself. Developer can only trust the date time returned without the timezone information, and the correct timezone for that time should be UTC always.

Related

Wrong time being returned by date-fns when involving 2 timezones

Introduction
I have the current situation:
I receive the date from the backend as UTC
The user can have in his own profile his timezone setup
User can pick the date and time in two different time pickers
As soon as the date is returned by the backend I convert it to the user local timezone (timezone of his profile)
User selects new date, I create a zonedDate, modify it and store it as UTC
User selects new time, I use the utcToZonedTime to convert to user's local timezone (the UTC returned from backend), then I update with setHours and setMinutes and store back as UTC using toISOString() string
How the code is structured
I currently have the following code for when the user pick the date
import utcToZonedTime from 'date-fns-tz/utcToZonedTime';
const localizedTime = computed(() =>
utcToZonedTime(record.value.date, loggedUser.timezone)
);
const date = computed({
get: () => formatToDate(localizedTime.value),
set: (value: string) => {
// The `value` will come as YYYY-MM-DD from the DatePicker component
const zonedDateString = `${value}T17:30`;
const zonedDate = toDate(zonedDateString, {
timeZone: loggedUser.timezone,
});
record.value.date = zonedDate.toISOString();
},
});
This works fine for now. I set the hour and minutes to a hardcoded 17:30.
Now, the problem happens whenever picks the time:
import utcToZonedTime from 'date-fns-tz/utcToZonedTime';
import setMinutes from 'date-fns/setMinutes';
import setHours from 'date-fns/setHours';
const localizedTime = computed(() =>
utcToZonedTime(record.value.date, loggedUser.timezone)
);
const time = computed({
get: () => format(localizedTime.value, 'HH:mm'),
set: (time: string) => {
// Time is returned as HH:mm from the input
const [hour, minutes] = time.split(':');
console.log('Localized time:')
console.log(localizedTime.value);
let currentDateParsed = setHours(
localizedTime.value,
hour as unknown as number
);
currentDateParsed = setMinutes(
currentDateParsed,
minutes as unknown as number
);
console.log('Current date parsed:')
console.log(currentDateParsed);
record.value.date = currentDateParsed.toISOString();
},
});
Problem
As a setup I have the following criterias:
User timezone is set to Europe/Lisbon (GMT+1)
My computer timezone is set to Europe/Zagreb (GMT+2)
I receive the following date from backend in UTC 2022-06-02T16:00:56.000000Z
Time is displayed as 17:00 (I'm using the user profile's timezone and not the computer's timezone)
Whenever I set the date, it works perfect time. Whenever I try to set hours and minutes, the timezones get mixed up.
I select the time as 18:30 and it is displayed back to the user as 17:30.
The part of the code that is giving me problems is:
const time = computed({
get: () => format(localizedTime.value, 'HH:mm'),
set: (time: string) => {
// Time is returned as HH:mm from the input
const [hour, minutes] = time.split(':');
console.log('Localized time:')
console.log(localizedTime.value); 👈 // Thu Jun 02 2022 17:00:56 GMT+0200 (Central European Summer Time)
let currentDateParsed = setHours(
localizedTime.value,
hour as unknown as number
);
currentDateParsed = setMinutes(
currentDateParsed,
minutes as unknown as number
);
console.log('Current date parsed:')
console.log(currentDateParsed); 👈 // Thu Jun 02 2022 18:30:56 GMT+0200 (Central European Summer Time)
console.log('Current date parsed toISOString():');
console.log(currentDateParsed.toISOString()); 👈 // 2022-06-02T16:00:56.000Z
record.value.date = currentDateParsed.toISOString();
},
});
I have tried converting the date back to UTC and work only in UTC and also only in user's local time but nothing seems to work. I have uploaded the following video showing the issue

expo notification how set start time

The challenge is: how can I set up the start date for notification in the new expo API. In the old API (which is depricated today) it was feasible but I can't see the solution in the new doc
For example: set up a notification on every 2nd day start from a user given date (e.g. 12th of Jan).
I went through on these types
export type SchedulableNotificationTriggerInput =
| DateTriggerInput
| TimeIntervalTriggerInput
| DailyTriggerInput
| WeeklyTriggerInput
| CalendarTriggerInput;
but no success so far.
As far as I can tell you should be able to set the start date this way:
const dateString = "21/01/2021"; // Jan 21
const trigger = new Date(dateString);
trigger.setMinutes(0);
trigger.setSeconds(0);
Notifications.scheduleNotificationAsync({
content: {
title: 'Happy new hour!',
},
trigger,
});
You should play around with trigger.setMinutes and trigger.setSeconds to set a specific hour on your specific day.

Timezone names for .NET application in LINUX

I have an ASP.NET CORE app.
While this code works in Windows:
var utcNow = DateTime.UtcNow;
var currentDateTime = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(utcNow, "US Eastern Standard Time");
Will this work when deployed on Linux Kubernetes cluster - given the harcoded timezone name "US Eastern Standard Time"
Or do I need to configure a different name?
Thanks
Anand
For LINUX the name to use is "EST"
var utcNow = DateTime.UtcNow;
string estTz = string.Empty;
#if RUN_ON_WINDOWS
estTz = "US Eastern Standard Time";
#else
estTz = "EST";
#endif
var currentDateTime = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(utcNow, estTz); // nyse tz
In case you are interested we have RUN_ON_WINDOWS in .csproj that the TeamCity build process for LINUX or WINDOWS deployment overwrites accordingly.
<ItemGroup Condition="'$(RunOnWindows)'=='true'">
For TimeZoneInfo, it has different ids for Windows and Linux, you could check this issue TimeZoneInfo should have consistent Ids across Windows and Linux #2538.
For a possible workaround, you could try TimeZoneConverter like
var utcNow = DateTime.UtcNow;
TimeZoneInfo tzi = TZConvert.GetTimeZoneInfo("Eastern Standard Time");
var currentDateTime = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(utcNow, tzi.Id);

JwtSecurityToken expiration date is two hours apart

In my .net core api application, I use:
var dt = DateTime.Now.AddMinutes(60); // time is 2018-04-27 14:49:00
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config["Tokens:Key"]));
var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
var claims = new[]
{
new Claim(JwtRegisteredClaimNames.Sub, user.Email),
new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
new Claim(JwtRegisteredClaimNames.UniqueName, user.UserName)
};
var token = new JwtSecurityToken(
_config["Tokens:Issuer"],
_config["Tokens:Audience"],
claims,
expires: dt,
signingCredentials: creds);
token.ValidTo is shown as 2018-04-27 12:49:00 ...
Why ?
It's because of the different timezones. Your timezone is probably UTC+2, and your variable dt contains the time in local time.
But JwtSecurityToken.ValidTo is a DateTime value which contains a time in UTC. The resulting JWT will give you a value (exp claim) based in Unix Epoch Time in seconds sine 1970-01-01 00:00 UTC.
In your case exp will be
1524833340
which equals
2018-04-27 12:49:00 UTC (14:49 in UTC+2)
as you can check here and the JWT framework knows how to handle that, independent from the timezone.
The behaviour is correct and you don't need to change anything.
In server side create token method, use Utc time to generate expiration time:
var token = new JwtSecurityToken(
issuer: _configuration["JWT:ValidIssuer"],
audience: _configuration["JWT:ValidAudience"],
expires: DateTime.UtcNow.AddMinutes(tokenValidityInMinutes),
claims: authClaims,
signingCredentials: new SigningCredentials(authSigningKey, SecurityAlgorithms.HmacSha256)
);
and in client side check for Utc time :
var identity = string.IsNullOrEmpty(tokenDTO?.Token) || tokenDTO?.Expiration < DateTime.UtcNow
In fact local time makes this problem, so you need to create an expiration time based on Utc and check it with DateTime.UtcNow

How to send multiple events with one .ics file using aspnetemail class in vb.net

I have to send mutiple events with one .ics file using ASpnetMail Class in vb.net. and i went throgh the ASpnetMail documention but i didn't get any clue..
Please suggest me...
Reagrds
Pankaj Pareek.
What you will want to do, is create a 2nd event, and add it to the ical.Events collection.
Here is a code example that a customer needed, for streaming the iCal to the browser. You could have just of easily of added it to an EmailMessage object, and sent it in an email.
iCalendar ical = new iCalendar();
ical.Method.Value = "Publish";
//create the 1st event
EventComponent e1 = new EventComponent();
e1.Summary.Text = "Last Day for Dropping Winter Term Course with \"W\"";
e1.Description.Text = "Last Day for Dropping Winter Term Course with \"W\"";
DateTime startAt = new DateTime( 2009, 01, 12, 8, 0, 0 );
e1.DateStart.Date = startAt;
e1.DateEnd.Date = startAt.AddHours( 9 );
ical.Event = e1;
//create the 2nd event
EventComponent e2 = new EventComponent();
e2.Summary.Text = "Martin Luther King Jr. Holiday";
e2.Description.Text = "Martin Luther King Jr. Holiday";
DateTime startAt2 = new DateTime( 2009, 01, 16, 8, 0, 0 );
e2.DateStart.Date = startAt2;
e2.DateEnd.Date = startAt2.AddHours( 9 );
//add it to the Events collection
ical.Events.Add( e2 );
//save to a file
ical.WriteToFile( "c:\\temp\\somefile.ics");
//stream the file to the browser
Response.ClearHeaders();
Response.ContentType = "text/calendar";
Response.AppendHeader( "Filename", "events.ics");
Response.AppendHeader("Content-Disposition", "attachment;filename=events.ics");
ical.WriteToStream( Response.OutputStream );
Response.Flush();
Response.End();
Does that help?
--Dave