1

我有从 Lotus Notes Domino 服务器查询日历条目的 Java 代码(基于开始和结束日期范围)。下面是代码的简化版本。

当查询日期格式与本地客户端相同的 Domino 服务器时,一切都很好,例如服务器和客户端都使用 m/d/y 格式。但是,如果服务器和客户端使用不同的格式(例如,服务器使用美国格式 m/d/y,客户端使用德语格式 d/m/y),则会发现错误数量的 Lotus Notes 条目。

这是因为我使用 getLocalTime() 将日期转换为本地字符串,然后使用 @TextToTime() 创建日期范围。

有没有办法找出服务器使用的日期格式?或者有没有办法完全避免日期到字符串的转换?我想传入两个 Lotus DateTime 对象,让服务器根据需要对它们进行解码。

import lotus.domino.*;


Session session = NotesFactory.createSession((String)null, (String)null, password);

Database db = session.getDatabase(dominoServer, mailfile, false);

// Get our start and end query dates in Lotus Notes format. We will query
// using the localized format for the dates.
lotus.domino.DateTime minStartDateLN = session.createDateTime(minStartDate);
lotus.domino.DateTime maxEndDateLN = session.createDateTime(maxEndDate);

// Query Lotus Notes to get calendar entries in our date range. 
// Here is an overview of this SELECT:
//   @IsAvailable(CalendarDateTime) is true if the LN document is a calendar entry
//   @Explode splits a string based on the delimiters ",; "
//   The operator *= is a permuted equal operator. It compares all entries on
//   the left side to all entries on the right side. If there is at least one
//   match, then true is returned. Explode is used because the CalendarDateTime
//   field can have many dates separated by ";" (e.g. for recurring meetings).
String calendarQuery = "SELECT (@IsAvailable(CalendarDateTime) & (@Explode(CalendarDateTime) *= @Explode(@TextToTime(\""
+ minStartDateLN.getLocalTime()
+ "-" + maxEndDateLN.getLocalTime() + "\"))))";

DocumentCollection queryResults = db.search(calendarQuery);
4

3 回答 3

1

您可以使用本机 Java 或 Lotus DateTime 方法从最小值和最大值中提取单独的年、月、日、小时、分钟和秒值,然后使用 @Date(year,month,day) 在查询中构建日期,小时,分钟,秒)

于 2012-02-17T01:34:15.793 回答
1

尝试格式化您正在搜索的日期 - 因此它将成为所有位置的通用格式:@TextToTime(@Text(CalendarDateTime))

另一个想法是使用像 Ytria 的 ScanEZ 这样的工具来查看日历条目中的所有字段/数据。相信有一个字段将以您可以搜索的通用格式保存日期。

于 2012-02-25T23:48:13.960 回答
1

有一种方法可以使用 Java lotus.domino.International 类(又名 NotesInternational 类)在 Domino 服务器上查找日期格式。这是最终的工作代码。

import lotus.domino.*;

Session session = NotesFactory.createSession((String)null, (String)null, password);

Database db = session.getDatabase(dominoServer, mailfile, false);

String strDateFormat;
// Get the date separator used on the Domino server, e.g. / or -
String dateSep = session.getInternational().getDateSep();

// Determine if the server date format is DMY, YMD, or MDY
if (session.getInternational().isDateDMY()) {
    strDateFormat = "dd" + dateSep + "MM" + dateSep + "yyyy";                
}
else if (session.getInternational().isDateYMD()) {
    strDateFormat = "yyyy" + dateSep + "MM" + dateSep + "dd";
}
else {
    strDateFormat = "MM" + dateSep + "dd" + dateSep + "yyyy";
}

DateFormat dateFormat = new SimpleDateFormat(strDateFormat);


String calendarQuery = "SELECT (@IsAvailable(CalendarDateTime) & (@Explode(CalendarDateTime) *= @Explode(@TextToTime(\"" +
    dateFormat.format(startDate) + " - " + dateFormat.format(endDate) + "\"))))";

DocumentCollection queryResults = db.search(calendarQuery); 
于 2012-03-06T13:39:31.180 回答