I am using foursquare venue API for fetching the hours. And as the documentation saids that it will return hours json representation as
end The time as HHMM (24hr) at which the segment ends. From https://developer.foursquare.com/docs/responses/hours
I begin to see some places that close after midnight and returns the hour in a format with a plus sign like this.
open: [
{
start: "1100"
end: "+0200"
}
]
Does anyone know what that mean?
{
start: "1100"
end: "+0200"
}
means: open 11:00 am - 2:00 am (next day)
Related
I was fiddling with Tequila Kiwi API to set up a short program that finds cheap round flights within some window period. However, departure times and arrival times are some long integer stead of the date strings. I googled around I could not anything.
My result
'aTimeUTC': 1661054400,
'airline': 'ET',
'bags_recheck_required': False,
'cityCodeFrom': 'YTO',
'cityCodeTo': 'ADD',
'cityFrom': 'Toronto',
'cityTo': 'Addis Ababa', ...
From API documentation. It should look like
"local_arrival": "2021-04-02T09:07:00.000Z",
"utc_arrival": "2021-04-02T13:07:00.000Z", ....
These are the parameters for the request:
query = {"fly_from": self.home_town,
"fly_to": fly_to,
"date_from": date_from,
"date_to": date_to,
"curr":"CAD",
"flight_type":"round",
"nights_in_dst_to": 120,
"nights_in_dst_from": 30
}
Everything else works except for those weirdly formatted aTime: 1661065200, aTimeUTC: 1661054400
its utc time in second, convert that into your time zone the help of internet
I have end date time in UTC format and with that time I am doing comparing it with current time on my server. I want to check that time difference should be 5 minutes. But I am always getting huge time difference.
console.log('utc format... ', currentDate, slot.endTimeWithDuration);
// log -> utc format... moment("2019-11-30T10:16:00.002") 2019-11-30T16:40:00Z
console.log('diff.... ', moment(slot.endTimeWithDuration).diff(currentDate,'minutes'))
// diff.... 383
How can I resolve this?
Try this something like :
moment.utc(moment(endTime, "HH:mm:ss").diff(moment(startTime, "HH:mm:ss"))).format("mm")
Or You can also make it more simple like below example:
var startTime = moment("07:27:28 am", 'hh:mm:ss a');
var endTime = moment("08:24:59 pm", 'hh:mm:ss a');
endTime.diff(startTime, 'hours');
I am using 2.22.1 to format dates.
When i put in a date that comes from a date selector, moment will put the date back one day. For example, when I try to format a date in the following way:
Example 1:
const day = new Date(value).getDate();
const month = new Date(value).getMonth();
const fullYear = new Date(value).getFullYear();
console.log('day', day); // 7
console.log('month', month); // 5
console.log('fullYear', fullYear); //2018
Formatting function:
moment.utc(new Date(month + ' ' + day + ' ' + fullYear), 'MM-DD-YYYY').format('DD-MM-YY')
Output: 06-05-18
Expected: 07-05-18
Example 2:
Input: Thu May 31 2018 00:00:00 GMT+0100 (GMT Summer Time)
Formatting function:
moment.utc(new Date(value)).format('DD-MM-YY')
Output: 30-05-18
Expected: 31-05-18
moment.utc will convert the input to universal time.
You are running new Date(...) with an input that's based on GMT +1.
If you think about this, it makes total sense.
Your output is 30-05-18, because it's 11 PM / 23:00 o'clock on the previous day.
This (how ever) would in fact work:
moment('05-06-2018', 'MM-DD-YYYY').format('DD-MM-YY')
// alternatively (and preferrably) this:
moment.utc('05-06-2018', 'MM-DD-YYYY').format('DD-MM-YY')
and output: "06-05-18"
Because the non utc version does not take a time input in this example.
One of the reasons moment.js exists, is to get rid of Date in your code all together.
(Keep in mind tho, that Date has drastically improved now. DateTimeFormat is a game changer)
Please just read the momentjs documentation on how to properly use moment.
edit:
If you want to process 400000 dates with this, I'd advise using RegExp, .split, .exec, .slice or Date instead.
(I can relate since I wrote a client sided Log parser with javascript generators and Service Workers for a statistical anti-cheat analysis)
I truly recommend playing around with such things to raise your knowledge.
I just ran into this issue and a quick fix I found for the time being processed in "Zulu time" (due to the Z at the end of the string) is to add .LocaleString() after the date variable.
I find that for data consistency, it's easier to store data in UTC time and then convert it to the locale string when displaying the data to the user.
For example, I'm using:
moment.utc(dateVariable.toLocaleString()).format("MM/DD/YYYY")
In my application i have to find out exact year, month and day between two dates. I tried with below snip. but answer is not correct. I used CTime for from to to dates. The result is obtained in CTimeSpan class. CTimeSpan has member function such as GetDays. We shall find out year, month and day from Total Days, but answer is not correct. Is any way to do ?
Thanks in advance
There is no common function to do that.
My idea would be:
COleDateTime date1(1979,12,31,0,0,0),
date2(2004,10,01,0,0,0);
// Get the normal differences
int iYears = date2.GetYear()-date1.GetYear(),
iMonths = date2.GetMonth()-date1.GetMonth(),
iDays = date2.GetDay()-date1.GetDay();
// Problematic underflow of days.
if (iDays<0)
{
// One month less
--iMonths;
// Advance from the start date until we reach the 1st of next month
for (iDays=0; (date1+COleDateTimeSpan(iDays,0,0,0)).GetDay()!=1; ++iDays)
;
// Now get the days from the 1st of the second date to the desired date.
iDays += static_cast<int>((COleDateTime(date2.GetYear(),date2.GetMonth(),1,0,0,0)-date2).GetTotalDays());
}
// underflow of months
if (iMonths<0)
{
--iYears;
iMonths +=12;
}
I don't see any CTimeSpan::GetTotalDays() function in the MSDN Docs.
Anyway, the GetTotalHours / GetTotalMinutes functions return the number of Complete Hours/Minutes and does not fully represent the TimeSpan value; the best way would be to use GetTotalSeconds and convert it as necessary.
In Groovy, how can I find the last day of the current month?
Thanks for your sage advice and better wisdom.
Yeah, as you commented, Calendar.FIELD is probably your best friend (though groovy's TimeCategory also has neat tricks).
Here's how i made for the last day of the current month:
Calendar.with {
println instance.getActualMaximum( DATE )
}
I didn't understood what you meant by "break out the current weekday if I'm looping through a month". Perhaps getting the weekday for each month?
Calendar.with {
(JANUARY..DECEMBER).each { month ->
def cal = instance
cal[MONTH] = month
println cal[DAY_OF_WEEK]
}
}