I'm trying to parse this URL and I'm wondering if anyone could tell me what to put in for the departure_time parameter so that it defaults to the current time:
https://maps.googleapis.com/maps/api/directions/json?origin=25broadyway&destination=pennstation,ny&departure_time=????current&mode=transit
I've tried:
current, 0, time.now....I can't figure it out
From the Google APIs:https://developers.google.com/maps/documentation/directions/
departure_time specifies the desired time of departure as seconds since midnight, January 1, 1970 UTC*.
Example: http://maps.googleapis.com/maps/api/directions/json?origin=Brooklyn&destination=Queens&key={API_KEY}&departure_time=1343641500&mode=transit
EDIT:
Try something like this method to get your departure_time in seconds:
private static string GoogleMapsDepartureTime(DateTime localTime)
{
DateTime inceptionDateTime = DateTime.Parse("01/01/1970 00:00:00");
DateTime departureDateTime = localTime.ToUniversalTime();
TimeSpan departureTimeSpan = departureDateTime - inceptionDateTime;
double departureTimeSeconds = departureTimeSpan.TotalSeconds;
return departureTimeSeconds.ToString().Split('.')[0];
}
I noticed there was no accepted answer or feedback so I'll take a crack at it. You should write "now" and it will give you the departure time to the nearest second.
Source:
https://developers.google.com/maps/documentation/directions/
Related
I'm new to python and have been trying like hell for the past few hours to figure out how to get this to work properly...
It's very simple code I'm sure, but I'm just not getting it.
It should be pretty self-explanatory below in the code, but basically I'm asking a user to input the date of an event as an 'int' and if it's not a number, then ask them to try again... UNLESS it's a "?"
while True:
date = None
street = str(input('Name of street?: ').title())
city = str(input("In what city?: ").title())
while True:
try:
year = int(input("Date of event? (or '?'): "))
if date == "?":
break
except Exception:
print("That's not a date, try again!")
continue
break
It seems that it's not even getting to see IF because it gets caught by the 'except' before it can.
If you're going to display help or something when a '?' is input, then just call the function to display the help where you have the break currently.
if date == "?":
display_help()
continue
Then, split reading the input and processing it into two steps.
in = input("Date of event? (or '?'): ")
if in == "?":
display_help()
continue
year = int(in)
Also, you ask for a date but then assume that a year is entered, I'd be more explicit in your promt.
"Please enter the year of the event, ex: 1998"
or whatever form you actually want it in.
Trying using a valueError exception. Also I think in your post you mentioned you wanted to enter a date as integer, so I replaced year with the date. If you wanted the year to be an integer you can replace the variable date with year. If you wanted to the user to enter a year, day and month then this program needs to be redesigned a bit.
date = None
street = str(input('Name of street?: ').title())
city = str(input("In what city?: ").title())
while True:
date = input("Date of event? (or '?'): ")
if date == "?":
break
else:
try:
date = int(date)
except ValueError:
print("That's not a date, try again!")
continue
break
Sorting objects in DOORS by the built-in DXL Attribute "Last Modified On" only sorts to the date level. That is, after sorting there is no guarantee to the order of Objects that were modified on the same calendar date (but at different times).
That's beyond stupid, especially since other online sources suggest that this field does in fact have this information available - but apparently only sorts on the displayed info, not the underlying data.
Neverminding how I'd LIKE this to work, what can I do instead? Today a module has literally hundreds of changed Objects, but I'm only interested in those altered in the last hour.
Looks like DOORS stores Last Modified On as a date only, without any time. Just to check, I added a layout DXL column with this in it:
Date dMod
dMod = obj."Last Modified On"
dMod = dateAndTime(dMod)
display dMod ""
In return I was greeted with entries like:
09/08/15 00:00:00
I'm not really proud of this next thing, but it sort of does the job. I created a DXL attribute called Last History Date with the following DXL:
History hr
Date dResult = null
Date dHist = null
Date dLastMod = null
dLastMod = obj."Last Modified On"
dLastMod = dateAndTime(dLastMod)
for hr in obj do {
dHist = hr.date
}
if (null dHist) { dResult = dLastMod }
else if (dLastMod > dHist) { dResult = dLastMod }
else { dResult = dHist }
obj.attrDXLName = dResult
If there are no history records, or history is recorded before Last Modified On, it just uses Last Modified On and you'll have to deal with 00:00:00. The history date isn't necessarily the same as Last Modified On -- depends on if you have "Affect change dates" or "Generate history" features turned on for the various object attributes. It's sort of a half-baked solution, but if you really want to sort with time I can't think of another way.
I want a Quartz timer service for the update code below. Every six months, all users' keys should be updated according to their creationDate:
//dataTypes are date only
List<User> allDbUsers=userRepository.findAll();
Date currDate=new Date();
final long DAY_IN_MILLIS = 1000 * 60 * 60 * 24;
for(User user:allDbUsers)
{
Date creationDate=user.getCreationDate();
String firstKey=user.getFirstKey();
Long diffInDays=(currDate.getTime()-creationDate.getTime())/DAY_IN_MILLIS;
if(diffInDays==180)
{
user.setSecondKey(firstKey);
user.setFirstKey("aH&#KK");
userRepository.saveAndFlush(user);
}
}
You can use Calendar for view diff between dates, for example:
Calendar currentDate = Calendar.getInstance();
Calendar sixMonthAfterCreation;
for (User user : allDbUsers) {
sixMonthAfterCreation = Calendar.getInstance()
sixMonthAfterCreation.setTime(user.getCreationDate());
sixMonthAfterCreation.add(Calendar.MONTH, 6);
String firstKey = user.getFirstKey();
if (currentDate.after(sixMonthAfterCreation)) {
user.setSecondKey(firstKey);
user.setFirstKey("aH&#KK");
userRepository.saveAndFlush(user);
}
}
or if you use java 8 you can convert you creation date to LocalDate and view diff.
If I right understand you, you want use Quartz Scheduler. I did not use it but I think you need implement org.quartz.Job, override execute method and write code for updating users in it.
For more information about Quartz Scheduler look this question
One clarification this code not for run scheduler, it code for method job.excecute(what job must do). Scheduler should run every midnight(for example), then every midnight will be called execute method which find all user for update and do it.
I have a long-term problem. I watch on the web, but I did not find right answer.
When I send data from WebAPI-Angular-Controller to Controller is a problem with formatting date. There are real data:
My TimeZone is UTC + 1
MS SQL:
Column type: DateTime2(3) value: 4.7.2015 20:00:00
The client receives the following formats based on the following criteria:
When I edit on WebApiConfig
config.Formatters.JsonFormatter.SerializerSettings.Converters.Add (new IsoDateTimeConverter DateTimeStyles = {} DateTimeStyles.AdjustToUniversal); The client receives 2015-07-04T03: 00: 00Z and this {{time | date 'HH: mm: ss'}} show wrong time. It is show time + 2 hours -> 22:00:00 -> I tried {{time | date 'HH: mm: ss' 'UTC'}}, bud show this time - 1 hour -> 19:00:00.
When I edit on WebApiConfig
config.Formatters.JsonFormatter.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc;, so it is the same as first example.
When I edit on WebApiConfig
config.Formatters.JsonFormatter.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local, so it is the same as first example excepting client receive data; they look like 2015-07-04T22: 00: 00 + 02: 00
When I edit on WebApiConfig
config.Formatters.JsonFormatter.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Undefined, client receive data; they look like 2015-07-04T20: 00: 00 -> it is look OK, bud problem is elsewhere.
I need this time (20:00:00) - curent time (f.e. 10:00:00) = 10:00:00 diff time, but angular show 11:00:00, why?
there is source from angularController
var d1 = new Date(bq.Done_Time)
var d2 = new Date()
bq.Time_Left = new Date(bq.Done_Time).getTime() - new Date().getTime()
Is the problem on server side or client side? And how can I resolve it?
Thank you very much for your valuable suggestions
Is there any ActionScript class which represents "durations of time", similar to the TimeDelta class in Python?
Edit: Thanks for the responses. I should clarify a bit, though: I want be able to ask questions like "how many weeks are between date0 and date1" or "let x represent "one day". What is date2 + x?"
I know I can do all this by representing dates as timestamps... But I'm hoping to find something nicer.
I posted a full AS3 port of the .NET TimeSpan class on this question, which sounds exactly like what you need.
// 5 days from new
var ts : TimeSpan = TimeSpan.fromDays(5);
var now : Date = new Date();
var fiveDaysTime : Date = ts.add(now);
// Diff between dates
var d1 : Date = new Date(2009, 1, 1);
var d2 : Date = new Date(2009, 1, 6);
var ts : TimeSpan = TimeSpan.fromDates(d1, d2);
You can use time() in the Date class to get unix era milliseconds and use that for time delta.
If you subtract two dates:
var dateDiff = date1 - date2;
dateDiff will hold the number of milliseconds between the two dates. You can then convert from milliseconds to whatever useful number you like.
I don't think there is a class which measures change in time in Actionscript 3. According to this blog post on Adventures in Actionscript, timing is very inaccurate in the Flash player on the web. That post is pretty informative and has a class called SuperTimer that might help you. You might want to keep this inaccuracy in mind if using solutions posed by Justin Niessner and toastie.