1
0
mirror of https://github.com/GitJournal/GitJournal.git synced 2025-07-08 09:00:54 +08:00

GitCommit: Let us specify the date time

The Timezone handling is java seems to be quite strange, so I'm going to
skip it for now and fix it later. We do seem to have proper timezone
classes in future versions of Java, but that requires me to increase the
minSDKVersion, and therefore not support very old android devices.
This commit is contained in:
Vishesh Handa
2019-01-23 11:03:06 +01:00
parent 519de8fcff
commit 8b40cd2285
4 changed files with 40 additions and 3 deletions
android/app/src/main/java/io/gitjournal/gitjournal
lib

@ -8,8 +8,13 @@ import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.CommitCommand;
import org.eclipse.jgit.api.errors.TransportException;
import org.eclipse.jgit.lib.PersonIdent;
import java.io.File;
import java.util.*;
import java.text.SimpleDateFormat;
import java.util.TimeZone;
import java.util.SimpleTimeZone;
import io.flutter.plugin.common.MethodChannel.Result;
@ -26,6 +31,7 @@ public class GitCommitTask extends AsyncTask<String, Void, Void> {
final String authorName = params[1];
final String authorEmail = params[2];
final String message = params[3];
final String commitDateTimeStr = params[4];
File cloneDir = new File(cloneDirPath);
Log.d("GitClone Directory", cloneDirPath);
@ -33,8 +39,35 @@ public class GitCommitTask extends AsyncTask<String, Void, Void> {
try {
Git git = Git.open(cloneDir);
PersonIdent identity = new PersonIdent(authorName, authorEmail);
if (commitDateTimeStr != null && !commitDateTimeStr.isEmpty()) {
Log.d(TAG, "CustomDateTime: " + commitDateTimeStr);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
Date date = format.parse(commitDateTimeStr);
TimeZone tz = identity.getTimeZone();
// Check for timezone
/*
if (commitDateTimeStr.indexOf('+') == 19) {
// FIXME: This does not deal with timezones with minutes!
int hours = Integer.parseInt(commitDateTimeStr.substring(20, 22));
int minutes = Integer.parseInt(commitDateTimeStr.substring(23));
Log.d(TAG, "TimeZone Hours: " + hours);
Log.d(TAG, "TimeZone Minutes: " + minutes);
tz = new SimpleTimeZone(hours, "foo");
} else {
Log.d(TAG, "No custom timezone provided");
}
*/
identity = new PersonIdent(identity, date, tz);
} else {
Log.d(TAG, "No custom datetime provided");
}
CommitCommand commitCommand = git.commit();
commitCommand.setAuthor(authorName, authorEmail);
commitCommand.setAuthor(identity);
commitCommand.setMessage(message);
commitCommand.setAllowEmpty(false);
commitCommand.call();

@ -124,6 +124,7 @@ public class MainActivity extends FlutterActivity {
String authorName = call.argument("authorName");
String authorEmail = call.argument("authorEmail");
String message = call.argument("message");
String dateTimeStr = call.argument("when");
if (folderName == null || folderName.isEmpty()) {
result.error("Invalid Parameters", "folderName Invalid", null);
@ -144,7 +145,7 @@ public class MainActivity extends FlutterActivity {
String cloneLocation = filesDir + "/" + folderName;
new GitCommitTask(result).execute(cloneLocation, authorName, authorEmail, message);
new GitCommitTask(result).execute(cloneLocation, authorName, authorEmail, message, dateTimeStr);
return;
} else if (call.method.equals("gitInit")) {
String folderName = call.argument("folderName");

@ -40,7 +40,7 @@ buildGitButtons() {
RaisedButton(
child: Text("Git Add"),
onPressed: () async {
await gitAdd("journal", "1");
await gitAdd("journal", ".");
},
),
RaisedButton(
@ -57,6 +57,7 @@ buildGitButtons() {
authorEmail: "noemail@example.com",
authorName: "Vishesh Handa",
message: "Default message from GitJournal",
when: "2017-10-20T01:21:10+02:00",
);
}),
];

@ -133,6 +133,7 @@ Future gitCommit({
String authorName,
String authorEmail,
String message,
String when,
}) async {
print("Going to git commit");
try {
@ -141,6 +142,7 @@ Future gitCommit({
'authorName': authorName,
'authorEmail': authorEmail,
'message': message,
'when': when,
});
print("Done");
} on PlatformException catch (e) {