SessionDateUtils.java
/*
** Module : SessionDateUtils.java
** Abstract : Defines APIs used to access the SESSION date-related attributes and methods.
**
** Copyright (c) 2020, Golden Code Development Corporation.
**
** -#- -I- --Date-- --------------------------------Description-----------------------------------
** 001 IAS 20200410 Created initial version.
*/
/*
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU Affero General Public License as
** published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
**
** You may find a copy of the GNU Affero GPL version 3 at the following
** location: https://www.gnu.org/licenses/agpl-3.0.en.html
**
** Additional terms under GNU Affero GPL version 3 section 7:
**
** Under Section 7 of the GNU Affero GPL version 3, the following additional
** terms apply to the works covered under the License. These additional terms
** are non-permissive additional terms allowed under Section 7 of the GNU
** Affero GPL version 3 and may not be removed by you.
**
** 0. Attribution Requirement.
**
** You must preserve all legal notices or author attributions in the covered
** work or Appropriate Legal Notices displayed by works containing the covered
** work. You may not remove from the covered work any author or developer
** credit already included within the covered work.
**
** 1. No License To Use Trademarks.
**
** This license does not grant any license or rights to use the trademarks
** Golden Code, FWD, any Golden Code or FWD logo, or any other trademarks
** of Golden Code Development Corporation. You are not authorized to use the
** name Golden Code, FWD, or the names of any author or contributor, for
** publicity purposes without written authorization.
**
** 2. No Misrepresentation of Affiliation.
**
** You may not represent yourself as Golden Code Development Corporation or FWD.
**
** You may not represent yourself for publicity purposes as associated with
** Golden Code Development Corporation, FWD, or any author or contributor to
** the covered work, without written authorization.
**
** 3. No Misrepresentation of Source or Origin.
**
** You may not represent the covered work as solely your work. All modified
** versions of the covered work must be marked in a reasonable way to make it
** clear that the modified work is not originating from Golden Code Development
** Corporation or FWD. All modified versions must contain the notices of
** attribution required in this license.
*/
package com.goldencode.p2j.util;
/**
* This class provides implementation for SESSION date-related attributes.
* Mainly, the APIs implemented here are defined in the {@link CommonSession}
* interface (or one of its super interfaces) and are not statically
* implemented by the classes used by the {@link SessionUtils#asHandle()}.
*/
public class SessionDateUtils
implements SessionExports
{
/** Singleton instance */
public static SessionDateUtils INSTANCE = new SessionDateUtils();
/** Private default constructor - to enforce singleton */
private SessionDateUtils()
{
super();
}
/**
* Sets the order of date components (SESSION:DATE-FORMAT) for conversion to/from strings.
* <p>
* The order of the 3 date sub-components as a 3 character string using "M", "D" and "Y" once
* each. The order from index 0 to index 2 represents the left to right ordering of the
* components. So the leftmost date component will be defined by the character at index
* position 0.
* <p>
* The value set is specific to the current user's context.
*
* @param dateFormat
* Defines the order of date components for conversion to/from strings.
*/
public void setDateFormat(String dateFormat)
{
setDateFormat(new character(dateFormat));
}
/**
* Sets the order of date components (SESSION:DATE-FORMAT) for conversion to/from strings.
* <p>
* The order of the 3 date sub-components as a 3 character string using "M", "D" and "Y" once
* each. The order from index 0 to index 2 represents the left to right ordering of the
* components. So the leftmost date component will be defined by the character at index
* position 0.
* <p>
* The value set is specific to the current user's context.
*
* @param dateFormat
* Defines the order of date components for conversion to/from strings.
*/
public void setDateFormat(character dateFormat)
{
date.setDateOrder(dateFormat);
}
/**
* Gets the order of date components (SESSION:DATE-FORMAT) for conversion to/from strings.
* <p>
* The order of the 3 date sub-components is a 3 character string using
* "M", "D" and "Y" once each. The order from index 0 to index 2
* represents the left to right ordering of the components. So the leftmost
* date component will be defined by the character at index position 0.
* <p>
* The value accessed is specific to the current user's context.
*
* @return Defines the order of date components for conversion to/from strings.
*/
public character getDateFormat()
{
return date.getDateOrder();
}
/**
* Sets the SESSION:TIMEZONE used as the default offset in minutes from
* UTC for this user's context.
*
* @param offset
* The new timezone offset which must be between -840 and 840
* inclusive. The value may also be <code>unknown</code> which
* is the equivalent of resetting this attribute to the default.
*/
public void setSessionTimeZone(NumberType offset)
{
date.setTimeZone(offset);
}
/**
* Accesses the SESSION:TIMEZONE used as the default offset in minutes from
* UTC for this user's context.
*
* @return The timezone offset. If this has never been set, then
* <code>unknown</code> will be returned.
*/
public integer getSessionTimeZone()
{
return date.getTimeZone();
}
/**
* Obtains the currently configured TIME-SOURCE attribute for the current
* user's context. This attribute is can be read and written but it is
* not honored for date/time processing in P2J. The intention of the
* attribute is to define the system from which time values will be obtained.
* In P2J, time values are always obtained from the application server.
* <p>
* The default value is "local" which in Progress means that the client
* machine is the source (this is the same as the empty string ""). It is
* common to use a database name in the 4GL, which makes the application
* use the database server as the time source.
*
* @return The time source attribute.
*/
public character getSessionTimeSource()
{
return date.getTimeSource();
}
/**
* Sets the <code>TIME-SOURCE</code> attribute for the user's context.
* This attribute is can be read and written but it is not honored for
* date/time processing in P2J. The intention of the attribute is to define
* the system from which time values will be obtained. In P2J, time values
* are always obtained from the application server.
*
* @param timeSource
* The new value to set. If <code>null</code>, then the empty
* string will be used, which in the 4GL has the same affect as
* "local".
*/
public void setSessionTimeSource(character timeSource)
{
date.setTimeSource(timeSource);
}
/**
* Obtains the currently configured DISPLAY-TIMEZONE attribute for the current
* user's context. This attribute is used for displaying DATETIME-TZ values that do not have
* the timezone specified in the display format.
*
* @return The display-timezone attribute.
*/
public integer getSessionDisplayTimeZone()
{
return date.getDisplayTimeZone();
}
/**
* Sets the <code>DISPLAY-TIMEZONE</code> attribute for the user's context.
* This attribute is used for displaying DATETIME-TZ values that do not have
* the timezone specified in the display format.
*
* @param displayTimezone
* The new value to set.
*/
public void setSessionDisplayTimeZone(NumberType displayTimezone)
{
date.setDisplayTimeZone(displayTimezone);
}
/**
* Implementation of SESSION:YEAR-OFFSET attribute getter. Returns the
* currently configured start year for the two-digit Y2K windowing range.
* This is the equivalent to the Progress -yy command line parameter. The
* default value is 1950 unless otherwise specified in the directory (see
* {@link date#getWindowingYear}).
*
* @return The start year for the two-digit windowing range.
*/
public integer getYearOffset()
{
return date.getYearOffset();
}
/**
* Implementation of SESSION:YEAR-OFFSET attribute setter. Sets the
* configured start year for the two-digit Y2K windowing range. This is
* the equivalent of the Progress -yy command line parameter. The
* default value is 1950 unless otherwise specified in the directory (see
* {@link date#getWindowingYear}).
*
* @param year
* The new start year for the two-digit windowing range.
*/
public void setYearOffset(NumberType year)
{
date.setYearOffset(year);
}
}