Skip to content
This repository has been archived by the owner on Dec 26, 2022. It is now read-only.

Commit

Permalink
use relative dates & add doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Pistashe committed Dec 12, 2021
1 parent 086fff9 commit 9d20287
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
2 changes: 1 addition & 1 deletion browser_action/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
<div class="panel-formElements-item">
<div>
<input type="date" name="dateMaxSearch" id="dateMax" />
<label for="dateMax">Date maximale de recherche</label>
<label for="dateMax">Date maximale de recherche (MM/JJ/YYYY)</label>
</div>
</div>

Expand Down
1 change: 1 addition & 0 deletions browser_action/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
document.getElementById(injectionVaccine).checked = true;
}

/** @param {Date} dateMaxSearch La date maximale de recherche de rdv */
function displayDateMaxSearch(dateMaxSearch) {
const date = new Date(dateMaxSearch);
document.getElementById('dateMax').value = date.toISOString().split('T')[0]
Expand Down
16 changes: 13 additions & 3 deletions commons/AppStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class AppStatus {
this.injectionType = "fullServiceInjection";
/** @type {'modernaInjection' | 'pfizerInjection'} vaccin d'injection souhaité par le user */
this.injectionVaccine = "pfizerInjection";
this.dateMaxSearch = new Date(2022, 1, 15);
/** @type {Date} Date max de recherche de rdv (par défaut aujd + 1 mois) */
this.dateMaxSearch = new Date((new Date()).getFullYear()+1, (new Date()).getMonth(), (new Date()).getDate());
/** @type {(string) => void} callback quand une {@link VaccineLocation} a été ajouté */
this.onLocationAddedCb = (job) => {};
/** @type {(string) => void} callback quand une {@link VaccineLocation} a été supprimée */
Expand All @@ -35,6 +36,7 @@ class AppStatus {
this.onInjectionTypeCb = (newValue) => {};
/** @type {'modernaInjection' | 'pfizerInjection'} callback quand injectionVaccine change de valeur */
this.onInjectionVaccineCb = (newValue) => {};
/** @type {Date} callback quand maxDateSearch change de valeur */
this.onDateMaxSearchCb = (newValue) => {};

this.onStorageChange = this.onStorageChange.bind(this);
Expand All @@ -51,7 +53,7 @@ class AppStatus {
autoBook: false,
injectionType: "fullServiceInjection",
injectionVaccine: "pfizerInjection",
dateMaxSearch: new Date(2022, 1, 15),
dateMaxSearch: new Date((new Date()).getFullYear()+1, (new Date()).getMonth(), (new Date()).getDate()),
});

Object.keys(result.locations).forEach((url) => {
Expand Down Expand Up @@ -151,6 +153,10 @@ class AppStatus {
onInjectionVaccineChange(callback) {
this.onInjectionVaccineCb = callback;
}

/**
* @param {(Date) => void} callback quand dateMaxSearch change de valeur
*/
onDateMaxSearchChange(callback) {
this.onDateMaxSearchCb = callback;
}
Expand Down Expand Up @@ -181,6 +187,10 @@ class AppStatus {
browser.storage.sync.set({ injectionType: this.injectionType });
}


/**
* @param {Date} value The new dateMaxSearch value
*/
setDateMaxSearch(value) {
this.dateMaxSearch = new Date(value.value);
browser.storage.sync.set({ dateMaxSearch: this.dateMaxSearch });
Expand Down Expand Up @@ -211,7 +221,7 @@ class AppStatus {
this.onInjectionTypeCb(this.injectionType);
this.injectionVaccine = "pfizerInjection";
this.onInjectionTypeCb(this.injectionVaccine);
this.dateMaxSearch = new Date(2022, 1, 15);
this.dateMaxSearch = new Date((new Date()).getFullYear(), (new Date()).getMonth()+1, (new Date()).getDate());
this.onDateMaxSearchCb(this.dateMaxSearch);
}

Expand Down
16 changes: 1 addition & 15 deletions content_scripts/doctolib/book.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,10 @@
autoBook: false,
injectionType: "fullServiceInjection",
injectionVaccine: "pfizerInjection",
dateMaxSearch: new Date(2022, 1, 15)
dateMaxSearch: new Date((new Date()).getFullYear()+1, (new Date()).getMonth(), (new Date()).getDate()),
});

const dateMaxSearchDate = typeof(dateMaxSearch) === 'string' ? new Date(dateMaxSearch) : dateMaxSearch;
console.log(dateMaxSearchDate)

if (stopped || !locations[url]) {
running = false;
Expand Down Expand Up @@ -455,19 +454,6 @@

const date = new Date(
`${selectedMonth} ${selectedDay} ${selectedYear} ${selectedTime}`);
// console.log(parts)
// const year = parts[1] === 'decembre' ? 2021 : 2022;
// const date = new Date(
// `${MONTHS[parts[1]]} ${parts[0]} ${year} ${
// parts[2]
// }`
// );

const tomorrow = new Date();
tomorrow.setHours(23);
tomorrow.setMinutes(59);
tomorrow.setDate(tomorrow.getDate() + 1);


if (date > dateMaxSearchDate) {
const formatedDate = dateMaxSearchDate.toLocaleDateString();
Expand Down

0 comments on commit 9d20287

Please sign in to comment.