OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 180 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 180 Rev 182
Line 1... Line 1...
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
3
 * 
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
4
 * Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
5
 * 
5
 * 
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
9
 * language governing permissions and limitations under the License.
Line 13... Line 13...
13
 
13
 
14
 package org.openconcerto.utils;
14
 package org.openconcerto.utils;
15
 
15
 
16
import java.math.BigDecimal;
16
import java.math.BigDecimal;
17
import java.math.BigInteger;
17
import java.math.BigInteger;
-
 
18
import java.time.LocalDate;
-
 
19
import java.time.LocalDateTime;
-
 
20
import java.time.ZoneId;
18
import java.util.Arrays;
21
import java.util.Arrays;
19
import java.util.Calendar;
22
import java.util.Calendar;
20
import java.util.Collection;
23
import java.util.Collection;
21
import java.util.Collections;
24
import java.util.Collections;
22
import java.util.Date;
25
import java.util.Date;
Line 422... Line 425...
422
            coarserAmount = amount1;
425
            coarserAmount = amount1;
423
            coarser = unit1;
426
            coarser = unit1;
424
        }
427
        }
425
        return finerAmount == finer.convert(coarserAmount, coarser);
428
        return finerAmount == finer.convert(coarserAmount, coarser);
426
    }
429
    }
-
 
430
 
-
 
431
    public static LocalDateTime toLocalDateTime(Calendar calendar) {
-
 
432
        if (calendar == null)
-
 
433
            return null;
-
 
434
        return LocalDateTime.ofInstant(calendar.toInstant(), getTZ(calendar));
-
 
435
    }
-
 
436
 
-
 
437
    private static ZoneId getTZ(Calendar calendar) {
-
 
438
        final TimeZone tz = calendar.getTimeZone();
-
 
439
        return tz == null ? ZoneId.systemDefault() : tz.toZoneId();
-
 
440
    }
-
 
441
 
-
 
442
    public static final Calendar toCalendar(final LocalDateTime dt) {
-
 
443
        final Calendar cal = Calendar.getInstance();
-
 
444
        cal.setTimeInMillis(dt.atZone(getTZ(cal)).toInstant().toEpochMilli());
-
 
445
        return cal;
-
 
446
    }
-
 
447
 
-
 
448
    public static LocalDate toLocalDate(Calendar calendar) {
-
 
449
        if (calendar == null)
-
 
450
            return null;
-
 
451
        if (calendar instanceof GregorianCalendar)
-
 
452
            return LocalDate.of(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DAY_OF_MONTH));
-
 
453
        else
-
 
454
            return toLocalDateTime(calendar).toLocalDate();
-
 
455
    }
427
}
456
}