SvnRevisionRange not taking time correctly - sharpsvn

When creating a SvnRevisionRange, range.StartRevision.Time decreases 5 hours to the date time provided. So when getting the log it doesn't retrieve the correct logs since the time is not passed correctly. Can anyone help? SharpSvn version is 1.6017.1920.11722 in .net 3.5
DateTime startDateTime = dtStart.DateTime.Date;
DateTime endDateTime = dtEnd.DateTime.Date.AddHours(23).AddMinutes(59).AddSeconds(59);
SvnRevisionRange range = new SvnRevisionRange(new SvnRevision(startDateTime), new SvnRevision(endDateTime));

Just to clarify the question-- you're saying that the time properties of the SvnRevisionRange object are inconsistent with the values originally passed in?
If so, this test would fail:
DateTime startDateTime = DateTime.UtcNow.AddDays(-1);
DateTime endDateTime = DateTime.UtcNow;
SvnRevisionRange range = new SvnRevisionRange(new SvnRevision(startDateTime), new SvnRevision(endDateTime));
Assert.AreEqual(startDateTime, range.StartRevision.Time, "The start times are not equal");
Assert.AreEqual(endDateTime, range.EndRevision.Time, "The end times are not equal");
Run the code above as a unit test and post the results...

Related

Date Format For Google Classroom API ScheduledTime

I'm trying to set the scheduled time when creating an assignment using the Google Classroom API. However, I'm confused about which date format is needed. By the error messages, it seems to accept a string which holds a timestamp and a timezone or Z at the end. Among others, I've tried using System.currentTimeMillis() + "Z", as well as googleDate.getValue() + "Z", googleDate.getValue() since Google Date format seems to be the way to go based on this doc but none of them seem to work.
Any ideas perhaps?
Thank you.
String timezone = timestamp + offset + "";
System.currentTimeMillis()
com.google.api.client.util.DateTime googleDate =
new com.google.api.client.util.DateTime(new java.util.Date());
// Date javaDate = new Date(googleDate.getValue());
CourseWork courseWork = new CourseWork()
.setCourseId(course.getId())
.setTitle("title PUBLISHED 2")
.setDescription("desc")
.setScheduledTime(googleDate.getValue() + "Z")
.setMaxPoints(100.0)
.setDueDate(date)
.setDueTime(timeOfDay)
.setWorkType("ASSIGNMENT")
.setState("PUBLISHED")
;
This is what I get when I manually add a timestamp and turn it into a string.
And this using the Google date instead.
And this with the new Java 8 apis
java.time
I recommend that you use java.time, the modern Java date and time API, for your date and time work. The following code gives the same result as the code from your answer.
LocalDate localDate = LocalDate.now().plusDays(7);
String s = localDate.atStartOfDay(ZoneId.systemDefault())
.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
System.out.println(s);
Output in my time zone today:
2021-10-20T00:00:00+02:00
Compared to your own answer you have fewer conversions, and you are freed from writing your own format pattern string since the formatter we need is built in.
This worked:
LocalDate localDate = LocalDate.now().plusDays(7);
java.util.Date date1 = java.util.Date.from(localDate.atStartOfDay()
.atZone(ZoneId.systemDefault())
.toInstant());
String s = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX").format(date1);
It seems the imports were using the Google Date class instead of java.util.date.

PDFbox Document Propperties will not set

