Weather from yesterday - json

I would like to get everyday of the weather from yesterday with darksky, but how do I set this up? Because the UnixTime is based on date, but the only thing I would like is the following data from yesterday, not hourly, daily is just fine:
Is use this from the API:
GET https://api.darksky.net/forecast/{key}/52.1038,5.1909?exclude=currently,flags,hourly&lang=nl&units=auto
Here you can read the documentation:
https://darksky.net/dev/docs/time-machine
{
"time":1502575200,
"summary":"Licht bewolkt vanaf de middag, houdt aan tot de avond.",
"icon":"partly-cloudy-day",
"sunriseTime":1502598072,
"sunsetTime":1502651386,
"moonPhase":0.69,
"precipIntensity":0.0178,
"precipIntensityMax":0.1245,
"precipIntensityMaxTime":1502618400,
"precipProbability":0.13,
"precipType":"rain",
"temperatureMin":13.25,
"temperatureMinTime":1502596800,
"temperatureMax":21.37,
"temperatureMaxTime":1502640000,
"apparentTemperatureMin":13.25,
"apparentTemperatureMinTime":1502596800,
"apparentTemperatureMax":21.37,
"apparentTemperatureMaxTime":1502640000,
"dewPoint":12.9,
"humidity":0.76,
"windSpeed":0.47,
"windGust":4.88,
"windGustTime":1502658000,
"windBearing":12,
"cloudCover":0.27,
"pressure":1019.62,
"ozone":303.52,
"uvIndex":4,
"uvIndexTime":1502618400
}

From their documentation for request parameters:
Either be a UNIX time (that is, seconds since midnight GMT on 1 Jan 1970) or a string formatted as follows: [YYYY]-[MM]-[DD]T[HH]:[MM]:[SS][timezone].
The easiest way would be to subtract 86400 (the number of seconds in a day) from the current UNIX timestamp. This will give you yesterday's UNIX timestamp.

The API sends through daily information in the response. https://darksky.net/dev/docs/response You can get this data using any time value on a given day.
Days are 86400 second long and so subtracting or adding multiples of this number will allow you to change the date.
The API also allows a string formatted as [YYYY]-[MM]-[DD]T[HH]:[MM]:[SS][timezone]. You could use this format instead for readability if it is easier.

Related

Weird date format from mysql in vuejs

Time in mysql is stored like this
2022-04-25 11:03:20
but when it is showed on client with vuejs i am getting this as response
2022-04-25T09:03:20.000Z
How do i show it as it is shown in db?
The date you're getting is in ISO-8601 format. You'll want to continue to store it like that so you've got the timezone (as denoted by the suffix 'Z'). In your frontend, it's easy to convert the date into any format you like.
For example, based on your example, you can use:
const dateFromDb = '2022-04-25T09:03:20.000Z';
const dateForUi = new Date(dateFromDb).toLocaleString('nl-NL');
console.log(dateForUi); // 25-4-2022 10:03:20
You can also convert any date object back into ISO format, using .toISOString().
There's also many other date formatting methods (outlined in the Date() docs), or for more advanced date / time operations there are libraries like moment.js

Google apps script - form input time changes when copied

I have a Google form to collect info on people leaving the organisation. One of the questions is 'What date and what time do they leave' The response is in the format dd/mm/yyyy, hh:mm. so a typical response would be 24/04/2015 17:00:00, and that's what I see in the Form responses 1 worksheet when the form is submitted.
I need to add the day of the week and copy the information into another worksheet within the spreadsheet, so I use
var leaveDate = inputSheet.getRange("G" + lastRow).getValue();
var leaveDateTime = Utilities.formatDate(leaveDate, "GMT", "EEE dd-MM-yyyy hh:mm:ss");
The issue I'm seeing is that when I paste the value the time is changing, and what gets pasted is
Fri 24-04-2015 04:00:00
Can anyone explain why this is happening and what I can do to resolve it?
Thanks
Apps Script converts date types to the time zone set up in the script editor. In the script editor, you need to set the time zone, even if you've set it in the spreadsheet.
Set the time zone to your local time zone.
Make sure the time zone in your spreadsheet, and the time zone in your script editor match.
If you have multiple editors of the spreadsheet in multiple time zones, and the other users have set the time to their local time, then obviously, their time and your time won't be the same. If someone left the organization on the other side of the world, at 4pm their time, they didn't leave the organziation at 4pm your time. You could assume that if the spreadsheet states 4pm, that it was their local time, and convert the time. In that case, you'd need to know the time zone of every time entry that is made, and then adjust it as necessary.
Try:
...
// var leaveDateTime = Utilities.formatDate(leaveDate, "GMT", "EEE dd-MM-yyyy hh:mm:ss");
var leaveDateTime = Utilities.formatDate(leaveDate, "GMT", "EEE dd-MM-yyyy HH:mm:ss");
...
UPDATE
Thanks to #sandy-good and #wchiquito for pointing me in the right direction. There were 2 issues. First issue is using hh instead of HH. The second issue is that we are on GMT+1 at the moment, and will be until end October, at which point we go back to GMT! As I don't want to code around that I'm going to simplify it by dropping the day, which then means I don't have to reformat the date.

