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