In Tutorialspoint is learn about PDFbox.
PDFbox Tutorialpoint
I put an method in my programm to update the metadata from an existing PDF-File.
The Document Properties will not set and i spent many hours to find out why.
When the modification date ".setModificationDate()" will be wrong or coment out, the meatadata of documet properties will not changed.
I dont want to put a static date as the tutorial, i want to insert variables.
//Setting the created date of the document
Calendar date = new GregorianCalendar();
date.set(2015, 11, 5);
//Setting the modified date of the document
date.set(2016, 6, 5);
// Save the metadata to file
pdfDocument.setModificationDate(date);
The data of the ".setModificationDate()" method are want a "Calendar" type.
I do it on different ways and nothing will be work.
Try first
Calendar transfomedDate = new GregorianCalendar();
transfomedDate = convertStringDateToCalendar(StringDate);
Calendar modifiedDate = new GregorianCalendar();
modifiedDate.set(transfomedDate.get(Calendar.YEAR),
transfomedDate.get(Calendar.MONTH),
transfomedDate.get(Calendar.DAY_OF_MONTH),
transfomedDate.get(Calendar.HOUR_OF_DAY),
transfomedDate.get(Calendar.MINUTE),
transfomedDate.get(Calendar.SECOND));
pdfDocument.setModificationDate(modifiedDate);
This Methos will be work correctly on creating Date but not on mofdificationDate?
Then i will trying to put the parameters of the modification in "int" variables and use it on this way.
Calendar transfomedDate = new GregorianCalendar();
transfomedDate = convertStringDateToCalendar(StringDate);
int year = transfomedDate.get(Calendar.YEAR);
int month = transfomedDate.get(Calendar.MONTH);
int day = transfomedDate.get(Calendar.DAY_OF_MONTH)
Calendar modifiedDate = new GregorianCalendar();
// modifiedDate.set(2017, 10, 11);
modifiedDate.set(year, month, day);
pdfDocument.setModificationDate(modifiedDate);
It will not work to.
I dont knwo why PDFbox will not aipdate the metadate when the modficationDate will be commet out or be wrong. I can be ignore the it are wrong?
I dont know what i can do now?
Thanks
Mike

How to create a datetime in apex given a datetime string?

With apex, I pass a string like:
2017-02-05T01:44:00.000Z
to an apex function from javascript, however, when attempting to turn it into a datetime, it gives me invalid date/time error. I can create a date with it like
date newdate = date.valueOf(dateString);
but if I do datetime newdate = datetime.valueOf(dateString) I get the error. I don't get why it sees the string as incorrectly formatted to give invalid date/time. When I create just a date instead of datetime, I lose the time and it sets it to 00:00:00.
Thank you to anyone with some insight on how to create the datetime in apex! I have been trying to find the apex format and from what I see. I can't understand why it thinks this is invalid.
Try this.
String inpputString = '2017-02-05T01:44:00.000Z';
DateTime resultDateTime = DateTime.ValueofGmt(inpputString.replace('T', ' '));
System.Debug('resultDateTime>> '+resultDateTime);
Output:
10:10:41:011 USER_DEBUG [4]|DEBUG|resultDateTime>> 2017-02-05 01:44:00

Convert milliseconds to date string back and forth using java 7

I have the following code which uses all recommendations discussed in similar questions.
public class DateUtils {
static String secondsToDate(String seconds) {
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(Long.parseLong(seconds) * 1000);
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH);
int day = calendar.get(Calendar.DAY_OF_MONTH);
return String.format("%d-%d-%d", year, month, day);
}
static String dateToSeconds(String date) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
try {
Date parsed = format.parse(date);
long timeInMillis = parsed.getTime();
return Long.toString(timeInMillis / 1000);
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
public static void main(String[] args) {
String timestamp = "1409515200";
String date = secondsToDate(timestamp);
String timestamp2 = dateToSeconds(date);
System.out.printf("%s %s", timestamp, timestamp2);
}
}
The result of the code:
1409515200 1406836800
As you can see the conversion back and forth doesn't work. What's wrong?
Your problem here is the rounding. In the first method, you are converting your timestamp (which is the number of milliseconds from 1970) into a date. You are now getting only the date, discarding hours, minutes, seconds and milliseconds and converting it back. This means that you will always have a difference of the amount you are discarding (between 0 at 00:00:00:000 and 86400000 at 23:59:59:999). To fix it, simply change your date format to include the hours with milliseconds precision.
The answer by Aurasphere is correct and should be accepted.
Some further tips…
Use date-time classes for date-time values, rather than strings. Perform your business logic using date-time objects, and pass around such objects amongst your code rather than strings.
Avoid tracking date-times as a count-from-epoch. When you do need to serialize to text, use the unambiguous and easy-to-read formats defined by the ISO 8601 standard such as 2016-05-09T16:47:54Z.
You are using old troublesome legacy classes that have been supplanted by the java.time framework built into Java 8 and later. Much of that functionality has been back-ported to Java 6 & 7 in the ThreeTen-Backport project, and further adapted for Android in the ThreeTenABP project.
Using java.time classes will make your work easier and your code easier to comprehend, less likely to encounter the confusion seen in the Question.
An Instant is a moment on the timeline in UTC, with a resolution of nanoseconds. That class offers a convenient factory method ofEpochSecond, so no need to multiply by a thousand for milliseconds.
String input = "1409515200";
long seconds = Long.parseLong( input );
Instant instant = Instant.ofEpochSecond( seconds );
To get the wall-clock time for some locality, assign a time zone to get a ZonedDateTime.
ZoneId zoneId = ZoneId.of( "America/Montreal" );
ZonedDateTime zdt = ZonedDateTime.ofInstant( instant , zoneId );
To generate a string in standard ISO 8601 format, call toString. Note that this method extends that format to append the name of the time zone in square brackets. For example, 2007-12-03T10:15:30+01:00[Europe/Paris].
String output = zdt.toString();
To get the date-only as in the Question, extract a LocalDate object.
LocalDate localDate = zdt.toLocalDate();
From there you can determine the first moment of the day. The first moment is not always the time-of-day 00:00:00.0, so let java.time determine that.
ZonedDateTime zdtStartOfDay = localDate.atStartOfDay( zoneId );
To get the two long integer counts of seconds seen in the Question, extract an Instant from each of our ZonedDateTime objects, and ask for the seconds-since-epoch. Note that you might be losing data as the ZonedDateTime/Instant objects can store values with a resolution up to nanoseconds. The call asking for whole seconds from epoch means any fraction of a second is truncated.
long seconds1 = zdt.toInstant().getEpochSecond();
long seconds2 = zdtStartOfDay.toInstant().getEpochSecond();