JSON time offset (Trello)

I'd like to create Trello cards over the Trello API. I'am able to create a card with:
curl -X POST 'https://api.trello.com/1/lists/{LIST_ID}/cards?name=TEST9&due=2014-05-08T08:00:00&key={APP_KEY}&token={TOKEN}'
However, I can't determine my time offset for the due date:
2014-05-08T08:00:00.{OFFSET}
My Timezone is CET (Europe/Berlin), how can I tell Trello this with the time offset?
I could not find it in the documentation, but I am quite sure Trello stores the due dates in UTC. So as the comment already suggests, convert your timestamp to their timezone (which would be UTC).

Sequelize — use UNIX timestamp for DATE fields

Is there a way to force Sequelize use UNIX Timestamp as default time format both for createdAt/updatedAt timestamps and for custom-defined Sequelize.DATE field types?
Thanks!
P.S. I'm using MySQL
At any given moment in time, there are two possible dates (depending on one's position relative to the international date line): that is, converting from a UNIX timestamp to a date requires one to consider the timezone.
For example, the UNIX timestamp 946684800 is 2000-01-01 00:00:00Z. Whilst this represents the first day of the new millenium pretty much everywhere east of the Atlantic, it's still millenium eve everywhere to the west of that ocean. So which date does it represent?
Whilst it's possible to convert from a date to a timestamp, one must define one's own convention for so doing (e.g. represent a given date as midnight in UTC) or else the same date may be represented differently upon each encoding. Generally speaking, this is a bad idea which may have all sorts of unintended consequences.
There is a reason that the DATE data type exists: it is the correct way to store a date. Use it.
While eggyal's answer is the proper way to do things in MySQL, some of us might be working in an environment or team that requires us to use a unix timestamp instead of a datetime / timestamp.
I found that a great way to accomplish this is to use hooks inside of sequelize. At the bottom of each of your models, you can add this code:
{
tableName: 'Addresses',
hooks : {
beforeCreate : (record, options) => {
record.dataValues.createdAt = Math.floor(Date.now() / 1000);
record.dataValues.updatedAt = Math.floor(Date.now() / 1000);
},
beforeUpdate : (record, options) => {
record.dataValues.updatedAt = Math.floor(Date.now() / 1000);
}
}
}
This will insert the createdAt and updatedAt fields as unix timestamps.
No or at least not yet.
CreatedAt is set using the utils.now function in sequelize. That function uses the javascript Date function with no additional arguments. Squelize could be modified to change the way it calls Date but there is no code to do that in the current version.
see here
You could however disable the createdAt and other timestamps and use raw queries to set your own. However then you're sacrificing the functionality of sequelize.
Best solution is probably to convert those fields to unix time in your business logic before using them.

fmt:formatDate and timeZone

I have fields in a Mysql database typed datetime.
I store, for example, a payment's date with next Java code:
payment.setCreatedOn(new Date(System.currentTimeMillis()));
In my view layer I use fmt:formatDate to format dates:
<fmt:formatDate value="${payment.createdOn}" pattern="EEE, dd MMM yyyy HH:mm:ss"/>
My server is in London and my application's users are in Vienna. The time showing is delayed probably because of different time zones. I can use a timeZone Parameter in fmt:formatDate.
timeZone: Time zone in which to
represent the formatted time.
After searching in Google, I think the value Europe/Vienna is valid for timeZone parameter.
Does anyone knows if there is list anywhere of the valid timeZone strings?
Sergio - I'm sure you've long since found it anyway ...
Here's the homepage for the Olson database or 'zoneinfo' which is the definitive source of TZ info.
And here's a nice wiki for browsing zones.
Here is a list for the IBM JDK, a little dated but has full list:
http://publib.boulder.ibm.com/infocenter/wsdoc400/v6r0/index.jsp?topic=/com.ibm.websphere.iseries.doc/info/ae/ae/adrtzval.htm
You need to use the international time (UTC/Zulu) to add the following schedule client time use, for example "GMT+1". See this example.
Put this parameter as argument in your server to set UTC time use, in this case is for tomcat:
-Duser.timezone="UTC"
/* Java */
#RequestMapping(value = "/web", method = { RequestMethod.POST, RequestMethod.GET })
public String web(Model model, HttpSession session, Locale locale) {
Date today = new Date();
model.addAttribute("currentTime", today);
model.addAttribute("timezone", "GMT+1");
return "web";
}
To show date choose your pattern you want (properties)
/* JSP web */
<fmt:timeZone value="${timezone}">
<spring:message code="date_format_dateMin" var="pattern"/>
<fmt:formatDate value="${currentTime}" timeZone="${timezone}" pattern="${pattern}" var="searchFormated" />
<span class="innerLabel">${searchFormated}</span>
</fmt:timeZone>
/* Properties */
date_format_dateMin=yyyy/MM/dd HH:mm
date_format=yyyy/MM/dd HH:mm:ss
date_format2=yyyy/MM/dd
date_format3_js=yy/mm/dd
date_format4_time=HH:mm
date_format4=dd/MM/yyyy HH:mm:ss