2012-02-16 27 views
1

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

查询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); 

回答

0

有一种方法可以使用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); 
1

您可以提取个人的年,月,日,小时,即使用本地Java或Lotus的DateTime方法分钟,并从您的最小值和最大值第二值,然后建立查询使用日期@日期(年,月,日,时,分,秒)

+0

我试过了,如果我只是查询一个日期,它会起作用。不幸的是,我永远不知道如何使用@Date格式指定日期范围(从头到尾)。仅供参考:我现在发布了一个可行的解决方案。 – 2012-03-06 13:43:42

1

尝试格式化您正在搜索的日期 - 所以它会在所有地区通用格式: @TextToTime(@Text(CalendarDateTime))

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

+0

我试图找到一种通用的格式,例如yyyy-mm-ddThh:mm:ss,但永远找不到适用于所有Domino服务器的格式。仅供参考:我现在发布了一个可行的解决方案。 – 2012-03-06 13:41:02

相关问题