BEGIN:VEVENT
DTSTART;TZID=America/Los_Angeles:20151116T123000
DTEND;TZID=America/Los_Angeles:20151116T140000
EXDATE;TZID=America/Los_Angeles:20160215T123000
EXDATE;TZID=America/Los_Angeles:20160530T123000
EXDATE;TZID=America/Los_Angeles:20160704T123000
EXDATE;TZID=America/Los_Angeles:20160905T123000
EXDATE;TZID=America/Los_Angeles:20170220T123000
EXDATE;TZID=America/Los_Angeles:20170529T123000
RRULE:FREQ=WEEKLY;BYDAY=MO
DTSTAMP:20161007T103007Z
UID:up5l07cp40qiqia1evqjk02r9c#google.com
CREATED:20151116T002427Z
DESCRIPTION:
LAST-MODIFIED:20160829T190451Z
LOCATION:
SEQUENCE:2
STATUS:CONFIRMED
SUMMARY:iOS Today
TRANSP:OPAQUE
END:VEVENT
I am trying to build a calenderView for an android App using library https://github.com/alamkanak/Android-Week-View and this library https://github.com/mangstadt/biweekly to parse the ICS. However I am having problems creating Events that have recurrence, like in the example.
protected TreeMap<Integer,TreeMap<Integer,List<WeekViewEvent>>> doInBackground(String... params) {
ICalendar ical = Biweekly.parse(params[0]).first();
List<VEvent> le = ical.getEvents();
for(VEvent ev: le){
Calendar startTime = Calendar.getInstance();
startTime.setTimeInMillis(ev.getDateStart().getValue().getTime());
if(ev.getRecurrenceRule()!=null){
//Don't know what do I do here
}
int year = startTime.get(Calendar.YEAR);
int month = startTime.get(Calendar.MONTH);
//Log.v("Calendar",year+" Ano " + month +" Mes");
Calendar endTime = Calendar.getInstance();
if(ev.getDateEnd()==null){
continue;
}
endTime.setTimeInMillis(ev.getDateEnd().getValue().getTime());
WeekViewEvent we = new WeekViewEvent(0,ev.getSummary().getValue(),startTime,endTime);
if(eventos.get(we.getStartTime().get(Calendar.YEAR))==null){
TreeMap<Integer,List<WeekViewEvent>> as = new TreeMap<>();
List<WeekViewEvent> listEv = new ArrayList<>();
listEv.add(we);
as.put(we.getStartTime().get(Calendar.MONTH),listEv);
eventos.put(we.getStartTime().get(Calendar.YEAR),as);
}
else {
TreeMap<Integer, List <WeekViewEvent>> as = eventos.get(we.getStartTime().get(Calendar.YEAR));
if(as.containsKey(we.getStartTime().get(Calendar.MONTH))){
as.get(we.getStartTime().get(Calendar.MONTH)).add(we);
}else {
List<WeekViewEvent> listEv= new ArrayList<>();
listEv.add(we);
as.put(we.getStartTime().get(Calendar.MONTH),listEv);
}
}
}
return eventos;
}
Any help is appreciated.
Maybe you should give iCalendarAgenda a try at http://jfxtras.org/
It utilizes a new iCalendar API for Java called iCalendarFX. While I haven't used it on Android, I know that Tom Eugelink has got the Agenda control (that iCalendarAgenda extends) to run on Android.
I wrote iCalendarFx and it will easily parse the VEVENT you have there.
Related
Trying to insert Current date from android to mysql via Retrofit. The date is showing in the mysql database as 0000-00-00. I've read over multiple threads on SO on this topic and tried to apply the answers but so far I have not been successful. Please see the below code snippets for context.
PHP CODE:
<?php
include('conn.php');
$userId = $_POST['userId'];
$moodBefore = $_POST['moodBefore'];
$automaticThought = $_POST['automaticThought'];
$distortions = $_POST['distortions'];
$challengeThought = $_POST['challengeThought'];
$alternativeThought = $_POST['alternativeThought'];
$moodAfter = $_POST['moodAfter'];
$posted = $_POST['posted'];
$insert = "INSERT INTO Cbt ( userId, moodBefore, automaticThought, distortions, challengeThought, alternativeThought, moodAfter, posted) VALUES
('$userId','$moodBefore', '$automaticThought', '$distortions', '$challengeThought', '$alternativeThought', '$moodAfter', '$posted')";
$resultinsert = $conn -> query($insert);
if(!$resultinsert){
echo $conn->error;
}
?>
RETROFIT API CODE:
public interface Api {
#FormUrlEncoded
#POST("insert.php")
Call<ResponseBody> insertLog(
#Field("userId") int userId,
#Field("moodBefore") int moodBefore,
#Field("automaticThought") String automaticThought,
#Field("distortions") int distortions,
#Field("challengeThought") String challengeThought,
#Field("alternativeThought") String alternativeThought,
#Field("moodAfter") int moodAfter,
#Field("posted") String date
);
JAVA CODE:
String posted = new SimpleDateFormat("ddMMyyyy").format(new Date());
case R.id.nextBtnMoodPage:
if (hasSelected) {
Call<ResponseBody> call = RetrofitClient
.getInstance()
.getApi()
.insertLog(userId, moodBefore, automaticThoughtString, distortions, challengeThoughtString, alternativeThoughtString, moodAfter, posted);
call.enqueue(new Callback<ResponseBody>() {.....and so on
I would like the date to insert succesfully and not show 0000-00-00
If I could also make the date show as DD-MM-YYYY that would be even better.
This worked in the Java code, all other parts of the code stay the same
private Date currentDate() {
final Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, 0);
return cal.getTime();
}
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
String posted = dateFormat.format(currentDate());
I am trying to integrate a database with a web application that extracts event data from Google Calendar API which inputs the data into the database. The following code is identical to the Quickstart class provided by Google.
I basically want 'DateTime start' to be converted to 'long start'. I need the long value for SQL.
import com.google.api.client.util.DateTime;
// ...
DateTime now = new DateTime(System.currentTimeMillis());
Events events = service.events().list(calendarId)
.setTimeMin(now)
.setOrderBy("startTime")
.setSingleEvents(true)
.execute();
List<Event> items = events.getItems();
if (items.isEmpty()) {
System.out.println("No upcoming events found.");
} else {
System.out.println("Upcoming events");
for (Event event : items) {
DateTime start = event.getStart().getDateTime();
DateTime end = event.getEnd().getDateTime();
if (start == null) {
start = event.getStart().getDate();
}
System.out.printf("%s\n", start.toString());
Google has implemented the Rfc3339 parser in Google HTTP Client Library. You can try parsing it first and the use the DateTime.getValue() function to convert it into long.
You may also try using the DatetimeFormatter to format it to the way you want the value.
DateTimeFormatter formatter = DateTimeFormatter
.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
.withZone(ZoneId.of("UTC"));
public void convertDatetime() {
String timeStamp = "2019-05-24T11:32:26.553955473Z";
DateTime dateTime = DateTime.parseRfc3339(timeStamp);
long millis = dateTime.getValue();
String result = formatter.format(new Date(millis).toInstant());
I am trying to convert pure java code into swift.But,I am having a little problem with setting the current time.I can get the current time in milliseconds.But I cant set the current time.Any help with that?
Here is my code
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
let now = NSDate()
var auctionDate = [String:String]()
let dateFormatter = NSDateFormatter()
dateFormatter.locale = NSLocale(localeIdentifier: "en_US")
var sdfDDMMYYYYEEE : NSDateFormatter!
sdfDDMMYYYYEEE.dateFormat = "dd/MM/yyyy (EEE)"
var sdfDDMMYYYY : NSDateFormatter!
sdfDDMMYYYY.dateFormat = "dd/MM/yyyy"
var sdfEEE : NSDateFormatter!
sdfEEE.dateFormat = "EEE"
// This is how i get the current time
println((now.timeIntervalSince1970)*1000 + 86400000.00)
for var i = 0; i < 5; i++ {
if sdfEEE.stringFromDate(now) == "Sun" {
// This is where i have to set my time with that ((now.timeIntervalSince1970)*1000 + 86400000.00)
i--;
continue;
}
auctionDate[(sdfDDMMYYYY.stringFromDate(now) as String)] = (sdfDDMMYYYYEEE.stringFromDate(now) as String)
// Here too I have to set my time
}
println(dateFormatter.stringFromDate(now))
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Here is the java code that I want to convert into swift code
import java.text.*;
import java.util.*;
public class DateTest{
Date now = new Date();
Map<String, String> myDate = new LinkedHashMap<String, String>();
myDate.put("", "All");
SimpleDateFormat sdfDDMMYYYYEEE = new SimpleDateFormat("dd/MM/yyyy (EEE)");
SimpleDateFormat sdfDDMMYYYY = new SimpleDateFormat("dd/MM/yyyy");
SimpleDateFormat sdfEEE = new SimpleDateFormat("EEE");
for (int i = 0; i < 5; i++) {
if (sdfEEE.format(now).equals("Sun")) {
now.setTime(now.getTime() + 86400000);
i--;
continue;
}
myDate.put(sdfDDMMYYYY.format(now), sdfDDMMYYYYEEE.format(now));
now.setTime(now.getTime() + 86400000);
}
}
Any help with setting the current time in swift.I am almost closing to my answer.
In your code you want to add seconds to time eince 1970. You're in luck, there is an initializer for that: NSDate(timeIntervalSince1970: NSTimeInterval)
let now = NSDate(timeIntervalSince1970: 86400000)
This will create a new NSDate and add 86400000 seconds to the time in seconds right now since 1970.
I am getting exception while invoking NotesCalendar.getNewInvitations method.
NotesException: NotesCalendar error: The database handle is NULL
at lotus.domino.local.NotesCalendar.NgetNewInvitations(Native Method)
at lotus.domino.local.NotesCalendar.getNewInvitations(Unknown Source)
at JavaAgent.main(Unknown Source)
I am trying to run this code locally to Domino Server.
import lotus.domino.*;
public class JavaAgent extends NotesThread {
public static void main(String []args){
try
{
NotesThread.sinitThread(); // start thread
Session session = NotesFactory.createSession();
System.out.println("session="+session);
// (Your code goes here)
DbDirectory dbdir = session.getDbDirectory("");
System.out.println("dbdir="+dbdir);
Database db1= session.getDatabase("server", "Conf");
NotesCalendar cal = session.getCalendar(db1);
java.util.Calendar jdt = java.util.Calendar.getInstance();
jdt.set(2015, 1, 1, 1, 1, 1);
DateTime dt1 = session.createDateTime(jdt);
DateTime dt2 = session.createDateTime("Yesterday 02");
// java.util.Vector invites = cal.getNewInvitations(dt1, dt2);
// System.out.println("invites "+invites.size());
java.util.Vector invites= cal.getEntries(dt1, dt2);
for (int j = 0; j < 3; j++) {
// Create document to post results
Document doc = db1.createDocument();
doc.appendItemValue("Form", "main");
doc.appendItemValue("subject", "New invitations");
RichTextItem body = doc.createRichTextItem("body");
if (invites.size() == 0) body.appendText("No invitations");
else {
for (int i = 0; i < invites.size(); i++) {
NotesCalendarNotice cale = (NotesCalendarNotice)invites.elementAt(i);
body.appendText(cale.read());
cale.recycle();
body.addNewLine();
}
}
doc.save(true, true);
java.util.concurrent.TimeUnit.MINUTES.sleep(30);
invites = cal.getNewInvitations(dt1, cal.getUntilTime());
} }
catch(Exception e)
{
e.printStackTrace();
}
finally
{
NotesThread.stermThread(); // must terminate every thread
}
}
}
The simple answer is getNewInvitations() doesn't make sense in the context of a resource reservation database. The method was designed to read unprocessed invitations from a mail file.
However, in the comments you say your code doesn't work for mail files either. It might be helpful to get something simpler to work and then build on that. I just tried the following code:
database = session.getDatabase(null, "mail/user.nsf");
NotesCalendar calendar = session.getCalendar(database);
// Start date is 01-Jan-2015
java.util.Calendar start = java.util.Calendar.getInstance();
start.set(2015, 0, 1);
dtStart = session.createDateTime(start);
// End date is now
java.util.Calendar end = java.util.Calendar.getInstance();
dtEnd = session.createDateTime(end);
// Get entries on the calendar between start and end
Vector<?> entries = calendar.getEntries(dtStart, dtEnd);
System.out.println("Number of entries is " + entries.size());
// Get invitations from start date (from the Inbox)
Vector<?> invites = calendar.getNewInvitations(dtStart, calendar.getUntilTime());
System.out.println("Number of invites is " + invites.size());
Everything worked as expected. Perhaps you could try the above code and see if getNewInvitations() still throws an exception.
This is my piece of code to create java calendar object in Node.js using node-java module.
var java = require("java");
java.classpath.push("commons-lang3-3.1.jar");
java.classpath.push("commons-io.jar");
java.classpath.push("common-util.jar");
var vehId = java.newInstanceSync("java.lang.Integer", 922);
var lattitude = java.newInstanceSync("java.lang.Double", 8.6717136);
var longitude = java.newInstanceSync("java.lang.Double", 76.8168311);
var time= '';
var Calendar = java.newInstance("java.util.Calendar", function(err, result) {
if(err) {
console.log('Error: '+err);
return;
}
else {
console.log("Result: "+result);
time = Calendar.getInstance();
}
});
var args = {
vehicleId : vehId,
lat : lattitude,
lan : longitude,
packetTime : time
};
console.log(args);
This is the error got when tried to execute the program.
Error: Could not find method "java.util.Calendar()" on class "class java.util.Calendar". No methods with that name.
Couldn't create calendar object using java.newInstance() or java.newInstanceSync() functions.
Try this.
var Calendar = java.newInstanceSync("java.util.GregorianCalendar");
It will create a default GregorianCalendar using the current time in the default time zone.