I am working with MPXJ framework to generate an XML file with i import into project 2007. I have run in to allot of problems but i can't seem to find an answer to the following.
I have a fixed Work and duration on a task, but when i add a resource and import it in project i get an error message:
"The resource is assigned outside the original dates for task 2 in project. The duration of this fixed-duration task will change to accommodate the resource assignment".
Project then changes the work and or duration value. that is not what i want. i want the resource to use the 24 hours calendar but i can't seem to attach the project 2007 standard calendar, so i thought lets make my own 24 hours calendar and attach that to resource. now i can't seem to set the 0:00:00 to 0:00:00 time in a work day.
ProjectCalendar calendar = projectFile.addResourceCalendar();
calendar.setName("24 Hours");
calendar.setUniqueID(Count);
calendar.setWorkingDay(Day.MONDAY, true);
calendar.setWorkingDay(Day.TUESDAY, true);
calendar.setWorkingDay(Day.WEDNESDAY, true);
calendar.setWorkingDay(Day.TUESDAY, true);
calendar.setWorkingDay(Day.FRIDAY, true);
Resource resource = projectFile.addResource();
resource.setUniqueID(Count);
resource.setName("Painters");
resource.setResourceCalendar(calendar);
Any one know of a solution to one get the default 24 hour calendar set to the resource of make my own.
The code below illustrates how to create a 24 hour calendar. My apologies for the long-winded way each day is set up, I need to improve the way the Day class works so that it is easier to iterate.
The key point to note is that the DateRange instance is set up to start at 00:00 hours on one date, and finish at 00:00 hours on the following day. The actual date used is irrelevant, the calendar is only using the time element of the date.
Hope that makes sense!
//
// Use this date formatter to make it simple to specific the range
// start and wne dates
//
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
//
// This is an immutable date range, so we can share it without
// worrying about it being changed
//
DateRange range = new DateRange(format.parse("2000-01-01 00:00"), format.parse("2000-01-02 00:00"));
//
// Add the calendar and name it
//
ProjectCalendar test = file.addBaseCalendar();
test.setName("Test 24 Hours");
//
// Mark each day as working
//
test.setWorkingDay(Day.SUNDAY, true);
test.setWorkingDay(Day.MONDAY, true);
test.setWorkingDay(Day.TUESDAY, true);
test.setWorkingDay(Day.WEDNESDAY, true);
test.setWorkingDay(Day.THURSDAY, true);
test.setWorkingDay(Day.FRIDAY, true);
test.setWorkingDay(Day.SATURDAY, true);
//
// Add a working hours range to each day
//
ProjectCalendarHours hours;
hours = test.addCalendarHours(Day.SUNDAY);
hours.addRange(range);
hours = test.addCalendarHours(Day.MONDAY);
hours.addRange(range);
hours = test.addCalendarHours(Day.TUESDAY);
hours.addRange(range);
hours = test.addCalendarHours(Day.WEDNESDAY);
hours.addRange(range);
hours = test.addCalendarHours(Day.THURSDAY);
hours.addRange(range);
hours = test.addCalendarHours(Day.FRIDAY);
hours.addRange(range);
hours = test.addCalendarHours(Day.SATURDAY);
hours.addRange(range);
Related
I'm setting up a calendar invite email using ical.net. Sending out a non-recurring event seems to work perfectly: I set the start and end date like this
iCalEvent.DtStart = new CalDateTime(DateTime.SpecifyKind(model.EventTime.Value, DateTimeKind.Utc));
iCalEvent.DtEnd = new CalDateTime(DateTime.SpecifyKind(model.EventTime.Value.AddMinutes(model.DurationMins.Value), DateTimeKind.Utc));
when the email arrives, the time zone has been converted to the recipients timezone (The timezone is -7, the eventTime is 4pm and the duration is 3 hours)
However, when I take this same exact code and add this line to it
IRecurrencePattern recurrence = new RecurrencePattern(FrequencyType.Daily, 1)
{
Until = DateTime.SpecifyKind(model.endDate.Value.AddDays(1), DateTimeKind.Utc)
};
iCalEvent.RecurrenceRules = new List<IRecurrencePattern> { recurrence };
Suddenly my timezone is no longer converted when the email is received (The timezone is -7, the eventTime is 4pm and the duration is 3 hours. The endDate is on the 28th)
I need the DateTime to be displayed to the user in their own timezone and I need to display recurring events from the eventTime to the endDate
It may also be useful to note that I do not have a timezone property specified on Calendar as it was causing the sent email to show a "not supported calendar message" in outlook. Before I removed it, it looked like this
iCal.AddTimeZone(new VTimeZone("UTC"));
when I opened ical files that had this time zone specified, they seemed to work correctly for multi day events, but as I need them to appear in outlook with the accept/decline/tentative buttons, it is out of the question to add it back
i've also tried specifying datetimes like this
iCalEvent.DtStart = new CalDateTime(leEvent.EventTime.Value, "UTC");
but nothing changed
EDIT: I now understand that the issue is due to a recurring event needing a timezone as specified here, but I'm not quite sure where the timezone needs to be specified. I went back to adding the vTimeZone back in and validating it through this site, and it appears that the iCal file is missing the standard/daylight section inside of the timezone block
I have also tried specifying the timezone as GMT and specifying the timezone as "\"America/Phoenix\"" so that the tzid came out as TZID:"America/Phoenix" (with quotes in the ical file.
This is my code at the moment that causes the issue.
iCalEvent.DtStart = new CalDateTime(DateTime.SpecifyKind(model.EventTime.Value, DateTimeKind.Utc));
iCalEvent.DtEnd = new CalDateTime(iCalEvent.DtStart.Value.AddMinutes(model.DurationMins.Value));
if (model.EndDate.HasValue)
{
IRecurrencePattern recurrence = new RecurrencePattern(FrequencyType.Daily, 1)
{
Until = DateTime.SpecifyKind(model.MaxDate.Value, DateTimeKind.Utc).ToLocalTime()
};
iCalEvent.RecurrenceRules = new List<IRecurrencePattern> { recurrence };
iCalEvent.DtStart = new CalDateTime(iCalEvent.DtStart.Value.ToLocalTime(), "America/Phoenix");
iCalEvent.DtEnd = new CalDateTime(iCalEvent.DtEnd.Value.ToLocalTime(), "America/Phoenix");
iCal.AddTimeZone(new VTimeZone("America/Phoenix"));
}
I'm not quite sure what needs to happen to correct the standard/daylight ical error from this point.
FINAL EDIT:
after reading through this post, I found that this issue has already been solved as of last november. I checked the version we had in our project and it turned out some genius just copied the dll straight in without setting it up through nuget (and a version from several years ago no less). I grabbed the latest version and this time specifying the timezone caused no issues in outlook. I'm still experimenting with addTimeZone and addLocalTimeZone but I'm definitely on the right track. Thank you to rianjs for this extremely useful library. I don't know how I would possible work with this crazy calendar standard without it.
A recurring event is always relative to the sender's timezone (or rather to the event location), and not to the recipient's timezone, because of daylight saving changes which may happen at different time between the organiser and the various recipients.
So in most cases you want to use a meaningful timezone in the event (i.e. not UTC).
Then Outlook is simply showing that the event is indeed happening according to the given timezone. This is an indication that the event may not always be at the same time of day for the recipient.
Since this took me so long to figure out, I might as well share my solution in case anyone else runs into this problem and finds this.
I defined the DtStart/DtEnd with two datetimes that had kind utc
calendarEvent.DtStart = new CalDateTime(model.EventTime.Value);
calendarEvent.DtEnd = new CalDateTime(model.EventTime.Value.AddMinutes(model.DurationMins.Value));
which worked great for single day events, but with multidays I ended up doing this
if (model.EndDate.HasValue)
{
RecurrencePattern recurrence = new RecurrencePattern(FrequencyType.Daily, 1)
{
Until = model.EndDate.Value //has kind: Utc
};
var timezoneOffsetString = "Etc/GMT";
if (timezoneOffset > 0) //client time zone offset, calculated through js
{
timezoneOffsetString += "-" + timezoneOffset;
}
else if (timezoneOffset < 0)
{
timezoneOffsetString += "+" + (-1 * timezoneOffset);
}
calendar.AddTimeZone(timezoneOffsetString);
calendarEvent.DtStart = calendarEvent.DtStart.ToTimeZone(timezoneOffsetString);
calendarEvent.DtEnd = calendarEvent.DtEnd.ToTimeZone(timezoneOffsetString);
calendarEvent.RecurrenceRules = new List<RecurrencePattern> { recurrence };
}
It's not fullproof as some places may have weird dst problems, but nodatime was treating the "America/Phoenix" tzid as an LMT time, which was giving me a time that was like 28 minutes off... Besides, treating all dates as GMT is closer to the implementation we have in the rest of our app so it worked for my situation
This solution gave me the idea to piece together the Etc/GMT stuff.
iam using devexpress scheduler. in my form iam using
schedulerControl1.ActiveViewType = DevExpress.XtraScheduler.SchedulerViewType.WorkWeek;
schedulerControl1.WorkWeekView.WorkTime.Start = System.TimeSpan.FromHours(7);
schedulerControl1.WorkWeekView.WorkTime.End = System.TimeSpan.FromHours(22);
schedulerControl1.WorkWeekView.ShowWorkTimeOnly = true;
schedulerControl1.WorkWeekView.ShowAllDayArea = false;
as you can see iam using workweek view, the start week setting properties was monday, but the header is displaying 10 october, 11 octoberand so on. the thing is how do i change the scheduler header to day name like monday, tuesday and so on.
n.b : if its duplicate please refer it
you can use formatting services (see Formatting Services - an example of use) for this purpose.
See Also:
Work Week View without specific dates
Refer these for the alternative way to implement this:
How to: Display Custom Day Headers
SchedulerControl.CustomDrawDayOfWeekHeader Event
How to: Custom Paint Day Headers
CustomDrawDayHeader, how to use custom captions with default background ?
Hope this help.
I have been working on a C# app in Visual Studio 2013 that will calculate employee hours from Google Calendar events. I have used this link, https://developers.google.com/google-apps/calendar/quickstart/dotnet, for instructions on how to connect to Google Calendar via the API. When I enter my hours worked for the day on the calendar, I create an event, and use the From Time as the start time, and the Until Time as the end time. I can't figure out how to calculate the total hours for the day. What I want to be able to do is simply subtract the From time from the Until time to get the total hours worked for that day. I just can't figure out how to get the start and end times into variables that I can then perform arithmetic on. I can then figure out how to do that for each day of the week, and add them together.
Using example from Google Calendar API, they provide the event date & date time as below,
Events events = request.Execute();
Console.WriteLine("Upcoming events:");
if (events.Items != null && events.Items.Count > 0)
{
foreach (var eventItem in events.Items)
{
string when = eventItem.Start.DateTime.ToString();//Right here
if (String.IsNullOrEmpty(when))
{
when = eventItem.Start.Date;//And here
}
Console.WriteLine("{0} ({1})", eventItem.Summary, when);
}
}
I am logging time in many places
If Request.DynamicSettings.AirlineSettings.AirlineGeneralSettings.TimeLogEnabled Then
StartTime = DateTime.Now
LogTime(Reflection.MethodBase.GetCurrentMethod.DeclaringType.FullName, Reflection.MethodBase.GetCurrentMethod.Name, StartTime, DateTime.Now, "AB-SCR(I)", 0,)
End If
all places i have used
DateTime.Now
I am facing an issue now,
I am currently hosting this in a gulf server, GMT +4:00
I need to host this same project for another country at Gmt +3Gmt
for this hosting i need time to be logged using that country's local time.
Is there any way to do this, without having to modify each and every line of my code.
i have seen this article timzone with asp.net but as my service is already up i have a lot of codes to change, i am looking for a simpler solution.
thanks.
A few things:
You cannot change the time zone in the IIS configuration or web.config. This is not an IIS problem, but rather a problem in your application code.
DateTime.Now should never be used in a server side application, such as an ASP.Net web application. Read The case against DateTime.Now.
If you are just timing how long something takes to run, don't use DateTime at all. Instead, use System.Diagnostics.Stopwatch.
Stopwatch sw = Stopwatch.StartNew();
// ...do some work ...
sw.Stop();
TimeSpan elapsed = sw.Elapsed; // how long it took will be in the Elapsed property
If you actually want the current time in a specific time zone, then you need to know the time zone identifier. (GMT+4 and GMT+3 are not time zones, but rather time zone offsets see "Time Zone != Offset" in the timezone tag wiki.) You can see a list of Windows time zones by using TimeZoneInfo.GetSystemTimeZones(), or by calling tzutil /l on the command line.
Then in your application:
string tz = "Arabian Standard Time";
DateTime now = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, tz);
You should probably refactor your code such that this is done inside your LogTime method. Then you will have only one place to set the time zone for your application.
How can i make a timer countdown set to specific date and time like the date is on June 1, 00:00:00
The code have to show the remaining time to that specific date or time.
You could use jQuery Countdown Plugin
Or here is a very good free Under construction template with a countdown timer
http://demo.ourtuts.com/site-under-construction/
in the demo the countdown timer is set up as follows(grabbed from source)
$(function () {
var austDay = new Date("December 10, 2012 02:15:00");
$('#defaultCountdown').countdown({until: austDay, layout: '{dn} {dl}, {hn} {hl}, {mn} {ml}, and {sn} {sl}'});
$('#year').text(austDay.getFullYear());
});
You can just change the date string
var austDay = new Date("December 10, 2012 02:15:00");
to suit your need, You can also change the design if you want.
link to download this is at http://www.ourtuts.com/free-site-under-construction-template/