Skip to content

Commit ddbe74b

Browse files
authored
Merge pull request #117 from martinRenou/add_time_celltype
Add time cell type
2 parents e7aec62 + adc1f88 commit ddbe74b

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

ipysheet/easy.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
read_only (bool): Whether the cell is editable or not
3434
numeric_format (string): Numbers format
3535
date_format (string): Dates format
36+
time_format (string): Time format
3637
renderer (string): Renderer name to use for the cell
3738
"""
3839
}

ipysheet/sheet.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class Cell(widgets.Widget):
3333
choice = List(Unicode(), allow_none=True, default_value=None).tag(sync=True)
3434
numeric_format = Unicode('0.000', allow_none=True).tag(sync=True)
3535
date_format = Unicode('YYYY/MM/DD', allow_none=True).tag(sync=True)
36+
time_format = Unicode('h:mm:ss a', allow_none=True).tag(sync=True)
3637

3738
@traitlets.validate('value')
3839
def _validate_value(self, proposal):

js/src/sheet.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ let CellRangeModel = widgets.WidgetModel.extend({
3333
squeeze_column: true,
3434
transpose: false,
3535
numeric_format: '0.000',
36-
date_format: 'YYYY/MM/DD'
36+
date_format: 'YYYY/MM/DD',
37+
time_format: 'h:mm:ss a'
3738
});
3839
},
3940
}, {
@@ -95,7 +96,7 @@ let SheetModel = widgets.DOMWidgetModel.extend({
9596
this.grid_to_cell()
9697
},
9798
cell_bind: function(cell) {
98-
cell.on_some_change(['value', 'style', 'type', 'renderer', 'read_only', 'choice', 'numeric_format', 'date_format'], () => {
99+
cell.on_some_change(['value', 'style', 'type', 'renderer', 'read_only', 'choice', 'numeric_format', 'date_format', 'time_format'], () => {
99100
this.cells_to_grid();
100101
});
101102
},
@@ -145,6 +146,10 @@ let SheetModel = widgets.DOMWidgetModel.extend({
145146
cell_data.options['correctFormat'] = true;
146147
cell_data.options['dateFormat'] = cell.get('date_format') || cell_data.options['dateFormat'];
147148
}
149+
if (cell.get('time_format') && cell.get('type') == 'time') {
150+
cell_data.options['correctFormat'] = true;
151+
cell_data.options['timeFormat'] = cell.get('time_format') || cell_data.options['timeFormat'];
152+
}
148153

149154
cell_data.options['style'] = extend({}, cell_data.options['style'], cell.get('style'));
150155
}

0 commit comments

Comments
 (0)