本文整理汇总了Java中com.google.api.client.util.DateTime类的典型用法代码示例。如果您正苦于以下问题:Java DateTime类的具体用法?Java DateTime怎么用?Java DateTime使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DateTime类属于com.google.api.client.util包,在下文中一共展示了DateTime类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkValidAddress
import com.google.api.client.util.DateTime; //导入依赖的package包/类
/**
* verifies that an address url is a valid Calendar address Saber can
* sync with
* @param address (String) google calendar address
* @param service connected calendar service with user credentials
* @return (boolean) true if valid
*/
public boolean checkValidAddress(String address, Calendar service)
{
try
{
service.events().list(address)
.setTimeMin(new DateTime(ZonedDateTime.now().format(EventRecurrence.RFC3339_FORMATTER)))
.setTimeMax(new DateTime(ZonedDateTime.now().plusDays(7).format(EventRecurrence.RFC3339_FORMATTER)))
.setOrderBy("startTime")
.setSingleEvents(true)
.setMaxResults(Main.getBotSettingsManager().getMaxEntries())
.execute();
return true;
}
catch(Exception e)
{
return false;
}
}
示例2: getEntries
import com.google.api.client.util.DateTime; //导入依赖的package包/类
/**
* Gets a list of entries belonging to the given calendar defined between the given range of time. Recurring events
* are not expanded, always recurrence is handled manually within the framework.
*
* @param calendar The calendar owner of the entries.
* @param startDate The start date, not nullable.
* @param endDate The end date, not nullable
* @param zoneId The timezone in which the dates are represented.
* @return A non-null list of entries.
* @throws IOException For unexpected errors
*/
public List<GoogleEntry> getEntries(GoogleCalendar calendar, LocalDate startDate, LocalDate endDate, ZoneId zoneId) throws IOException {
if (!calendar.existsInGoogle()) {
return new ArrayList<>(0);
}
ZonedDateTime st = ZonedDateTime.of(startDate, LocalTime.MIN, zoneId);
ZonedDateTime et = ZonedDateTime.of(endDate, LocalTime.MAX, zoneId);
String calendarId = URLDecoder.decode(calendar.getId(), "UTF-8");
List<Event> events = dao.events()
.list(calendarId)
.setTimeMin(new DateTime(Date.from(st.toInstant())))
.setTimeMax(new DateTime(Date.from(et.toInstant())))
.setSingleEvents(false)
.setShowDeleted(false)
.execute()
.getItems();
return toGoogleEntries(events);
}
示例3: getDateTime
import com.google.api.client.util.DateTime; //导入依赖的package包/类
/**
* Convert Google's rather strange and nonstandard solution to a format we can work with.
* Note that this will return null if there is no time information
* @param dt The original DateTime object
* @return A parsed java LocalDateTime object
*/
public static LocalDateTime getDateTime(DateTime dt){
try {
DateTimeFormatter f = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
return LocalDateTime.parse(dt.toStringRfc3339(), f);
}
catch(Exception e) { e.printStackTrace(); return null; }
}
示例4: getDataFromApi
import com.google.api.client.util.DateTime; //导入依赖的package包/类
@Override
protected List<Event> getDataFromApi() throws IOException {
Date start = mMonth;
start.setDate(1);
start.setHours(0);
start.setMinutes(0);
DateTime dateTime = new DateTime(mMonth);
Date end = (Date) start.clone();
end.setMonth(start.getMonth() + 1);
end.setHours(0);
end.setMinutes(0);
DateTime nextMonth = new DateTime(end);
Log.d(TAG, "Find events between " + dateTime.toString() + " and " + end.toString());
return getCalendarService().events().list(mCalendarId)
.setTimeMin(dateTime)
.setTimeMax(nextMonth)
.setSingleEvents(true)
.execute()
.getItems();
}
示例5: send
import com.google.api.client.util.DateTime; //导入依赖的package包/类
Object send() throws IOException {
Log.d(TAG, "Sending message Add Record for scene " + sceneNo);
SceneRecord record = new SceneRecord();
SceneService.AddRecord addRecord = null;
record.set("id", sceneNo + bestScore.getPlayerId());
record.set("sceneNo", sceneNo);
record.set("playerId", bestScore.getPlayerId());
record.set("score", bestScore.getScore());
record.set("lives", bestScore.getLives());
record.set("attempts", bestScore.getAttempts());
record.set("date", new DateTime(System.currentTimeMillis()));
addRecord = BestScoreService.remoteService.addRecord(record);
Object o = addRecord.execute();
//todo evaluate o
Log.d(TAG, addRecord.toString());
return o;
}
示例6: addSchedule
import com.google.api.client.util.DateTime; //导入依赖的package包/类
public String addSchedule(Date start, Date end, String title, String description, String location, String color, ArrayList<String> recurrence, TimeZone timezone) throws Exception {
String id = null;
Event googleSchedule = new Event();
googleSchedule.setStart(new EventDateTime().setTimeZone(timezone.getID()).setDateTime(new DateTime(start)));
googleSchedule.setEnd(new EventDateTime().setTimeZone(timezone.getID()).setDateTime(new DateTime(end)));
googleSchedule.setRecurrence(null);
googleSchedule.setSummary(title.trim());
googleSchedule.setDescription(description.trim());
googleSchedule.setLocation(location.trim());
googleSchedule.setColorId(color);
googleSchedule.setRecurrence(recurrence);
Event createdEvent = this.CALENDAR.events().insert(this.CALENDAR_NAME, googleSchedule).execute();
id = createdEvent.getId();
return id;
}
示例7: asMsSinceEpoch
import com.google.api.client.util.DateTime; //导入依赖的package包/类
/**
* Return timestamp as ms-since-unix-epoch corresponding to {@code timestamp}.
* Return {@literal null} if no timestamp could be found. Throw {@link IllegalArgumentException}
* if timestamp cannot be recognized.
*/
@Nullable
private static Long asMsSinceEpoch(@Nullable String timestamp) {
if (Strings.isNullOrEmpty(timestamp)) {
return null;
}
try {
// Try parsing as milliseconds since epoch. Note there is no way to parse a
// string in RFC 3339 format here.
// Expected IllegalArgumentException if parsing fails; we use that to fall back
// to RFC 3339.
return Long.parseLong(timestamp);
} catch (IllegalArgumentException e1) {
// Try parsing as RFC3339 string. DateTime.parseRfc3339 will throw an
// IllegalArgumentException if parsing fails, and the caller should handle.
return DateTime.parseRfc3339(timestamp).getValue();
}
}
示例8: testQuery
import com.google.api.client.util.DateTime; //导入依赖的package包/类
@Test
public void testQuery() throws Exception {
// using com.google.api.services.calendar.model.FreeBusyRequest message
// body for single parameter "content"
com.google.api.services.calendar.model.FreeBusyRequest request = new FreeBusyRequest();
List<FreeBusyRequestItem> items = new ArrayList<FreeBusyRequestItem>();
items.add(new FreeBusyRequestItem().setId(getCalendar().getId()));
request.setItems(items);
request.setTimeMin(DateTime.parseRfc3339("2014-11-10T20:45:30-00:00"));
request.setTimeMax(DateTime.parseRfc3339("2014-11-10T21:45:30-00:00"));
final com.google.api.services.calendar.model.FreeBusyResponse result = requestBody("direct://QUERY", request);
assertNotNull("query result", result);
LOG.debug("query: " + result);
}
示例9: updateFile
import com.google.api.client.util.DateTime; //导入依赖的package包/类
public void updateFile(SyncItem syncItem) {
Drive drive = driveFactory.getDrive(this.credential);
try {
java.io.File localFile = syncItem.getLocalFile().get();
File remoteFile = syncItem.getRemoteFile().get();
BasicFileAttributes attr = Files.readAttributes(localFile.toPath(), BasicFileAttributes.class);
remoteFile.setModifiedTime(new DateTime(attr.lastModifiedTime().toMillis()));
if (isGoogleAppsDocument(remoteFile)) {
return;
}
LOGGER.log(Level.INFO, "Updating file " + remoteFile.getId() + " (" + syncItem.getPath() + ").");
if (!options.isDryRun()) {
Drive.Files.Update updateRequest = drive.files().update(remoteFile.getId(), remoteFile, new FileContent(determineMimeType(localFile), localFile));
//updateRequest.setModifiedDate(true);
File updatedFile = executeWithRetry(options, () -> updateRequest.execute());
syncItem.setRemoteFile(Optional.of(updatedFile));
}
} catch (IOException e) {
throw new JDriveSyncException(JDriveSyncException.Reason.IOException, "Failed to update file: " + e.getMessage(), e);
}
}
示例10: updateMetadata
import com.google.api.client.util.DateTime; //导入依赖的package包/类
public void updateMetadata(SyncItem syncItem) {
Drive drive = driveFactory.getDrive(this.credential);
try {
java.io.File localFile = syncItem.getLocalFile().get();
File remoteFile = syncItem.getRemoteFile().get();
BasicFileAttributes attr = Files.readAttributes(localFile.toPath(), BasicFileAttributes.class);
if (isGoogleAppsDocument(remoteFile)) {
return;
}
LOGGER.log(Level.FINE, "Updating metadata of remote file " + remoteFile.getId() + " (" + syncItem.getPath() + ").");
if (!options.isDryRun()) {
File newRemoteFile = new File();
newRemoteFile.setModifiedTime(new DateTime(attr.lastModifiedTime().toMillis()));
Drive.Files.Update updateRequest = drive.files().update(remoteFile.getId(), newRemoteFile).setFields("modifiedTime");
File updatedFile = executeWithRetry(options, () -> updateRequest.execute());
syncItem.setRemoteFile(Optional.of(updatedFile));
}
} catch (IOException e) {
throw new JDriveSyncException(JDriveSyncException.Reason.IOException, "Failed to update file: " + e.getMessage(), e);
}
}
示例11: store
import com.google.api.client.util.DateTime; //导入依赖的package包/类
public void store(SyncDirectory syncDirectory) {
Drive drive = driveFactory.getDrive(this.credential);
try {
java.io.File localFile = syncDirectory.getLocalFile().get();
File remoteFile = new File();
remoteFile.setName(localFile.getName());
remoteFile.setMimeType(MIME_TYPE_FOLDER);
remoteFile.setParents(createParentReferenceList(syncDirectory));
BasicFileAttributes attr = Files.readAttributes(localFile.toPath(), BasicFileAttributes.class);
remoteFile.setModifiedTime(new DateTime(attr.lastModifiedTime().toMillis()));
LOGGER.log(Level.FINE, "Inserting new directory '" + syncDirectory.getPath() + "'.");
if (!options.isDryRun()) {
File insertedFile = executeWithRetry(options, () -> drive.files().create(remoteFile).execute());
syncDirectory.setRemoteFile(Optional.of(insertedFile));
}
} catch (IOException e) {
throw new JDriveSyncException(JDriveSyncException.Reason.IOException, "Failed to update file: " + e.getMessage(), e);
}
}
示例12: getDataFromApi
import com.google.api.client.util.DateTime; //导入依赖的package包/类
/**
* Fetch a list of the next 10 events from the primary calendar.
* @return List of Strings describing returned events.
* @throws IOException
*/
private List<String> getDataFromApi() throws IOException {
// List the next 10 events from the primary calendar.
DateTime now = new DateTime(System.currentTimeMillis());
List<String> eventStrings = new ArrayList<String>();
Events events = mActivity.mService.events().list("primary")
.setMaxResults(10)
.setTimeMin(now)
.setOrderBy("startTime")
.setSingleEvents(true)
.execute();
List<Event> items = events.getItems();
for (Event event : items) {
DateTime start = event.getStart().getDateTime();
if (start == null) {
// All-day events don't have start times, so just use
// the start date.
start = event.getStart().getDate();
}
eventStrings.add(
String.format("%s (%s)", event.getSummary(), start));
}
return eventStrings;
}
示例13: setUpBasicMockBehaviorForOpeningReadChannel
import com.google.api.client.util.DateTime; //导入依赖的package包/类
/**
* Helper for the shared boilerplate of setting up the low-level "API objects" like
* mockStorage.objects(), etc., that is common between test cases targetting
* {@code GoogleCloudStorage.open(StorageResourceId)}.
*/
private void setUpBasicMockBehaviorForOpeningReadChannel() throws IOException {
when(mockStorage.objects()).thenReturn(mockStorageObjects);
when(mockStorageObjects.get(eq(BUCKET_NAME), eq(OBJECT_NAME)))
.thenReturn(mockStorageObjectsGet);
when(mockClientRequestHelper.getRequestHeaders(eq(mockStorageObjectsGet)))
.thenReturn(mockHeaders);
when(mockStorageObjectsGet.execute())
.thenReturn(new StorageObject()
.setBucket(BUCKET_NAME)
.setName(OBJECT_NAME)
.setUpdated(new DateTime(11L))
.setSize(BigInteger.valueOf(111L))
.setGeneration(1L)
.setMetageneration(1L));
}
示例14: testGetItemInfoBucket
import com.google.api.client.util.DateTime; //导入依赖的package包/类
/**
* Test GoogleCloudStorage.getItemInfo(StorageResourceId) when arguments represent only a bucket.
*/
@Test
public void testGetItemInfoBucket()
throws IOException {
when(mockStorage.buckets()).thenReturn(mockStorageBuckets);
when(mockStorageBuckets.get(eq(BUCKET_NAME))).thenReturn(mockStorageBucketsGet);
when(mockStorageBucketsGet.execute())
.thenReturn(new Bucket()
.setName(BUCKET_NAME)
.setTimeCreated(new DateTime(1234L))
.setLocation("us-west-123")
.setStorageClass("class-af4"));
GoogleCloudStorageItemInfo info = gcs.getItemInfo(new StorageResourceId(BUCKET_NAME));
GoogleCloudStorageItemInfo expected = new GoogleCloudStorageItemInfo(
new StorageResourceId(BUCKET_NAME), 1234L, 0L, "us-west-123", "class-af4");
assertEquals(expected, info);
verify(mockStorage).buckets();
verify(mockStorageBuckets).get(eq(BUCKET_NAME));
verify(mockStorageBucketsGet).execute();
}
示例15: testGetItemInfoBucketReturnMismatchedName
import com.google.api.client.util.DateTime; //导入依赖的package包/类
/**
* Test handling of mismatch in Bucket.getName() vs StorageResourceId.getBucketName().
*/
@Test
public void testGetItemInfoBucketReturnMismatchedName()
throws IOException {
when(mockStorage.buckets()).thenReturn(mockStorageBuckets);
when(mockStorageBuckets.get(eq(BUCKET_NAME))).thenReturn(mockStorageBucketsGet);
when(mockStorageBucketsGet.execute())
.thenReturn(new Bucket()
.setName("wrong-bucket-name")
.setTimeCreated(new DateTime(1234L))
.setLocation("us-west-123")
.setStorageClass("class-af4"));
try {
gcs.getItemInfo(new StorageResourceId(BUCKET_NAME));
fail("Expected IllegalArgumentException with a wrong-bucket-name");
} catch (IllegalArgumentException iae) {
// Expected.
}
verify(mockStorage).buckets();
verify(mockStorageBuckets).get(eq(BUCKET_NAME));
verify(mockStorageBucketsGet).execute();
}