breezejs: date is not set to the right time

I've noticed that if a date property comes back from the server with the value "2013-07-11T17:11:04.700", then breeze changes the value to Thu Jul 11 19:11:04 UTC+0200 2013.
Notice the time is now 2 hours ahead !
I had already come across this issue when saving entities, so I had to explicitly convert my date properties using momentjs :
date.hours(date.hours() - moment().zone() / 60);
But now it seems the problem occurs also when doing read operations.
What's the best way to make sure breeze does not alter values of my date properties ?
Breeze does not manipulate the datetimes going to and from the server in any way EXCEPT to add a UTZ timezone specifier to any dates returned from the server that do not already have one. This is only done because different browsers interpret dates without a timezone specifier differently and we want consistency between browsers.
The source of your issues is likely to be that when you save your data with dates to the database, that the dateTime datatype you are using does NOT contain a timezone offset. This means that when the data is retrieved you are likely "losing" the offset and the Breeze default mentioned above kicks in. This can be corrected by using a database date time datatype with an timezone offset ( datetime2 or datetimeoffset in SQLServer).
Note that your browser DOES format dates according to it's current timezone.
Another approach is that you can replace Breeze's DataType.parseDateFromServer to NOT infer any time zone info if it is not provided:
breeze.DataType.parseDateFromServer = function (source) {
return new Date(Date.parse(source));
};
However, this can run into the problem that different browsers interpret DateTime strings without a time zone offset differently... So you may still get strange results depending on the browser. If that happens you will need to add some browser detection code to the snippet above.
Another alternative is to do the following using the moment.js library.
breeze.DataType.parseDateFromServer = function (source) {
var date = moment(source);
return date.toDate();
};
Not sure how helpful this is, but hopefully Breeze's behavior is clearer.
By default, Breeze does not provide any way to do this, but you can keep the below code in your model JS file to overcome this issue:
breeze.DataType.parseDateFromServer = function (source) {
if (typeof source === 'string') {
//Check for local offset time or UTC time from server
if (source.slice(-1) !== "Z") {
var oldSource = source;
try {
source = source.substring(0, source.lastIndexOf("-") - 1)
source = new Date(source);
var tzDifference = source.getTimezoneOffset();
//convert the offset to milliseconds, add to targetTime, and make a new Date
var offsetTime = new Date(source.getTime() + tzDifference * 60 * 1000);
return offsetTime;
}
catch (err) {
source = new Date(source);
return source;
}
}
else {
source = new Date(source);
var tzDifference = source.getTimezoneOffset();
//convert the offset to milliseconds, add to targetTime, and make a new Date
var offsetTime = new Date(source.getTime() + tzDifference * 60 * 1000);
return offsetTime;
}
}
}