📄 dateatom.java
字号:
/* * MC2 -- j2me spreadsheet * * Copyright (c) 2004-2006 Michael Zemljanukha (mixaz@mail.ru) * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */package com.wapindustrial.calc;import ral.Real;import java.util.*;public class DateAtom extends LispObject { public Real value; // time in DHMS format public DateAtom( ) { // get current Time value = new Real(); Real tmpVal = new Real(); value.time(); tmpVal.date(); value.add(tmpVal); } public DateAtom( Real value ) { this.value = new Real(value); } public DateAtom( int year, int month, int day, int hour, int min) { value = new Real(year); value.mul(100); value.add(month); value.mul(100); value.add(day); value.mul(100); value.add(hour); value.mul(100); value.add(min); value.div(100); } public DateAtom( int year, int month, int day ) { this(year, month, day, 0, 0); } // to represent complex atoms as lists FunctorList toList() { return new FunctorList1( Bfunc.BFUNC.table[Bfunc.INDEX_DATE], // move this from CanvasHandler to something like BFUNC new FloatAtom( value ) ); } public void toValueBuffer( StringBuffer sb, int format ) { dateToBuffer( sb, value, format ); } public void toFormulaBuffer( StringBuffer sb ) { sb.append( '#' ); dateToBuffer( sb, value, Cell.FORMAT_SHOWDATETIME ); sb.append( '#' ); } //#ifdef JAVA_COMPILER public void toJavaBuffer( StringBuffer sb, int ident ) { addIdent( sb, ident ); sb.append( "new DateAtom(" ); sb.append( value.toString() ); sb.append( "L) " ); }//#endif public int typeNumber() { return TYPE_DATE; } public LispObject convertToType( int type ) throws EvaluateException { LispObject rez = this; switch( type ) { case TYPE_FLOAT: rez = new FloatAtom( value ); ((FloatAtom) rez).value.fromDHMS(); // convert from DHMS to hours break; case TYPE_LONG: Real tmp= new Real( value ); tmp.fromDHMS(); // convert from DHMS to hours tmp.sub(17268672); // subtract 01.01.1970 00:00 tmp.mul(3600000); // convert from hours to millisec rez = new LongAtom( tmp.toLong() ); break; case TYPE_DATE: break; default: // to STRING return super.convertToType( type ); } return rez; } public static void dateToBuffer(StringBuffer sb, Real ll, int formats) { Real r1, r2, r100 = new Real(100); r1 = new Real( ll ); r1.mul(100); r2 = new Real( r1 ); r1.trunc(); r2.assign(r1); r2.mod(r100); int min = r2.toInteger(); r1.div(100); r1.trunc(); r2.assign(r1); r2.mod(r100); int hour = r2.toInteger(); r1.div(100); r1.trunc(); r2.assign(r1); r2.mod(r100); int day = r2.toInteger(); r1.div(100); r1.trunc(); r2.assign(r1); r2.mod(r100); int month = r2.toInteger(); r1.div(100); r1.trunc(); int year = r1.toInteger(); formats &= Cell.MASK_DATE; if ( formats == Cell.FORMAT_SHOWDATE || formats == Cell.FORMAT_SHOWDATETIME ) { if (year != 0) { if (day < 10) sb.append('0'); sb.append(Integer.toString(day)); sb.append( '/' ); if (month < 10) sb.append('0'); sb.append(Integer.toString(month)); sb.append( '/' ); if (year < 1000) sb.append('0'); if (year < 100) sb.append('0'); if (year < 10) sb.append('0'); sb.append(Integer.toString(year)); } else { // days only sb.append(month*100+day); } } if ( formats == Cell.FORMAT_SHOWDATETIME ) { sb.append( ' ' ); } if ( formats == Cell.FORMAT_SHOWTIME || formats == Cell.FORMAT_SHOWDATETIME ) { if (hour < 10) { sb.append('0'); } sb.append(Integer.toString(hour)); sb.append(':'); if (min < 10) { sb.append('0'); } sb.append(Integer.toString(min)); } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -