I am trying to test Quartz.net dll with sample code by creating jobs. But I want to change the system time and test some cases like : I am trying to set this SystemTime.UtcNow = () => new DateTime(2013,11,23,58,00); in my test console app before creating , and added a job to tick at .WithCronSchedule("0 59 23 ? * *") but its not ticking ... not sure whether SystemTime has taken effect.
sample code below :
ISchedulerFactory sf = new StdSchedulerFactory();
IScheduler sched = sf.GetScheduler();
SystemTime.UtcNow = () => new DateTime(2013, 12, 04, 23, 58, 00);
SystemTime.Now = () => new DateTime(2013, 12, 04, 23, 58, 00);
////TEST
IJobDetail job = JobBuilder.Create<SimpleJob>()
.WithIdentity("job1", "group1")
.Build();
ICronTrigger trigger = (ICronTrigger)TriggerBuilder.Create()
.WithIdentity("trigger1", "group1")
.WithCronSchedule("0 59 23 ? * *")
.Build();
Have you tried setting the SystemTime to exactly the scheduled time or a bit after that? Your SystemTime value does not change and if Quartz.Net tries to check whether the job should be run using that delegate, it will actually never be the right time to run it in your test.
Related
I have made an app using ionic.
Inside it, I make a http get to get some value from my db.
Then, I loop through the result to compute the difference in terms of time between the created date of my value inside the db and the actual date.
This code works very well on my linux but when I run the code on my iphone on ios, everything works fine except the for loop which does not work... it's very strange. Someone faced it ?
ionViewWillEnter() {
let date = new Date();
this.http.get(this.server + `json.php?&id=${1}`).subscribe(resData => {
console.log(resData);
this.events = resData;
for (let i=0; i < 10; i++){
this.events[i]['unique_id'] = parseInt(this.events[i]['unique_id']);
if ((date.getTime() - new Date(this.events[i].created_at).getTime()) / 1000 < 60) {
this.events[i].ecart_now = 'there is ' + Math.round((date.getTime() - new Date(this.events[i].created_at).getTime()) / 1000) + 's';
}
}
})
}
A high possibility is the invalid date format. Safari and Internet Explorer browsers have issue with date format: new Date("2011-02-07");.
Console log new Date(this.events[i].created_at) and you would see invalid date.
Use below formats:
new Date(2011, 01, 07);
new Date(2011, 01, 07, 11, 05, 00);
I don't think I'm hallucinating as I've tried it a dozen times. Here's my code:
$('#teo_prep_due').change(function() {
var ber = $('#ber_rcvd');
var tpd = $('#teo_prep_due');
var brDate = ber.datepicker('getDate');
var tpDate = tpd.datepicker('getDate');
var s1Date = new Date();
var s2Date = new Date();
var sdDate = new Date();
s1Date.setDate(brDate.getDate() + 5);
console.log(s1Date);
s2Date.setDate(tpDate.getDate() - 3);
console.log(s2Date);
if (s1Date < s2Date) {
sdDate.setDate(s1Date.getDate());
} else {
sdDate.setDate(s2Date.getDate());
}
$('#survey_due').datepicker('setDate', sdDate);
});
On my date form, I've entered February 28, 2013 for ber_rcvd and March 14, 2013 for teo_prep_due. Following the code, my result should be March 5, 2013. However, s2Date is resulting in February 11, 2013, as if a full month and 3 days are being subtracted instead of just 3 days. Has anyone else run into this?
Using: jquery-1.9.1.min.js, jquery-migrate-1.1.1.js and jquery-ui-1.10.1.min.js.
http://jsfiddle.net/devlshone/veP7b/
The problem is that .setDate() does not set the date, it sets the day of the month. It takes an integer as an argument. When you created s2Date it defaulted to today, which is in February. When you add tpDate.getDate()// equals 14 with -3, you get 11, and therefore February 11th.
I work with an export from a Zimbra calendar and wold like to create a list of all events occurring on each day. The simplified calendar looks like this.
BEGIN:VCALENDAR
X-WR-CALNAME:Test-Parking
VERSION:2.0
BEGIN:VTIMEZONE
TZID:Europe/Berlin
BEGIN:STANDARD
DTSTART:19710101T030000
TZOFFSETTO:+0100
TZOFFSETFROM:+0200
RRULE:FREQ=YEARLY;WKST=MO;INTERVAL=1;BYMONTH=10;BYDAY=-1SU
TZNAME:CET
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
RRULE:FREQ=DAILY;COUNT=3;INTERVAL=1
SUMMARY:Day Event 3 Times
DTSTART;VALUE=DATE:20120911
DTEND;VALUE=DATE:20120912
END:VEVENT
BEGIN:VEVENT
SUMMARY:4 hours event
DTSTART;TZID="Europe/Berlin":20120911T090000
DTEND;TZID="Europe/Berlin":20120911T130000
END:VEVENT
END:VCALENDAR
Now i have written some lines of code to filter the events:
public class CalendarTester {
private Calendar calendar;
private TimeZoneRegistry registry;
public static void main(String[] args) throws Exception {
CalendarTester tester = new CalendarTester();
tester.run();
}
private void run() throws IOException, ParserException, URISyntaxException,
ParseException {
readCalendar();
TimeZone tz = registry.getTimeZone("Europe/Berlin");
SimpleDateFormat formatter = new SimpleDateFormat();
GregorianCalendar cal = new GregorianCalendar(2012,
GregorianCalendar.SEPTEMBER, 10);
cal.set(GregorianCalendar.HOUR_OF_DAY, 0);
cal.set(GregorianCalendar.MINUTE, 0);
cal.set(GregorianCalendar.SECOND, 0);
cal.setTimeZone(tz);
for (int i = 0; i < 5; i++) {
Period p = new Period(new DateTime(cal.getTime()), new Dur(1, 0, 0,
0));
p.setTimeZone(tz);
Rule[] rules = new Rule[1];
rules[0] = new PeriodRule(p);
Filter f = new Filter(rules, Filter.MATCH_ALL);
System.out.println("_____________");
System.out.println(formatter.format(cal.getTime()));
for (Object event : f.filter(calendar
.getComponents(Component.VEVENT))) {
printEvent((VEvent) event, formatter);
}
cal.add(GregorianCalendar.DAY_OF_YEAR, 1);
}
}
private void printEvent(VEvent event, SimpleDateFormat formatter) {
System.out.println("Start: "
+ formatter.format(event.getStartDate().getDate()) + " End: "
+ formatter.format(event.getEndDate().getDate()) + " Summary: "
+ event.getSummary().getValue());
}
private void readCalendar() throws FileNotFoundException, IOException,
ParserException {
FileInputStream fin = new FileInputStream(
"files/Recuring_Calendar_Entry_From_To.ics");
CalendarBuilder builder = new CalendarBuilder();
calendar = builder.build(fin);
registry = builder.getRegistry();
}
}
Now i get the Simple event correctly but the 3 time occuring one day event 4 times, because of the wrong start and end times.
_____________
10.09.12 01:00
_____________
11.09.12 01:00
Start: 11.09.12 02:00 End: 12.09.12 02:00 Summary: Day Event 3 Times
Start: 11.09.12 10:00 End: 11.09.12 14:00 Summary: 4 hours event
_____________
12.09.12 01:00
Start: 11.09.12 02:00 End: 12.09.12 02:00 Summary: Day Event 3 Times
_____________
13.09.12 01:00
Start: 11.09.12 02:00 End: 12.09.12 02:00 Summary: Day Event 3 Times
_____________
14.09.12 01:00
Start: 11.09.12 02:00 End: 12.09.12 02:00 Summary: Day Event 3 Times
So if anyone has an idea what i have to change at the import or at the filter, that i get all events in the same timezone.
Tanks for any suggestions, Cy
I did some tests to figure out what is going on. The start was the Tests for the filters in:
test/net/fortuna/ical4j/filter/PeriodRuleTest.java
If i create a new all day event like it is shown there everything is ok.
If i add a recure roule the functionality is broken.
Recur recur = new Recur("FREQ=DAILY;COUNT=3;INTERVAL=1");
event.getProperties().add(new RRule(recur));
Now the Event matches for the starting date and on the following 3 days as it is shown in the sample above.
If I set the COUNT=1 in the rule the event now matches 2 times. Maybe I do not understand the recurring rule? If I take a look at the web calendar (Zimbra) where I exported this events everything is like i expected.
Here you can see my test class
I noticed a couple of things:
The first thing is that your "Day Event 3 Times" event is not using the Europe/Berlin timezone for its dates, so the event is effectively in "floating time". This may not matter if your local timezone is Europe/Berlin tho.
Second, the same event spans 11 Sep - 12 Sep. So with the recurrence rule you will end up with three event instances:
11 Sep - 12 Sep
12 Sep - 13 Sep
13 Sep - 14 Sep
I didn't look too closely at what the code is doing, but that might explain why you are getting matches on 14 sep.
I use below codes to convert a 12hour UTC to a new timezone
MySourceCodes: (part of my udp socket server codes)
// $gps_time = "9:43:52";
$gps_time = $time_hour.":".$time_min.":".$time_sec;
// $time_received = "01:45:04 2012-07-28";
$time_received = date('H:i:s Y-m-d');
$utc = new DateTimeZone("UTC");
$moscow = new DateTimeZone("Europe/Moscow");
//Instantiate both AM and PM versions of your time
$gps_time_am = new DateTime("$gps_time AM", $utc);
$gps_time_pm = new DateTime("$gps_time PM", $utc);
//Received time
$time_received = new DateTime($time_received, $moscow);
//Change timezone to Moscow
$gps_time_am->setTimezone($moscow); /* ### ### Line 105 Error ### ### */
$gps_time_pm->setTimezone($moscow);
//Check the difference in hours. If it's less than 1 hour difference, it's the correct one.
if ($time_received->diff($gps_time_pm)->h < 1) {
$correct_time = $gps_time_pm->format("H:i:s Y-m-d");
}
else {
$correct_time = $gps_time_am->format("H:i:s Y-m-d");
}
echo $correct_time;
PHP Error :
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (0:11:38 AM) at position 8 (A): The timezone could not be found in the database' in C:\xampp\php\udp.php:105
Stack trace:
#0 C:\xampp\php\udp.php(105): DateTime->__construct('0:11:38 AM', Object(DateTimeZone))
#1 {main} thrown in C:\xampp\php\udp.php on line 105
Error give when input time is 0:11:38 AM
Question:
how can I solve the problem ?
Edit: my input time Source from GPS Tracker (change seconds to 12hour format time)
$time_hour = floor($get_time / 3600);
$time_min = floor(($get_time - ($time_hour*3600)) / 60);
$time_sec = dotwodigits(($get_time - (($time_hour*3600) + ($time_min * 60))));
GPS Time = $time_hour.":".$time_min.":".$time_sec
As I've pointed out in the comments, 12-hour time doesn't have a 0:xx:yy time. What you can do, then, is check the value of $time_hour beforehand:
//assigning values to $time_hour, $time_min, and $time_sec
if ($time_hour == 0) $time_hour = 12;
//rest of code
This will prevent the invalid time from being passed to the DateTime constructor.
EDIT: This check can actually be performed during the assignment of $time_hour:
$time_hour = floor($get_time / 3600) ?: 12;
I currently have a list of DateTimes stored as the timezone's UTC datetime. When I go to convert from UTC to local datetime and when the date falls on the start of Daylight Standard time, the hour that repeats is 1am and not 2am.
I use the following to convert from UTC to local time. Notice that 1am repeats in local1 and local2. I expected 2am to repeat.
Which is correct?
TimeZoneInfo tz = TimeZoneInfo.FindSystemTimeZoneById("Mountain Standard Time");
//UTC time
var utc1 = new DateTime(1990, 10, 28, 7, 0, 0); //This is start of daylight standard time.
var utc2 = new DateTime(1990, 10, 28, 8, 0, 0);
var utc3 = new DateTime(1990, 10, 28, 9, 0, 0);
utc1 = DateTime.SpecifyKind(utc1, DateTimeKind.Utc);
utc2 = DateTime.SpecifyKind(utc2, DateTimeKind.Utc);
utc3 = DateTime.SpecifyKind(utc3, DateTimeKind.Utc);
//Get the local time with adjustment for Daylight standard time, "fall back"
var local1 = TimeZoneInfo.ConvertTimeFromUtc(utc1, tz); //Returns 1am
var local2 = TimeZoneInfo.ConvertTimeFromUtc(utc2, tz); //Returns 1am. Should this be 2am?
var local3 = TimeZoneInfo.ConvertTimeFromUtc(utc3, tz); //Returns 2am
At 2am you "fall back" to 1am (1:59 -> 1), hence 1am is repeated and 2am only occurs one hour later. similarly when you "spring forward" there would be NO 2 AM (1:59 -> 3)
source: http://aa.usno.navy.mil/faq/docs/daylight_time.php (US Naval Observatory keeps the US DoD official time (source for that: http://www.usno.navy.mil/USNO/time))