First day of week

Hi!
How can I change the first day of week for calendar? Trying to change it from Sunday to Monday.

You mean the calendar widget?

its http://fullcalendar.io/

1 Like

Yes, I want to change the first day attribute (http://fullcalendar.io/docs/display/firstDay/). Can I just add the option here https://github.com/frappe/erpnext/blob/develop/erpnext/projects/doctype/time_log/time_log_calendar.js or is there some better way?

@quu we have never done that, but yeah before creating the calendar you should be able to do it.

Hi, we (and indeed most european customers) are looking also for a setting to change the first day of the week to monday in the Calendar in ERPNext 6. Can you help?

Hi, any news on this topic?

This feature has not yet been added. Please create Github Issue for this feature suggestion.

1 Like

here you go provide possibility to change the first day of the week to Monday · Issue #7943 · frappe/erpnext · GitHub

thanks;-)

@SwitsolAG, @info, @quu can you comment (or +1 if you don’t have any comment actually) on the issue please?
that will raise attention of dev’s on the matter

@vrms …waiting for the issue to be solved, i’ve made an hack for date picker:

create your own javascript for ControlDate in ur public js folder:

frappe.ui.form.ControlDate = frappe.ui.form.ControlData.extend({
	set_input: function(value) {
		this._super(value);
		if(value && this.last_value && this.last_value !== this.value) {
			this.datepicker.selectDate(new Date(value));
		}
	},
	make_input: function() {
		this._super();
		this.set_date_options();
		this.set_datepicker();
	},
	set_date_options: function() {
		var me = this;
		this.datepicker_options = {
			language: frappe.boot.user.language || "en",
			autoClose: true,
			todayButton: new Date()
		};

		var date_format =
			(frappe.boot.sysdefaults.date_format || 'yyyy-mm-dd');
		this.datepicker_options.dateFormat = date_format;

		this.datepicker_options.onSelect = function(dateStr) {
			me.set_value(me.get_value());
			me.$input.trigger('change');
		}
	},
	set_datepicker: function() {
		this.$input.datepicker(this.datepicker_options);
		this.datepicker = this.$input.data('datepicker');
	}
});

The only difference with original is the line: language: frappe.boot.user.language || "en". It gets the language for the logged user.

Add to build.js and make it loading from hooks.

Create new datepicker.xx.js where xx is a 2 letter language, i.e. for italian is it:

;(function ($) { $.fn.datepicker.language['it'] = {
    days: ['Domenica', 'Lunedì', 'Martedì', 'Mercoledì', 'Giovedì', 'Venerdì', 'Sabato'],
    daysShort: ['Dom', 'Lun', 'Mar', 'Mer', 'Gio', 'Ven', 'Sab'],
    daysMin: ['Do', 'Lu', 'Ma', 'Me', 'Gi', 'Ve', 'Sa'],
    months: ['Gennaio','Febbraio','Marzo','Aprile','Maggio','Giugno','Luglio','Agosto',
    'Settembre','Ottobre','Novembre','Dicembre'],
    monthsShort: ['Gen', 'Feb', 'Mar', 'Apr', 'Mag', 'Giu', 'Lug', 'Ago', 'Set', 'Ott', 'Nov', 'Dic'],
    today: 'Oggi',
    clear: 'Reset',
    dateFormat: 'mm/dd/yyyy',
    timeFormat: 'hh:ii aa',
    firstDay: 1
}; })(jQuery);

then have a bench build, it should work …

1 Like

@vrms …i think i made calendar localizaion working :sweat_smile: …localizing will change first day of week as well.

As per date picker, create your own javascript in ur public js folder and add:

frappe.views.CalendarView = frappe.views.CalendarView.extend({
	required_libs: [
		'assets/frappe/js/lib/fullcalendar/fullcalendar.min.css',
		'assets/frappe/js/lib/fullcalendar/fullcalendar.min.js',
		'assets/path/to/public/js/locale-all.js'
	]
})

frappe.views.Calendar = frappe.views.Calendar.extend({

	setup_options: function() {
		var me = this;
		this.cal_options = {
			locale: frappe.boot.user.language || "en",
			header: {
				left: 'title',
				center: '',
				right: 'prev,next month,agendaWeek,agendaDay'
			},
			editable: true,
			selectable: true,
			selectHelper: true,
			forceEventDuration: true,
			events: function(start, end, timezone, callback) {
				return frappe.call({
					method: me.get_events_method || "frappe.desk.calendar.get_events",
					type: "GET",
					args: me.get_args(start, end),
					callback: function(r) {
						var events = r.message;
						me.prepare_events(events);
						callback(events);
					}
				})
			},
			eventClick: function(event, jsEvent, view) {
				// edit event description or delete
				var doctype = event.doctype || me.doctype;
				if(frappe.model.can_read(doctype)) {
					frappe.set_route("Form", doctype, event.name);
				}
			},
			eventDrop: function(event, delta, revertFunc, jsEvent, ui, view) {
				me.update_event(event, revertFunc);
			},
			eventResize: function(event, delta, revertFunc, jsEvent, ui, view) {
				me.update_event(event, revertFunc);
			},
			select: function(startDate, endDate, jsEvent, view) {
				if (view.name==="month" && (endDate - startDate)===86400000) {
					// detect single day click in month view
					return;

				}

				var event = frappe.model.get_new_doc(me.doctype);

				event[me.field_map.start] = me.get_system_datetime(startDate);

				if(me.field_map.end)
					event[me.field_map.end] = me.get_system_datetime(endDate);

				if(me.field_map.allDay) {
					var all_day = (startDate._ambigTime && endDate._ambigTime) ? 1 : 0;

					event[me.field_map.allDay] = all_day;

					if (all_day)
						event[me.field_map.end] = me.get_system_datetime(moment(endDate).subtract(1, "s"));
				}

				frappe.set_route("Form", me.doctype, event.name);
			},
			dayClick: function(date, allDay, jsEvent, view) {
				jsEvent.day_clicked = true;
				return false;
			}
		};

		if(this.options) {
			$.extend(this.cal_options, this.options);
		}
	}
});

make sure you will locale-all.js in the public js path.

You can download locale-all.js from fullcalendar 3.10 (version used in frappe)

that’s great, but I think it should be much easier (usable for anyone by a few clicks in setup, just like choosing the interface language, i.e.)

so therefore I think I’ll keep my issue up’n’running … thanks anyway

@vrms well …you can put in an custom app so that when installed u will get calendar and datepicker localization.

may be … it should be just a setting per user just like the display languaguge I think though.

thanks for the pointers anyway

@vrms Can’t get your point …first day of the week is strictly related to the localization …so if u set user language as English, you will get first day Sunday, if you set, let’s say, Italian then you will get Monday.

Why you want to add a new setting per user?

because I am in China (Monday) and use an English interface

u should use en-GB in order to have that settings

en-GB seems not to exist. en-US or en seems to be all there is. Both have Sun as first day. Is that due to my location?

Ok, i’ve modified localization file so that if you choose english language you’ll get monday as first day …if u choose english US you’ll get sunday.

I’ve sent a pull request, waiting for the core team review.