expo notification how set start time - react-native

The challenge is: how can I set up the start date for notification in the new expo API. In the old API (which is depricated today) it was feasible but I can't see the solution in the new doc
For example: set up a notification on every 2nd day start from a user given date (e.g. 12th of Jan).
I went through on these types
export type SchedulableNotificationTriggerInput =
| DateTriggerInput
| TimeIntervalTriggerInput
| DailyTriggerInput
| WeeklyTriggerInput
| CalendarTriggerInput;
but no success so far.

As far as I can tell you should be able to set the start date this way:
const dateString = "21/01/2021"; // Jan 21
const trigger = new Date(dateString);
trigger.setMinutes(0);
trigger.setSeconds(0);
Notifications.scheduleNotificationAsync({
content: {
title: 'Happy new hour!',
},
trigger,
});
You should play around with trigger.setMinutes and trigger.setSeconds to set a specific hour on your specific day.

Related

Wrong time being returned by date-fns when involving 2 timezones

Introduction
I have the current situation:
I receive the date from the backend as UTC
The user can have in his own profile his timezone setup
User can pick the date and time in two different time pickers
As soon as the date is returned by the backend I convert it to the user local timezone (timezone of his profile)
User selects new date, I create a zonedDate, modify it and store it as UTC
User selects new time, I use the utcToZonedTime to convert to user's local timezone (the UTC returned from backend), then I update with setHours and setMinutes and store back as UTC using toISOString() string
How the code is structured
I currently have the following code for when the user pick the date
import utcToZonedTime from 'date-fns-tz/utcToZonedTime';
const localizedTime = computed(() =>
utcToZonedTime(record.value.date, loggedUser.timezone)
);
const date = computed({
get: () => formatToDate(localizedTime.value),
set: (value: string) => {
// The `value` will come as YYYY-MM-DD from the DatePicker component
const zonedDateString = `${value}T17:30`;
const zonedDate = toDate(zonedDateString, {
timeZone: loggedUser.timezone,
});
record.value.date = zonedDate.toISOString();
},
});
This works fine for now. I set the hour and minutes to a hardcoded 17:30.
Now, the problem happens whenever picks the time:
import utcToZonedTime from 'date-fns-tz/utcToZonedTime';
import setMinutes from 'date-fns/setMinutes';
import setHours from 'date-fns/setHours';
const localizedTime = computed(() =>
utcToZonedTime(record.value.date, loggedUser.timezone)
);
const time = computed({
get: () => format(localizedTime.value, 'HH:mm'),
set: (time: string) => {
// Time is returned as HH:mm from the input
const [hour, minutes] = time.split(':');
console.log('Localized time:')
console.log(localizedTime.value);
let currentDateParsed = setHours(
localizedTime.value,
hour as unknown as number
);
currentDateParsed = setMinutes(
currentDateParsed,
minutes as unknown as number
);
console.log('Current date parsed:')
console.log(currentDateParsed);
record.value.date = currentDateParsed.toISOString();
},
});
Problem
As a setup I have the following criterias:
User timezone is set to Europe/Lisbon (GMT+1)
My computer timezone is set to Europe/Zagreb (GMT+2)
I receive the following date from backend in UTC 2022-06-02T16:00:56.000000Z
Time is displayed as 17:00 (I'm using the user profile's timezone and not the computer's timezone)
Whenever I set the date, it works perfect time. Whenever I try to set hours and minutes, the timezones get mixed up.
I select the time as 18:30 and it is displayed back to the user as 17:30.
The part of the code that is giving me problems is:
const time = computed({
get: () => format(localizedTime.value, 'HH:mm'),
set: (time: string) => {
// Time is returned as HH:mm from the input
const [hour, minutes] = time.split(':');
console.log('Localized time:')
console.log(localizedTime.value); 👈 // Thu Jun 02 2022 17:00:56 GMT+0200 (Central European Summer Time)
let currentDateParsed = setHours(
localizedTime.value,
hour as unknown as number
);
currentDateParsed = setMinutes(
currentDateParsed,
minutes as unknown as number
);
console.log('Current date parsed:')
console.log(currentDateParsed); 👈 // Thu Jun 02 2022 18:30:56 GMT+0200 (Central European Summer Time)
console.log('Current date parsed toISOString():');
console.log(currentDateParsed.toISOString()); 👈 // 2022-06-02T16:00:56.000Z
record.value.date = currentDateParsed.toISOString();
},
});
I have tried converting the date back to UTC and work only in UTC and also only in user's local time but nothing seems to work. I have uploaded the following video showing the issue

HERE-API - how to create an app_id, app_code and api_key

I'm trying to replicate the examples from the fleet telematics examples at (https://tcs.ext.here.com/examples/v3.1/fleet_telematics_api) into my app, but the authentication need app_id and app_code, I have only an api_key.
I want to be able to create the truckOverlayProvider to show and hide the truck restrictions.
What do I need and how can I achieve that, is there any tutorial step by step for this subject?
Just create a Freemium account at https://developer.here.com/ and you will find there in your dashboard your AppID and api_key.
Check this post:
https://developer.here.com/blog/announcing-two-new-authentication-types
Update: I am sharing also a screenshot:
Looking at the code for the example that you shared, here's how they are making the call for truck overlay:
var truckOverlayProvider = new H.map.provider.ImageTileProvider({
label: "Tile Info Overlay",
descr: "",
min: 12,
max: 20,
getURL: function(col, row, level) {
server_rr++;
if (server_rr > 4) server_rr = 1;
return ["https://",
server_rr,
".base.maps.api.here.com/maptile/2.1/truckonlytile/newest/normal.day/",
level,
"/",
col,
"/",
row,
"/256/png8",
"?style=fleet",
"&app_code=",
app_code,
"&app_id=",
app_id
].join("");
}
});
var truckOverlayLayer = new H.map.layer.TileLayer(truckOverlayProvider);
map.addLayer(truckOverlayLayer);
Looking more closely at the call:
https://1.base.maps.ls.hereapi.com/maptile/2.1/info?xnlp=CL_JSMv3.1.22.0&apikey=API_KEY&output=json
Here's more resources on getting map tiles truck information overlay

Google calendar API free slots

i am really new to the coding and would like to ask for some advice regarding calendar API.
I managed to created a list of the events and and show a busy time in the calendar, but i cant figure out how to show output of the free slots between the events.
# Call the Calendar API
now = datetime.datetime.utcnow().isoformat() + 'Z' # 'Z' indicates UTC time
print('Getting the upcoming 10 events')
events_result = service.events().list(calendarId='<email>', timeMin=now,
maxResults=10, singleEvents=True,
orderBy='startTime').execute()
events = events_result.get('items', [])
if not events:
print('No upcoming events found.')
for event in events:
start = event['start'].get('dateTime', event['start'].get('date'))
#print(start, event['summary'])"""
cst = timezone('UTC')
the_datetime_start = cst.localize(datetime.datetime(2020, 6, 10, 0))
print(the_datetime_start)
the_datetime_end = cst.localize(datetime.datetime(2020, 6, 10, 16))
print(the_datetime_end)
body = {
"timeMin": the_datetime_start.isoformat(),
"timeMax": the_datetime_end.isoformat(),
"timeZone": 'UK',
"items": [{"id": '<email>'}]
}
eventsResult = service.freebusy().query(body=body).execute()
print(eventsResult)
Hard to give you a code answer with your information, but if you want to show your free slots, you just have to:
Get all the tasks you have on your planning
Order it
Compare the first end date/hour task with the second start date/hour task
The différence between is your free slot, so you have your free slot
Do it again for the second task and the third task, and repeat for the other task

.getcurrentrow (DCIteratorBinding) is returning null after an hour

I am new in ADF (EJB/JPA not Business Component), when the user is using our new app developed on jdeveloper "12.2.1.2.0", after an hour of activity, system is loosing the current record. To note that the object lost is the parent object.
I tried to change the session-timeout (knowing that it will affect the inactivity time).
public List<SelectItem> getSProvMasterSelectItemList(){
List<SelectItem> sProvMasterSelectItemList = new ArrayList<SelectItem>();
DCIteratorBinding lBinding = ADFUtils.findIterator("pByIdIterator");/*After 1 hour I am able to get lBinding is not null*/
Row pRow = lBinding.getCurrentRow();/*But lBinding.getCurrentRow() is null*/
DCDataRow objRow = (DCDataRow) pRow;
Prov prov = (Prov) objRow.getDataProvider();
if (!StringUtils.isEmpty(prov)){
String code = prov.getCode();
if (StringUtils.isEmpty(code)){
return sProvMasterSelectItemList;
}else{
List<Lov> mProvList = getSessionEJBBean().getProvFindMasterProv(code);
sProvMasterSelectItemList.add(new SelectItem(null," "));
for (Lov pMaster:mProvList) {
sProvMasterSelectItemList.add(new SelectItem(pMaster.getId(),pMaster.getDescription()));
}
}
}
return sProvMasterSelectItemList ;
}
I expect to be able to read the current record at any time, specially that it is the master block, and one record is available.
This look like a classic issue of misconfigured Application Module.
Cause : Your application module is timing out and releasing it's transaction before the official adfc-config timeout value.
To Fix :
Go to the application module containing this VO > Configuration > Edit the default > Modify Idle Instance Timeout to be the same as your adf session timeout (Take time to validate the other configuration aswell)

Postman: Check date equals yesterdays date

I'm running a GET request using Postman and the JSON response is below:
{
"Version": "1.0.524.0",
"BuildName": "Live",
"BuildDate": "04/12/2018 18:58:50.85 \r\n"
}
The build date increments by one each day and I want to write a script to check the date has been incremented and if it hasn't then its a failed test.
Currently I have this:
pm.test("Check Build Date", function (CheckDate) {
pm.expect(pm.response.text()).to.include("04/12/2018 18:58:50.85");
});
However I know if I run this script tomorrow it won't work and I will get the following error:
FAIL Check Build Date | AssertionError: expected '{"Version":"1.0.524.0","BuildName":"Live","BuildDate":"05/12/2018 18:58:50.85 \\r\\n"}' to include '04/12/2018 18:58:50.85'
Can anybody assist, please?
If your response body is an object, like in your question, you can use pm.response.json().BuildDate and check that it equals that value.
pm.test("Check Build Date", () => {
pm.expect(pm.response.json().BuildDate).to.equal("04/12/2018 18:58:50.85 \r\n");
});
Not sure why you have those \r\n values in string on that response, they seem in the wrong place to me.
To know that the day has incremented by 1, you would need to store the state of the last run and do a check against that. You could be that with setting it as an environment variable.
Send an initial request to get and set the BuildDate. You will now have that value to use in a Check request.
pm.environemnt.set('lastBuildDate', pm.response.json().BuildDate)
In the check request, you could have something like this:
const moment = require('moment')
let dateDiff = moment(pm.reponse.json().BuildDate).isAfter(pm.environment.get('lastBuildDate'))
pm.test("Check Build Date", () => {
pm.expect(dateDiff).to.be.true
})
If you just want something that checks if the BuildDate is the after the time that that you are making the request - You could use something like this:
const moment = require('moment')
let dateNow = moment().format("DD/MM/YYYY hh:mm:ss.SS")
let dateDiff = moment(pm.response.json().BuildDate).isAfter(dateNow)
pm.test("Check Build Date", () => {
pm.expect(dateDiff).to.be.true
})
This is obviously not what you want to do but I would suggest taking a look at the momentjs module as see if that is something in there that you can use for your use case.