Skip to content

Commit 2cc666f

Browse files
ndg63276Mark Williams
andauthored
LIMS-2044: Remove luxon (#1022)
* LIMS-2044: Update luxon * LIMS-2044: Remove Luxon --------- Co-authored-by: Mark Williams <mark.williams@diamond.ac.uk>
1 parent f69d549 commit 2cc666f

6 files changed

Lines changed: 29 additions & 52 deletions

File tree

client/.eslintrc.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ module.exports = {
1111
'backbone/model-defaults': 0, // widely abused issue - so unlikely to be addressed without considerable effort
1212
'backbone/collection-model': 0, // ditto
1313
'backbone/defaults-on-top': 0, // ditto
14-
'backbone/initialize-on-top': 0 // ditto
14+
'backbone/initialize-on-top': 0, // ditto
15+
'backbone/no-silent': 0
1516
},
1617
env: {
1718
es6: true,
@@ -21,4 +22,4 @@ module.exports = {
2122
"ecmaVersion": 11,
2223
"sourceType": "module"
2324
}
24-
}
25+
}

client/package-lock.json

Lines changed: 0 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@
8181
"jquery.flot": "^0.8.3",
8282
"jquery.flot.tooltip": "^0.9.0",
8383
"lodash-es": "^4.17.21",
84-
"luxon": "^1.25.0",
8584
"markdown": "^0.5.0",
8685
"plotly.js": "^1.52.2",
8786
"portal-vue": "2.1.7",

client/src/js/models/visit.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
define(['backbone', 'backbone-validation', 'luxon'], function(Backbone, BackBoneValidation, luxon) {
1+
define(['backbone', 'backbone-validation'], function(Backbone, BackBoneValidation) {
22
var Visit = Backbone.Model.extend({
33
idAttribute: 'VISIT',
44
urlRoot: '/proposal/visits',
55

66
initialize: function(attributes, options) {
77
this.on('change', this.addDate, this)
8-
this.dateTimeZone = window.app.options.get('timezone')
98
this.addDate()
109
},
1110

@@ -47,17 +46,14 @@ define(['backbone', 'backbone-validation', 'luxon'], function(Backbone, BackBone
4746
pattern: 'number',
4847
},
4948
},
50-
51-
addDate: function() {
52-
var { DateTime } = luxon
53-
54-
this.set('ENISO', DateTime.fromISO(this.get('ENISO'), { zone: this.dateTimeZone }))
55-
this.set('STISO', DateTime.fromISO(this.get('STISO'), { zone: this.dateTimeZone }))
56-
this.set('LEN', Number(this.get('ENISO').diff(this.get('STISO'))/(3600*1000)).toFixed(2))
57-
this.set('VISITDETAIL', this.get('VISIT')+' ('+this.get('BL')+': '+this.get('ST')+')')
58-
},
5949

60-
dateTimeZone: 'Europe/London'
50+
addDate: function() {
51+
const enDate = new Date(this.get('ENISO'))
52+
const stDate = new Date(this.get('STISO'))
53+
const diffInHours = (enDate - stDate) / (3600 * 1000)
54+
this.set('LEN', Number(diffInHours).toFixed(2))
55+
this.set('VISITDETAIL', this.get('VISIT') + ' (' + this.get('BL') + ': ' + this.get('ST') + ')')
56+
}
6157

6258
})
6359

client/src/js/modules/calendar/views/calendar-view.vue

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ import Visits from 'collections/visits'
157157
import Beamlines from 'collections/bls'
158158
import FilterPills from 'app/components/filter-pills.vue'
159159
import CalendarDayEvents from 'modules/calendar/views/components/calendar-day-events.vue'
160-
import { DateTime } from 'luxon'
161160
162161
export default {
163162
name: 'CalendarView',
@@ -220,9 +219,9 @@ export default {
220219
},
221220
mounted() {
222221
const dateTime = this.todayDate
223-
this.currentMonth = dateTime.month - 1
224-
this.currentDay = dateTime.day
225-
this.currentYear = dateTime.year
222+
this.currentMonth = dateTime.getMonth()
223+
this.currentDay = dateTime.getDate()
224+
this.currentYear = dateTime.getFullYear()
226225
this.fetchBeamlinesByType()
227226
this.fetchVisitsCalendar()
228227
},
@@ -330,19 +329,16 @@ export default {
330329
}, {})
331330
},
332331
isToday(date) {
333-
const { month, day, year } = this.todayDate
334-
return date === day && month - 1 === this.currentMonth && year === this.currentYear
332+
const today = this.todayDate
333+
return (
334+
date === today.getDate() &&
335+
this.currentMonth === today.getMonth() &&
336+
this.currentYear === today.getFullYear()
337+
)
335338
},
336339
isPastDate(date) {
337-
const dateItem = DateTime.fromObject({
338-
year: this.currentYear,
339-
month: this.currentMonth + 1,
340-
day: date,
341-
zone: this.timezone
342-
})
343-
340+
const dateItem = new Date(this.currentYear, this.currentMonth, date);
344341
return dateItem < this.todayDate
345-
346342
},
347343
onHover(ref, addHover) {
348344
const hoveredRef = this.$refs[ref][0].$el
@@ -409,7 +405,9 @@ export default {
409405
return this.appOption['timezone']
410406
},
411407
todayDate() {
412-
return DateTime.local().setZone(this.timezone)
408+
const d = new Date()
409+
d.setHours(0, 0, 0, 0)
410+
return d
413411
},
414412
currentSelectedMonth() {
415413
return this.months[this.currentMonth]
@@ -439,20 +437,12 @@ export default {
439437
return this.currentYear + 1
440438
},
441439
daysInMonth() {
442-
return DateTime.fromObject({
443-
year: this.currentYear,
444-
month: this.currentMonth + 1,
445-
day: 1,
446-
zone: this.timezone
447-
}).daysInMonth
440+
return new Date(this.currentYear, this.currentMonth + 1, 0).getDate()
448441
},
449442
startDayOfMonth() {
450-
return DateTime.fromObject({
451-
year: this.currentYear,
452-
month: this.currentMonth + 1,
453-
day: 1,
454-
zone: this.timezone
455-
}).weekday - 1
443+
const dateItem = new Date(this.currentYear, this.currentMonth, 1)
444+
const day = dateItem.getDay()
445+
return (day === 0) ? 6 : day - 1
456446
},
457447
sortedVisitsByDay() {
458448
return Array(this.daysInMonth).fill('').reduce((acc, curr, index) => {

client/src/js/modules/samples/controller.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ define(['marionette',
1818
GetView,
1919
Sample, Samples,
2020
Protein, Proteins,
21-
Ligand, Ligands
21+
Ligand, Ligands,
2222
Crystal, Crystals,
2323
Instance,
2424
ProposalLookup) {

0 commit comments

Comments
 (0)