mirror of https://github.com/espruino/BangleApps
Merge remote-tracking branch 'origin/master'
commit
6571a37399
|
@ -339,6 +339,7 @@ function mergeObjects(obj1, obj2){
|
|||
|
||||
|
||||
const heights = {
|
||||
vvvsmall: [14,11],
|
||||
vvsmall: [15,13],
|
||||
vsmall: [20,15],
|
||||
small: [25,20],
|
||||
|
@ -533,7 +534,7 @@ function drawClock(){
|
|||
// we don't want the time to be displayed
|
||||
// and then immediately be trigger another time
|
||||
if(last_draw_time != null &&
|
||||
Date.now() - last_draw_time.getTime() < next_minute_boundary_secs * 1000 &&
|
||||
date.getTime() - last_draw_time.getTime() < next_minute_boundary_secs * 1000 &&
|
||||
has_commands() ){
|
||||
console.log("skipping draw clock");
|
||||
return;
|
||||
|
@ -544,17 +545,18 @@ function drawClock(){
|
|||
date = display_time(date);
|
||||
console.log("draw_clock:" + last_draw_time.toISOString() + " display:" + date.toISOString());
|
||||
|
||||
var rows = date_formatter.formatDate(date);
|
||||
var display;
|
||||
const rows = date_formatter.formatDate(date);
|
||||
for (var i = 0; i < rows.length; i++) {
|
||||
display = row_displays[i];
|
||||
var txt = display.getRowContext().row_text_formatter(rows[i]);
|
||||
display_row(display,txt);
|
||||
const display = row_displays[i];
|
||||
if(display != null){
|
||||
const txt = display.getRowContext().row_text_formatter(rows[i]);
|
||||
display_row(display,txt);
|
||||
}
|
||||
}
|
||||
// If the dateformatter has not returned enough
|
||||
// rows then treat the remaining rows as empty
|
||||
for (var j = i; j < row_displays.length; j++) {
|
||||
display = row_displays[j];
|
||||
const display = row_displays[j];
|
||||
display_row(display,'');
|
||||
}
|
||||
next_command();
|
||||
|
@ -610,6 +612,11 @@ function setColorScheme(colorscheme_name){
|
|||
}
|
||||
|
||||
const Locale = require('locale');
|
||||
|
||||
/**
|
||||
* Demonstration Date formatter so that we can see the
|
||||
* clock working in the emulator
|
||||
*/
|
||||
class DigitDateTimeFormatter {
|
||||
constructor() {
|
||||
this.row_types = {
|
||||
|
|
|
@ -6,8 +6,8 @@ class DigitDateTimeFormatter {
|
|||
large: {
|
||||
scroll_off: ['down'],
|
||||
scroll_in: ['up'],
|
||||
size: 'large',
|
||||
speed: 'slow'
|
||||
size: 'vlarge',
|
||||
speed: 'medium'
|
||||
},
|
||||
small: {
|
||||
angle_to_horizontal: 0,
|
||||
|
@ -20,13 +20,13 @@ class DigitDateTimeFormatter {
|
|||
{
|
||||
type: 'large',
|
||||
row_direction: [0.7,0.0],
|
||||
init_coords: [0.15,0.35],
|
||||
init_coords: [0.1,0.35],
|
||||
rows: 3
|
||||
},
|
||||
{
|
||||
type: 'large',
|
||||
row_direction: [0.7,0.0],
|
||||
init_coords: [0.55,0.35],
|
||||
init_coords: [0.6,0.35],
|
||||
rows: 2
|
||||
},
|
||||
{
|
||||
|
|
|
@ -1,39 +1,44 @@
|
|||
var DateFormatter = require("slidingtext.dtfmt.js");
|
||||
const hoursToText = require("slidingtext.utils.en.js").hoursToText;
|
||||
const numberToText = require("slidingtext.utils.en.js").numberToText;
|
||||
const dayOfWeek = require("slidingtext.utils.en.js").dayOfWeek;
|
||||
const numberToDayNumberText = require("slidingtext.utils.en.js").numberToDayNumberText;
|
||||
const monthToText = require("slidingtext.utils.en.js").monthToText;
|
||||
|
||||
class EnglishDateFormatter extends DateFormatter {
|
||||
constructor() {
|
||||
super();
|
||||
this.row_types = {
|
||||
small: {size: 'vsmall'}
|
||||
small: {size: 'vvsmall'}
|
||||
};
|
||||
this.row_defs = [
|
||||
{
|
||||
type: 'large',
|
||||
init_coords: [0.05,0.1],
|
||||
init_coords: [0.05,0.07],
|
||||
row_direction: [0.0,1.0],
|
||||
rows: 1
|
||||
},
|
||||
{
|
||||
type: 'medium',
|
||||
init_coords: [0.05,0.4],
|
||||
init_coords: [0.05,0.31],
|
||||
row_direction: [0.0,1.0],
|
||||
rows: 2
|
||||
},
|
||||
{
|
||||
type: 'small',
|
||||
init_coords: [0.05,0.9],
|
||||
init_coords: [0.05,0.8],
|
||||
row_direction: [0.0,1.0],
|
||||
rows: 1
|
||||
rows: 2
|
||||
}
|
||||
];
|
||||
}
|
||||
formatDate(date){
|
||||
var hours_txt = hoursToText(date.getHours());
|
||||
var mins_txt = numberToText(date.getMinutes());
|
||||
var date_txt = Locale.dow(date,1).toUpperCase() + " " + numberToText(date.getDate());
|
||||
return [hours_txt,mins_txt[0],mins_txt[1],date_txt];
|
||||
const hours_txt = hoursToText(date.getHours());
|
||||
const mins_txt = numberToText(date.getMinutes());
|
||||
const day_of_week = dayOfWeek(date);
|
||||
const date_txt = numberToDayNumberText(date.getDate()).join(' ');
|
||||
const month = monthToText(date);
|
||||
return [hours_txt,mins_txt[0],mins_txt[1],day_of_week,date_txt,month];
|
||||
}
|
||||
defaultRowTypes(){ return this.row_types;}
|
||||
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
var DateFormatter = require("slidingtext.dtfmt.js");
|
||||
const DateFormatter = require("slidingtext.dtfmt.js");
|
||||
const dayOfWeekShort = require("slidingtext.utils.en.js").dayOfWeekShort;
|
||||
const numberToDayNumberText = require("slidingtext.utils.en.js").numberToDayNumberText;
|
||||
const hoursToText = require("slidingtext.utils.en.js").hoursToText;
|
||||
const numberToText = require("slidingtext.utils.en.js").numberToText;
|
||||
|
||||
|
@ -6,26 +8,16 @@ class EnglishTraditionalDateFormatter extends DateFormatter {
|
|||
constructor() {
|
||||
super();
|
||||
this.row_types = {
|
||||
vsmall: {
|
||||
color: 'minor',
|
||||
speed: 'superslow',
|
||||
scroll_off: ['down'],
|
||||
scroll_in: ['up'],
|
||||
size: 'vvsmall',
|
||||
angle_to_horizontal: 90
|
||||
},
|
||||
small: {
|
||||
speed: 'medium',
|
||||
scroll_off: ['left'],
|
||||
scroll_in: ['left'],
|
||||
scroll_off: ['left','right'],
|
||||
scroll_in: ['left','right'],
|
||||
},
|
||||
large: {
|
||||
speed: 'medium',
|
||||
color: 'major',
|
||||
scroll_off: ['left'],
|
||||
scroll_in: ['left'],
|
||||
size: 'mlarge',
|
||||
angle_to_horizontal: 0
|
||||
scroll_off: ['left','right'],
|
||||
scroll_in: ['left','right']
|
||||
}
|
||||
};
|
||||
this.row_defs = [
|
||||
|
@ -46,32 +38,27 @@ class EnglishTraditionalDateFormatter extends DateFormatter {
|
|||
init_coords: [0.05,0.75],
|
||||
row_direction: [0.0,1.0],
|
||||
rows: 1
|
||||
},
|
||||
{
|
||||
type: 'vsmall',
|
||||
init_coords: [0.9,0.9],
|
||||
row_direction: [0.0,1.0],
|
||||
rows: 1
|
||||
},
|
||||
}
|
||||
];
|
||||
}
|
||||
formatDate(date){
|
||||
var date_txt = Locale.dow(date,1).toUpperCase() + " " + numberToText(date.getDate());
|
||||
var mins = date.getMinutes();
|
||||
const day_of_week = dayOfWeekShort(date);
|
||||
const date_txt = numberToDayNumberText(date.getDate()).join(' ');
|
||||
const mins = date.getMinutes();
|
||||
var hourOfDay = date.getHours();
|
||||
if(mins > 30){
|
||||
hourOfDay += 1;
|
||||
}
|
||||
var hours = hoursToText(hourOfDay);
|
||||
const hours = hoursToText(hourOfDay);
|
||||
// Deal with the special times first
|
||||
if(mins === 0){
|
||||
return [hours,"", "O'","CLOCK","", date_txt];
|
||||
return [hours,"", "O'","CLOCK","", day_of_week, date_txt];
|
||||
} else if(mins === 30){
|
||||
return ["","HALF", "PAST", "", hours, date_txt];
|
||||
return ["","HALF", "PAST", "", hours, day_of_week, date_txt];
|
||||
} else if(mins === 15){
|
||||
return ["","QUARTER", "PAST", "", hours, date_txt];
|
||||
return ["","QUARTER", "PAST", "", hours, day_of_week, date_txt];
|
||||
} else if(mins === 45) {
|
||||
return ["", "QUARTER", "TO", "", hours, date_txt];
|
||||
return ["", "QUARTER", "TO", "", hours, day_of_week, date_txt];
|
||||
}
|
||||
var mins_txt;
|
||||
var from_to;
|
||||
|
@ -87,14 +74,14 @@ class EnglishTraditionalDateFormatter extends DateFormatter {
|
|||
}
|
||||
|
||||
if(mins_txt[1] !== '') {
|
||||
return ['', mins_txt[0], mins_txt[1], from_to, hours, date_txt];
|
||||
return ['', mins_txt[0], mins_txt[1], from_to, hours, day_of_week, date_txt];
|
||||
} else {
|
||||
if(mins_value % 5 === 0) {
|
||||
return ['', mins_txt[0], from_to, '', hours, date_txt];
|
||||
return ['', mins_txt[0], from_to, '', hours, day_of_week, date_txt];
|
||||
} else if(mins_value === 1){
|
||||
return ['', mins_txt[0], 'MINUTE', from_to, hours, date_txt];
|
||||
return ['', mins_txt[0], 'MINUTE', from_to, hours, day_of_week, date_txt];
|
||||
} else {
|
||||
return ['', mins_txt[0], 'MINUTES', from_to, hours, date_txt];
|
||||
return ['', mins_txt[0], 'MINUTES', from_to, hours, day_of_week, date_txt];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,11 @@
|
|||
size: 'msmall',
|
||||
scroll_off: ['right'],
|
||||
scroll_in: ['right'],
|
||||
},
|
||||
small: {
|
||||
size: 'vvsmall',
|
||||
scroll_off: ['right'],
|
||||
scroll_in: ['right'],
|
||||
}
|
||||
},
|
||||
row_defs: [
|
||||
|
@ -41,9 +46,9 @@
|
|||
},
|
||||
{
|
||||
type: 'small',
|
||||
init_coords: [0.26,0.9],
|
||||
init_coords: [0.26,0.7],
|
||||
row_direction: [0.0,1.0],
|
||||
rows: 1
|
||||
rows: 3
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -51,9 +56,16 @@
|
|||
'en2 p': { date_formatter: 'en2',
|
||||
row_types: {
|
||||
vsmall: {
|
||||
color: 'minor',
|
||||
speed: 'superslow',
|
||||
angle_to_horizontal: 0,
|
||||
scroll_off: ['left'],
|
||||
scroll_in: ['left'],
|
||||
angle_to_horizontal: 0
|
||||
size: 'vsmall'
|
||||
},
|
||||
small: {
|
||||
scroll_off: ['left'],
|
||||
scroll_in: ['left']
|
||||
},
|
||||
small: {
|
||||
scroll_off: ['left'],
|
||||
|
@ -61,6 +73,7 @@
|
|||
angle_to_horizontal: 0
|
||||
},
|
||||
large: {
|
||||
size: 'mlarge',
|
||||
angle_to_horizontal: 90,
|
||||
speed: 'vslow',
|
||||
color: 'major',
|
||||
|
@ -78,7 +91,7 @@
|
|||
},
|
||||
{
|
||||
type: 'small',
|
||||
init_coords: [0.05,0.35],
|
||||
init_coords: [0.05,0.4],
|
||||
row_direction: [0.0,1.0],
|
||||
rows: 3
|
||||
},
|
||||
|
@ -93,7 +106,7 @@
|
|||
type: 'vsmall',
|
||||
init_coords: [0.05,0.1],
|
||||
row_direction: [0.0,1.0],
|
||||
rows: 1
|
||||
rows: 2
|
||||
},
|
||||
]
|
||||
},
|
||||
|
|
|
@ -3,15 +3,23 @@ const numberStr = ["ZERO","ONE", "TWO", "THREE", "FOUR", "FIVE",
|
|||
"ELEVEN", "TWELVE", "THIRTEEN", "FOURTEEN",
|
||||
"FIFTEEN", "SIXTEEN", "SEVENTEEN", "EIGHTEEN",
|
||||
"NINETEEN", "TWENTY"];
|
||||
const tensStr = ["ZERO", "TEN", "TWENTY", "THIRTY", "FOURTY", "FIFTY"];
|
||||
const tensStr = ["ZERO", "TEN", "TWENTY", "THIRTY", "FORTY", "FIFTY"];
|
||||
const dayNames = ["SUNDAY", "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY"];
|
||||
const monthStr = [
|
||||
"JAN", "FEB", "MAR", "APR", "MAY", "JULY",
|
||||
"AUG", "SEPT", "OCT", "NOV", "DEC"
|
||||
"JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JULY",
|
||||
"AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER"
|
||||
]
|
||||
|
||||
const monthToText = (month)=>{
|
||||
return monthStr[month - 1];
|
||||
}
|
||||
const dateNumberStr = ["ZEROTH", "FIRST", "SECOND", "THIRD", "FORTH", "FIFTH",
|
||||
"SIXTH","SEVENTH","EIGHTH","NINTH","TENTH","ELEVENTH","TWELFTH","THIRTEENTH",
|
||||
"FOURTEENTH", "FIFTEENTH", "SIXTEENTH", "SEVENTEENTH", "EIGHTEENTH", "NINETEENTH",
|
||||
"TWENTIETH"
|
||||
]
|
||||
|
||||
const dayOfWeek = (date) => dayNames[date.getDay()];
|
||||
const dayOfWeekShort = (date) => dayNames[date.getDay()].substring(0,3);
|
||||
const monthToText = (date)=>monthStr[date.getMonth()-1];
|
||||
|
||||
const hoursToText = (hours)=>{
|
||||
hours = hours % 12;
|
||||
if(hours === 0){
|
||||
|
@ -24,9 +32,9 @@ const numberToText = (value)=> {
|
|||
var word1 = '';
|
||||
var word2 = '';
|
||||
if(value > 20){
|
||||
var tens = (value / 10 | 0);
|
||||
const tens = (value / 10 | 0);
|
||||
word1 = tensStr[tens];
|
||||
var remainder = value - tens * 10;
|
||||
const remainder = value - tens * 10;
|
||||
if(remainder > 0){
|
||||
word2 = numberStr[remainder];
|
||||
}
|
||||
|
@ -36,6 +44,27 @@ const numberToText = (value)=> {
|
|||
return [word1,word2];
|
||||
}
|
||||
|
||||
const numberToDayNumberText = (value) => {
|
||||
var word1 = '';
|
||||
var word2 = '';
|
||||
if(value === 30) {
|
||||
word1 = "THIRTIETH";
|
||||
} else if(value > 20){
|
||||
const tens = (value / 10 | 0);
|
||||
word1 = tensStr[tens];
|
||||
const remainder = value - tens * 10;
|
||||
if(remainder > 0){
|
||||
word2 = dateNumberStr[remainder];
|
||||
}
|
||||
} else if(value > 0) {
|
||||
word1 = dateNumberStr[value];
|
||||
}
|
||||
return [word1,word2];
|
||||
}
|
||||
|
||||
exports.monthToText = monthToText;
|
||||
exports.hoursToText = hoursToText;
|
||||
exports.numberToText = numberToText;
|
||||
exports.numberToText = numberToText;
|
||||
exports.numberToDayNumberText = numberToDayNumberText;
|
||||
exports.dayOfWeek = dayOfWeek;
|
||||
exports.dayOfWeekShort = dayOfWeekShort;
|
Loading…
Reference in New Issue